Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

videolayout.js 48KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. var VideoLayout = (function (my) {
  2. var preMuted = false;
  3. var currentDominantSpeaker = null;
  4. var lastNCount = config.channelLastN;
  5. var lastNEndpointsCache = [];
  6. my.changeLocalAudio = function(stream) {
  7. connection.jingle.localAudio = stream;
  8. RTC.attachMediaStream($('#localAudio'), stream);
  9. document.getElementById('localAudio').autoplay = true;
  10. document.getElementById('localAudio').volume = 0;
  11. if (preMuted) {
  12. toggleAudio();
  13. preMuted = false;
  14. }
  15. };
  16. my.changeLocalVideo = function(stream, flipX) {
  17. connection.jingle.localVideo = stream;
  18. var localVideo = document.createElement('video');
  19. localVideo.id = 'localVideo_' + stream.id;
  20. localVideo.autoplay = true;
  21. localVideo.volume = 0; // is it required if audio is separated ?
  22. localVideo.oncontextmenu = function () { return false; };
  23. var localVideoContainer = document.getElementById('localVideoWrapper');
  24. localVideoContainer.appendChild(localVideo);
  25. // Set default display name.
  26. setDisplayName('localVideoContainer');
  27. AudioLevels.updateAudioLevelCanvas();
  28. var localVideoSelector = $('#' + localVideo.id);
  29. // Add click handler to both video and video wrapper elements in case
  30. // there's no video.
  31. localVideoSelector.click(function () {
  32. VideoLayout.handleVideoThumbClicked(localVideo.src);
  33. });
  34. $('#localVideoContainer').click(function () {
  35. VideoLayout.handleVideoThumbClicked(localVideo.src);
  36. });
  37. // Add hover handler
  38. $('#localVideoContainer').hover(
  39. function() {
  40. VideoLayout.showDisplayName('localVideoContainer', true);
  41. },
  42. function() {
  43. if (!VideoLayout.isLargeVideoVisible()
  44. || localVideo.src !== $('#largeVideo').attr('src'))
  45. VideoLayout.showDisplayName('localVideoContainer', false);
  46. }
  47. );
  48. // Add stream ended handler
  49. stream.onended = function () {
  50. localVideoContainer.removeChild(localVideo);
  51. VideoLayout.updateRemovedVideo(localVideo.src);
  52. };
  53. // Flip video x axis if needed
  54. flipXLocalVideo = flipX;
  55. if (flipX) {
  56. localVideoSelector.addClass("flipVideoX");
  57. }
  58. // Attach WebRTC stream
  59. RTC.attachMediaStream(localVideoSelector, stream);
  60. localVideoSrc = localVideo.src;
  61. VideoLayout.updateLargeVideo(localVideoSrc, 0);
  62. };
  63. /**
  64. * Checks if removed video is currently displayed and tries to display
  65. * another one instead.
  66. * @param removedVideoSrc src stream identifier of the video.
  67. */
  68. my.updateRemovedVideo = function(removedVideoSrc) {
  69. if (removedVideoSrc === $('#largeVideo').attr('src')) {
  70. // this is currently displayed as large
  71. // pick the last visible video in the row
  72. // if nobody else is left, this picks the local video
  73. var pick
  74. = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video')
  75. .get(0);
  76. if (!pick) {
  77. console.info("Last visible video no longer exists");
  78. pick = $('#remoteVideos>span[id!="mixedstream"]>video').get(0);
  79. if (!pick || !pick.src) {
  80. // Try local video
  81. console.info("Fallback to local video...");
  82. pick = $('#remoteVideos>span>span>video').get(0);
  83. }
  84. }
  85. // mute if localvideo
  86. if (pick) {
  87. VideoLayout.updateLargeVideo(pick.src, pick.volume);
  88. } else {
  89. console.warn("Failed to elect large video");
  90. }
  91. }
  92. };
  93. /**
  94. * Updates the large video with the given new video source.
  95. */
  96. my.updateLargeVideo = function(newSrc, vol) {
  97. console.log('hover in', newSrc);
  98. if ($('#largeVideo').attr('src') != newSrc) {
  99. var isVisible = $('#largeVideo').is(':visible');
  100. $('#largeVideo').fadeOut(300, function () {
  101. var oldSrc = $(this).attr('src');
  102. $(this).attr('src', newSrc);
  103. // Screen stream is already rotated
  104. var flipX = (newSrc === localVideoSrc) && flipXLocalVideo;
  105. var videoTransform = document.getElementById('largeVideo')
  106. .style.webkitTransform;
  107. if (flipX && videoTransform !== 'scaleX(-1)') {
  108. document.getElementById('largeVideo').style.webkitTransform
  109. = "scaleX(-1)";
  110. }
  111. else if (!flipX && videoTransform === 'scaleX(-1)') {
  112. document.getElementById('largeVideo').style.webkitTransform
  113. = "none";
  114. }
  115. // Change the way we'll be measuring and positioning large video
  116. var isDesktop = isVideoSrcDesktop(newSrc);
  117. getVideoSize = isDesktop
  118. ? getDesktopVideoSize
  119. : getCameraVideoSize;
  120. getVideoPosition = isDesktop
  121. ? getDesktopVideoPosition
  122. : getCameraVideoPosition;
  123. if (isVisible) {
  124. // Only if the large video is currently visible.
  125. // Disable previous dominant speaker video.
  126. var oldJid = getJidFromVideoSrc(oldSrc);
  127. if (oldJid) {
  128. var oldResourceJid = Strophe.getResourceFromJid(oldJid);
  129. VideoLayout.enableDominantSpeaker(oldResourceJid, false);
  130. }
  131. // Enable new dominant speaker in the remote videos section.
  132. var userJid = getJidFromVideoSrc(newSrc);
  133. if (userJid)
  134. {
  135. var resourceJid = Strophe.getResourceFromJid(userJid);
  136. VideoLayout.enableDominantSpeaker(resourceJid, true);
  137. }
  138. $(this).fadeIn(300);
  139. }
  140. });
  141. }
  142. };
  143. my.handleVideoThumbClicked = function(videoSrc) {
  144. // Restore style for previously focused video
  145. var focusJid = getJidFromVideoSrc(focusedVideoSrc);
  146. var oldContainer = getParticipantContainer(focusJid);
  147. if (oldContainer) {
  148. oldContainer.removeClass("videoContainerFocused");
  149. }
  150. // Unlock current focused.
  151. if (focusedVideoSrc === videoSrc)
  152. {
  153. focusedVideoSrc = null;
  154. var dominantSpeakerVideo = null;
  155. // Enable the currently set dominant speaker.
  156. if (currentDominantSpeaker) {
  157. dominantSpeakerVideo
  158. = $('#participant_' + currentDominantSpeaker + '>video')
  159. .get(0);
  160. if (dominantSpeakerVideo) {
  161. VideoLayout.updateLargeVideo(dominantSpeakerVideo.src, 1);
  162. }
  163. }
  164. return;
  165. }
  166. // Lock new video
  167. focusedVideoSrc = videoSrc;
  168. // Update focused/pinned interface.
  169. var userJid = getJidFromVideoSrc(videoSrc);
  170. if (userJid)
  171. {
  172. var container = getParticipantContainer(userJid);
  173. container.addClass("videoContainerFocused");
  174. }
  175. // Triggers a "video.selected" event. The "false" parameter indicates
  176. // this isn't a prezi.
  177. $(document).trigger("video.selected", [false]);
  178. VideoLayout.updateLargeVideo(videoSrc, 1);
  179. $('audio').each(function (idx, el) {
  180. if (el.id.indexOf('mixedmslabel') !== -1) {
  181. el.volume = 0;
  182. el.volume = 1;
  183. }
  184. });
  185. };
  186. /**
  187. * Positions the large video.
  188. *
  189. * @param videoWidth the stream video width
  190. * @param videoHeight the stream video height
  191. */
  192. my.positionLarge = function (videoWidth, videoHeight) {
  193. var videoSpaceWidth = $('#videospace').width();
  194. var videoSpaceHeight = window.innerHeight;
  195. var videoSize = getVideoSize(videoWidth,
  196. videoHeight,
  197. videoSpaceWidth,
  198. videoSpaceHeight);
  199. var largeVideoWidth = videoSize[0];
  200. var largeVideoHeight = videoSize[1];
  201. var videoPosition = getVideoPosition(largeVideoWidth,
  202. largeVideoHeight,
  203. videoSpaceWidth,
  204. videoSpaceHeight);
  205. var horizontalIndent = videoPosition[0];
  206. var verticalIndent = videoPosition[1];
  207. positionVideo($('#largeVideo'),
  208. largeVideoWidth,
  209. largeVideoHeight,
  210. horizontalIndent, verticalIndent);
  211. };
  212. /**
  213. * Shows/hides the large video.
  214. */
  215. my.setLargeVideoVisible = function(isVisible) {
  216. var largeVideoJid = getJidFromVideoSrc($('#largeVideo').attr('src'));
  217. var resourceJid = Strophe.getResourceFromJid(largeVideoJid);
  218. if (isVisible) {
  219. $('#largeVideo').css({visibility: 'visible'});
  220. $('.watermark').css({visibility: 'visible'});
  221. VideoLayout.enableDominantSpeaker(resourceJid, true);
  222. }
  223. else {
  224. $('#largeVideo').css({visibility: 'hidden'});
  225. $('.watermark').css({visibility: 'hidden'});
  226. VideoLayout.enableDominantSpeaker(resourceJid, false);
  227. }
  228. };
  229. /**
  230. * Indicates if the large video is currently visible.
  231. *
  232. * @return <tt>true</tt> if visible, <tt>false</tt> - otherwise
  233. */
  234. my.isLargeVideoVisible = function() {
  235. return $('#largeVideo').is(':visible');
  236. };
  237. /**
  238. * Checks if container for participant identified by given peerJid exists
  239. * in the document and creates it eventually.
  240. *
  241. * @param peerJid peer Jid to check.
  242. *
  243. * @return Returns <tt>true</tt> if the peer container exists,
  244. * <tt>false</tt> - otherwise
  245. */
  246. my.ensurePeerContainerExists = function(peerJid) {
  247. ContactList.ensureAddContact(peerJid);
  248. var resourceJid = Strophe.getResourceFromJid(peerJid);
  249. var videoSpanId = 'participant_' + resourceJid;
  250. if ($('#' + videoSpanId).length > 0) {
  251. // If there's been a focus change, make sure we add focus related
  252. // interface!!
  253. if (focus && $('#remote_popupmenu_' + resourceJid).length <= 0)
  254. addRemoteVideoMenu( peerJid,
  255. document.getElementById(videoSpanId));
  256. }
  257. else {
  258. var container
  259. = VideoLayout.addRemoteVideoContainer(peerJid, videoSpanId);
  260. // Set default display name.
  261. setDisplayName(videoSpanId);
  262. var nickfield = document.createElement('span');
  263. nickfield.className = "nick";
  264. nickfield.appendChild(document.createTextNode(resourceJid));
  265. container.appendChild(nickfield);
  266. // In case this is not currently in the last n we don't show it.
  267. if (lastNCount
  268. && lastNCount > 0
  269. && $('#remoteVideos>span').length >= lastNCount + 2) {
  270. showPeerContainer(resourceJid, false);
  271. }
  272. else
  273. VideoLayout.resizeThumbnails();
  274. }
  275. };
  276. my.addRemoteVideoContainer = function(peerJid, spanId) {
  277. var container = document.createElement('span');
  278. container.id = spanId;
  279. container.className = 'videocontainer';
  280. var remotes = document.getElementById('remoteVideos');
  281. // If the peerJid is null then this video span couldn't be directly
  282. // associated with a participant (this could happen in the case of prezi).
  283. if (focus && peerJid != null)
  284. addRemoteVideoMenu(peerJid, container);
  285. remotes.appendChild(container);
  286. AudioLevels.updateAudioLevelCanvas(peerJid);
  287. return container;
  288. };
  289. /**
  290. * Creates an audio or video stream element.
  291. */
  292. my.createStreamElement = function (sid, stream) {
  293. var isVideo = stream.getVideoTracks().length > 0;
  294. var element = isVideo
  295. ? document.createElement('video')
  296. : document.createElement('audio');
  297. var id = (isVideo ? 'remoteVideo_' : 'remoteAudio_')
  298. + sid + '_' + stream.id;
  299. element.id = id;
  300. element.autoplay = true;
  301. element.oncontextmenu = function () { return false; };
  302. return element;
  303. };
  304. my.addRemoteStreamElement
  305. = function (container, sid, stream, peerJid, thessrc) {
  306. var newElementId = null;
  307. var isVideo = stream.getVideoTracks().length > 0;
  308. if (container) {
  309. var streamElement = VideoLayout.createStreamElement(sid, stream);
  310. newElementId = streamElement.id;
  311. container.appendChild(streamElement);
  312. var sel = $('#' + newElementId);
  313. sel.hide();
  314. // If the container is currently visible we attach the stream.
  315. if (!isVideo
  316. || (container.offsetParent !== null && isVideo)) {
  317. var simulcast = new Simulcast();
  318. var videoStream = simulcast.getReceivingVideoStream(stream);
  319. RTC.attachMediaStream(sel, videoStream);
  320. if (isVideo)
  321. waitForRemoteVideo(sel, thessrc, stream);
  322. }
  323. stream.onended = function () {
  324. console.log('stream ended', this);
  325. VideoLayout.removeRemoteStreamElement(stream, container);
  326. if (peerJid)
  327. ContactList.removeContact(peerJid);
  328. };
  329. // Add click handler.
  330. container.onclick = function (event) {
  331. /*
  332. * FIXME It turns out that videoThumb may not exist (if there is
  333. * no actual video).
  334. */
  335. var videoThumb = $('#' + container.id + '>video').get(0);
  336. if (videoThumb)
  337. VideoLayout.handleVideoThumbClicked(videoThumb.src);
  338. event.preventDefault();
  339. return false;
  340. };
  341. // Add hover handler
  342. $(container).hover(
  343. function() {
  344. VideoLayout.showDisplayName(container.id, true);
  345. },
  346. function() {
  347. var videoSrc = null;
  348. if ($('#' + container.id + '>video')
  349. && $('#' + container.id + '>video').length > 0) {
  350. videoSrc = $('#' + container.id + '>video').get(0).src;
  351. }
  352. // If the video has been "pinned" by the user we want to
  353. // keep the display name on place.
  354. if (!VideoLayout.isLargeVideoVisible()
  355. || videoSrc !== $('#largeVideo').attr('src'))
  356. VideoLayout.showDisplayName(container.id, false);
  357. }
  358. );
  359. }
  360. return newElementId;
  361. };
  362. /**
  363. * Removes the remote stream element corresponding to the given stream and
  364. * parent container.
  365. *
  366. * @param stream the stream
  367. * @param container
  368. */
  369. my.removeRemoteStreamElement = function (stream, container) {
  370. if (!container)
  371. return;
  372. var select = null;
  373. var removedVideoSrc = null;
  374. if (stream.getVideoTracks().length > 0) {
  375. select = $('#' + container.id + '>video');
  376. removedVideoSrc = select.get(0).src;
  377. }
  378. else
  379. select = $('#' + container.id + '>audio');
  380. // Remove video source from the mapping.
  381. delete videoSrcToSsrc[removedVideoSrc];
  382. // Mark video as removed to cancel waiting loop(if video is removed
  383. // before has started)
  384. select.removed = true;
  385. select.remove();
  386. var audioCount = $('#' + container.id + '>audio').length;
  387. var videoCount = $('#' + container.id + '>video').length;
  388. if (!audioCount && !videoCount) {
  389. console.log("Remove whole user", container.id);
  390. // Remove whole container
  391. container.remove();
  392. Util.playSoundNotification('userLeft');
  393. VideoLayout.resizeThumbnails();
  394. }
  395. if (removedVideoSrc)
  396. VideoLayout.updateRemovedVideo(removedVideoSrc);
  397. };
  398. /**
  399. * Show/hide peer container for the given resourceJid.
  400. */
  401. function showPeerContainer(resourceJid, isShow) {
  402. var peerContainer = $('#participant_' + resourceJid);
  403. if (!peerContainer)
  404. return;
  405. if (!peerContainer.is(':visible') && isShow)
  406. peerContainer.show();
  407. else if (peerContainer.is(':visible') && !isShow)
  408. peerContainer.hide();
  409. };
  410. /**
  411. * Sets the display name for the given video span id.
  412. */
  413. function setDisplayName(videoSpanId, displayName) {
  414. var nameSpan = $('#' + videoSpanId + '>span.displayname');
  415. var defaultLocalDisplayName = "Me";
  416. var defaultRemoteDisplayName = "Speaker";
  417. // If we already have a display name for this video.
  418. if (nameSpan.length > 0) {
  419. var nameSpanElement = nameSpan.get(0);
  420. if (nameSpanElement.id === 'localDisplayName' &&
  421. $('#localDisplayName').text() !== displayName) {
  422. if (displayName && displayName.length > 0)
  423. $('#localDisplayName').text(displayName + ' (me)');
  424. else
  425. $('#localDisplayName').text(defaultLocalDisplayName);
  426. } else {
  427. if (displayName && displayName.length > 0)
  428. $('#' + videoSpanId + '_name').text(displayName);
  429. else
  430. $('#' + videoSpanId + '_name').text(defaultRemoteDisplayName);
  431. }
  432. } else {
  433. var editButton = null;
  434. nameSpan = document.createElement('span');
  435. nameSpan.className = 'displayname';
  436. $('#' + videoSpanId)[0].appendChild(nameSpan);
  437. if (videoSpanId === 'localVideoContainer') {
  438. editButton = createEditDisplayNameButton();
  439. nameSpan.innerText = defaultLocalDisplayName;
  440. }
  441. else {
  442. nameSpan.innerText = defaultRemoteDisplayName;
  443. }
  444. if (displayName && displayName.length > 0) {
  445. nameSpan.innerText = displayName;
  446. }
  447. if (!editButton) {
  448. nameSpan.id = videoSpanId + '_name';
  449. } else {
  450. nameSpan.id = 'localDisplayName';
  451. $('#' + videoSpanId)[0].appendChild(editButton);
  452. var editableText = document.createElement('input');
  453. editableText.className = 'displayname';
  454. editableText.id = 'editDisplayName';
  455. if (displayName && displayName.length) {
  456. editableText.value
  457. = displayName.substring(0, displayName.indexOf(' (me)'));
  458. }
  459. editableText.setAttribute('style', 'display:none;');
  460. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  461. $('#' + videoSpanId)[0].appendChild(editableText);
  462. $('#localVideoContainer .displayname')
  463. .bind("click", function (e) {
  464. e.preventDefault();
  465. $('#localDisplayName').hide();
  466. $('#editDisplayName').show();
  467. $('#editDisplayName').focus();
  468. $('#editDisplayName').select();
  469. var inputDisplayNameHandler = function (name) {
  470. if (nickname !== name) {
  471. nickname = name;
  472. window.localStorage.displayname = nickname;
  473. connection.emuc.addDisplayNameToPresence(nickname);
  474. connection.emuc.sendPresence();
  475. Chat.setChatConversationMode(true);
  476. }
  477. if (!$('#localDisplayName').is(":visible")) {
  478. if (nickname)
  479. $('#localDisplayName').text(nickname + " (me)");
  480. else
  481. $('#localDisplayName')
  482. .text(defaultLocalDisplayName);
  483. $('#localDisplayName').show();
  484. }
  485. $('#editDisplayName').hide();
  486. };
  487. $('#editDisplayName').one("focusout", function (e) {
  488. inputDisplayNameHandler(this.value);
  489. });
  490. $('#editDisplayName').on('keydown', function (e) {
  491. if (e.keyCode === 13) {
  492. e.preventDefault();
  493. inputDisplayNameHandler(this.value);
  494. }
  495. });
  496. });
  497. }
  498. }
  499. };
  500. /**
  501. * Shows/hides the display name on the remote video.
  502. * @param videoSpanId the identifier of the video span element
  503. * @param isShow indicates if the display name should be shown or hidden
  504. */
  505. my.showDisplayName = function(videoSpanId, isShow) {
  506. var nameSpan = $('#' + videoSpanId + '>span.displayname').get(0);
  507. if (isShow) {
  508. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  509. nameSpan.setAttribute("style", "display:inline-block;");
  510. }
  511. else {
  512. if (nameSpan)
  513. nameSpan.setAttribute("style", "display:none;");
  514. }
  515. };
  516. /**
  517. * Shows the presence status message for the given video.
  518. */
  519. my.setPresenceStatus = function (videoSpanId, statusMsg) {
  520. if (!$('#' + videoSpanId).length) {
  521. // No container
  522. return;
  523. }
  524. var statusSpan = $('#' + videoSpanId + '>span.status');
  525. if (!statusSpan.length) {
  526. //Add status span
  527. statusSpan = document.createElement('span');
  528. statusSpan.className = 'status';
  529. statusSpan.id = videoSpanId + '_status';
  530. $('#' + videoSpanId)[0].appendChild(statusSpan);
  531. statusSpan = $('#' + videoSpanId + '>span.status');
  532. }
  533. // Display status
  534. if (statusMsg && statusMsg.length) {
  535. $('#' + videoSpanId + '_status').text(statusMsg);
  536. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  537. }
  538. else {
  539. // Hide
  540. statusSpan.get(0).setAttribute("style", "display:none;");
  541. }
  542. };
  543. /**
  544. * Shows a visual indicator for the focus of the conference.
  545. * Currently if we're not the owner of the conference we obtain the focus
  546. * from the connection.jingle.sessions.
  547. */
  548. my.showFocusIndicator = function() {
  549. if (focus !== null) {
  550. var indicatorSpan = $('#localVideoContainer .focusindicator');
  551. if (indicatorSpan.children().length === 0)
  552. {
  553. createFocusIndicatorElement(indicatorSpan[0]);
  554. }
  555. }
  556. else if (Object.keys(connection.jingle.sessions).length > 0) {
  557. // If we're only a participant the focus will be the only session we have.
  558. var session
  559. = connection.jingle.sessions
  560. [Object.keys(connection.jingle.sessions)[0]];
  561. var focusId
  562. = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
  563. var focusContainer = document.getElementById(focusId);
  564. if (!focusContainer) {
  565. console.error("No focus container!");
  566. return;
  567. }
  568. var indicatorSpan = $('#' + focusId + ' .focusindicator');
  569. if (!indicatorSpan || indicatorSpan.length === 0) {
  570. indicatorSpan = document.createElement('span');
  571. indicatorSpan.className = 'focusindicator';
  572. focusContainer.appendChild(indicatorSpan);
  573. createFocusIndicatorElement(indicatorSpan);
  574. }
  575. }
  576. };
  577. /**
  578. * Shows video muted indicator over small videos.
  579. */
  580. my.showVideoIndicator = function(videoSpanId, isMuted) {
  581. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  582. if (isMuted === 'false') {
  583. if (videoMutedSpan.length > 0) {
  584. videoMutedSpan.remove();
  585. }
  586. }
  587. else {
  588. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  589. videoMutedSpan = document.createElement('span');
  590. videoMutedSpan.className = 'videoMuted';
  591. if (audioMutedSpan) {
  592. videoMutedSpan.right = '30px';
  593. }
  594. $('#' + videoSpanId)[0].appendChild(videoMutedSpan);
  595. var mutedIndicator = document.createElement('i');
  596. mutedIndicator.className = 'icon-camera-disabled';
  597. Util.setTooltip(mutedIndicator,
  598. "Participant has<br/>stopped the camera.",
  599. "top");
  600. videoMutedSpan.appendChild(mutedIndicator);
  601. }
  602. };
  603. /**
  604. * Shows audio muted indicator over small videos.
  605. */
  606. my.showAudioIndicator = function(videoSpanId, isMuted) {
  607. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  608. if (isMuted === 'false') {
  609. if (audioMutedSpan.length > 0) {
  610. audioMutedSpan.remove();
  611. }
  612. }
  613. else {
  614. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  615. audioMutedSpan = document.createElement('span');
  616. audioMutedSpan.className = 'audioMuted';
  617. Util.setTooltip(audioMutedSpan,
  618. "Participant is muted",
  619. "top");
  620. if (videoMutedSpan) {
  621. audioMutedSpan.right = '30px';
  622. }
  623. $('#' + videoSpanId)[0].appendChild(audioMutedSpan);
  624. var mutedIndicator = document.createElement('i');
  625. mutedIndicator.className = 'icon-mic-disabled';
  626. audioMutedSpan.appendChild(mutedIndicator);
  627. }
  628. };
  629. /**
  630. * Resizes the large video container.
  631. */
  632. my.resizeLargeVideoContainer = function () {
  633. Chat.resizeChat();
  634. var availableHeight = window.innerHeight;
  635. var availableWidth = Util.getAvailableVideoWidth();
  636. if (availableWidth < 0 || availableHeight < 0) return;
  637. $('#videospace').width(availableWidth);
  638. $('#videospace').height(availableHeight);
  639. $('#largeVideoContainer').width(availableWidth);
  640. $('#largeVideoContainer').height(availableHeight);
  641. VideoLayout.resizeThumbnails();
  642. };
  643. /**
  644. * Resizes thumbnails.
  645. */
  646. my.resizeThumbnails = function() {
  647. var videoSpaceWidth = $('#remoteVideos').width();
  648. var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
  649. var width = thumbnailSize[0];
  650. var height = thumbnailSize[1];
  651. // size videos so that while keeping AR and max height, we have a
  652. // nice fit
  653. $('#remoteVideos').height(height);
  654. $('#remoteVideos>span').width(width);
  655. $('#remoteVideos>span').height(height);
  656. $(document).trigger("remotevideo.resized", [width, height]);
  657. };
  658. /**
  659. * Enables the dominant speaker UI.
  660. *
  661. * @param resourceJid the jid indicating the video element to
  662. * activate/deactivate
  663. * @param isEnable indicates if the dominant speaker should be enabled or
  664. * disabled
  665. */
  666. my.enableDominantSpeaker = function(resourceJid, isEnable) {
  667. var displayName = resourceJid;
  668. var nameSpan = $('#participant_' + resourceJid + '>span.displayname');
  669. if (nameSpan.length > 0)
  670. displayName = nameSpan.text();
  671. console.log("UI enable dominant speaker",
  672. displayName,
  673. resourceJid,
  674. isEnable);
  675. var videoSpanId = null;
  676. var videoContainerId = null;
  677. if (resourceJid
  678. === Strophe.getResourceFromJid(connection.emuc.myroomjid)) {
  679. videoSpanId = 'localVideoWrapper';
  680. videoContainerId = 'localVideoContainer';
  681. }
  682. else {
  683. videoSpanId = 'participant_' + resourceJid;
  684. videoContainerId = videoSpanId;
  685. }
  686. videoSpan = document.getElementById(videoContainerId);
  687. if (!videoSpan) {
  688. console.error("No video element for jid", resourceJid);
  689. return;
  690. }
  691. var video = $('#' + videoSpanId + '>video');
  692. if (video && video.length > 0) {
  693. if (isEnable) {
  694. VideoLayout.showDisplayName(videoContainerId, true);
  695. if (!videoSpan.classList.contains("dominantspeaker"))
  696. videoSpan.classList.add("dominantspeaker");
  697. video.css({visibility: 'hidden'});
  698. }
  699. else {
  700. VideoLayout.showDisplayName(videoContainerId, false);
  701. if (videoSpan.classList.contains("dominantspeaker"))
  702. videoSpan.classList.remove("dominantspeaker");
  703. video.css({visibility: 'visible'});
  704. }
  705. }
  706. };
  707. /**
  708. * Gets the selector of video thumbnail container for the user identified by
  709. * given <tt>userJid</tt>
  710. * @param userJid user's Jid for whom we want to get the video container.
  711. */
  712. function getParticipantContainer(userJid)
  713. {
  714. if (!userJid)
  715. return null;
  716. if (userJid === connection.emuc.myroomjid)
  717. return $("#localVideoContainer");
  718. else
  719. return $("#participant_" + Strophe.getResourceFromJid(userJid));
  720. }
  721. /**
  722. * Sets the size and position of the given video element.
  723. *
  724. * @param video the video element to position
  725. * @param width the desired video width
  726. * @param height the desired video height
  727. * @param horizontalIndent the left and right indent
  728. * @param verticalIndent the top and bottom indent
  729. */
  730. function positionVideo(video,
  731. width,
  732. height,
  733. horizontalIndent,
  734. verticalIndent) {
  735. video.width(width);
  736. video.height(height);
  737. video.css({ top: verticalIndent + 'px',
  738. bottom: verticalIndent + 'px',
  739. left: horizontalIndent + 'px',
  740. right: horizontalIndent + 'px'});
  741. }
  742. /**
  743. * Calculates the thumbnail size.
  744. *
  745. * @param videoSpaceWidth the width of the video space
  746. */
  747. my.calculateThumbnailSize = function (videoSpaceWidth) {
  748. // Calculate the available height, which is the inner window height minus
  749. // 39px for the header minus 2px for the delimiter lines on the top and
  750. // bottom of the large video, minus the 36px space inside the remoteVideos
  751. // container used for highlighting shadow.
  752. var availableHeight = 100;
  753. var numvids = 0;
  754. if (lastNCount && lastNCount > 0)
  755. numvids = lastNCount + 1;
  756. else
  757. numvids = $('#remoteVideos>span:visible').length;
  758. // Remove the 3px borders arround videos and border around the remote
  759. // videos area
  760. var availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70;
  761. var availableWidth = availableWinWidth / numvids;
  762. var aspectRatio = 16.0 / 9.0;
  763. var maxHeight = Math.min(160, availableHeight);
  764. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  765. if (availableHeight < availableWidth / aspectRatio) {
  766. availableWidth = Math.floor(availableHeight * aspectRatio);
  767. }
  768. return [availableWidth, availableHeight];
  769. };
  770. /**
  771. * Returns an array of the video dimensions, so that it keeps it's aspect
  772. * ratio and fits available area with it's larger dimension. This method
  773. * ensures that whole video will be visible and can leave empty areas.
  774. *
  775. * @return an array with 2 elements, the video width and the video height
  776. */
  777. function getDesktopVideoSize(videoWidth,
  778. videoHeight,
  779. videoSpaceWidth,
  780. videoSpaceHeight) {
  781. if (!videoWidth)
  782. videoWidth = currentVideoWidth;
  783. if (!videoHeight)
  784. videoHeight = currentVideoHeight;
  785. var aspectRatio = videoWidth / videoHeight;
  786. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  787. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  788. videoSpaceHeight -= $('#remoteVideos').outerHeight();
  789. if (availableWidth / aspectRatio >= videoSpaceHeight)
  790. {
  791. availableHeight = videoSpaceHeight;
  792. availableWidth = availableHeight * aspectRatio;
  793. }
  794. if (availableHeight * aspectRatio >= videoSpaceWidth)
  795. {
  796. availableWidth = videoSpaceWidth;
  797. availableHeight = availableWidth / aspectRatio;
  798. }
  799. return [availableWidth, availableHeight];
  800. }
  801. /**
  802. * Creates the edit display name button.
  803. *
  804. * @returns the edit button
  805. */
  806. function createEditDisplayNameButton() {
  807. var editButton = document.createElement('a');
  808. editButton.className = 'displayname';
  809. Util.setTooltip(editButton,
  810. 'Click to edit your<br/>display name',
  811. "top");
  812. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  813. return editButton;
  814. }
  815. /**
  816. * Creates the element indicating the focus of the conference.
  817. *
  818. * @param parentElement the parent element where the focus indicator will
  819. * be added
  820. */
  821. function createFocusIndicatorElement(parentElement) {
  822. var focusIndicator = document.createElement('i');
  823. focusIndicator.className = 'fa fa-star';
  824. parentElement.appendChild(focusIndicator);
  825. Util.setTooltip(parentElement,
  826. "The owner of<br/>this conference",
  827. "top");
  828. }
  829. /**
  830. * Updates the remote video menu.
  831. *
  832. * @param jid the jid indicating the video for which we're adding a menu.
  833. * @param isMuted indicates the current mute state
  834. */
  835. my.updateRemoteVideoMenu = function(jid, isMuted) {
  836. var muteMenuItem
  837. = $('#remote_popupmenu_'
  838. + Strophe.getResourceFromJid(jid)
  839. + '>li>a.mutelink');
  840. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  841. if (muteMenuItem.length) {
  842. var muteLink = muteMenuItem.get(0);
  843. if (isMuted === 'true') {
  844. muteLink.innerHTML = mutedIndicator + ' Muted';
  845. muteLink.className = 'mutelink disabled';
  846. }
  847. else {
  848. muteLink.innerHTML = mutedIndicator + ' Mute';
  849. muteLink.className = 'mutelink';
  850. }
  851. }
  852. };
  853. /**
  854. * Returns the current dominant speaker resource jid.
  855. */
  856. my.getDominantSpeakerResourceJid = function () {
  857. return currentDominantSpeaker;
  858. };
  859. /**
  860. * Returns the corresponding resource jid to the given peer container
  861. * DOM element.
  862. *
  863. * @return the corresponding resource jid to the given peer container
  864. * DOM element
  865. */
  866. my.getPeerContainerResourceJid = function (containerElement) {
  867. var i = containerElement.id.indexOf('participant_');
  868. if (i >= 0)
  869. return containerElement.id.substring(i + 12);
  870. };
  871. /**
  872. * Adds the remote video menu element for the given <tt>jid</tt> in the
  873. * given <tt>parentElement</tt>.
  874. *
  875. * @param jid the jid indicating the video for which we're adding a menu.
  876. * @param parentElement the parent element where this menu will be added
  877. */
  878. function addRemoteVideoMenu(jid, parentElement) {
  879. var spanElement = document.createElement('span');
  880. spanElement.className = 'remotevideomenu';
  881. parentElement.appendChild(spanElement);
  882. var menuElement = document.createElement('i');
  883. menuElement.className = 'fa fa-angle-down';
  884. menuElement.title = 'Remote user controls';
  885. spanElement.appendChild(menuElement);
  886. // <ul class="popupmenu">
  887. // <li><a href="#">Mute</a></li>
  888. // <li><a href="#">Eject</a></li>
  889. // </ul>
  890. var popupmenuElement = document.createElement('ul');
  891. popupmenuElement.className = 'popupmenu';
  892. popupmenuElement.id
  893. = 'remote_popupmenu_' + Strophe.getResourceFromJid(jid);
  894. spanElement.appendChild(popupmenuElement);
  895. var muteMenuItem = document.createElement('li');
  896. var muteLinkItem = document.createElement('a');
  897. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  898. if (!mutedAudios[jid]) {
  899. muteLinkItem.innerHTML = mutedIndicator + 'Mute';
  900. muteLinkItem.className = 'mutelink';
  901. }
  902. else {
  903. muteLinkItem.innerHTML = mutedIndicator + ' Muted';
  904. muteLinkItem.className = 'mutelink disabled';
  905. }
  906. muteLinkItem.onclick = function(){
  907. if ($(this).attr('disabled') != undefined) {
  908. event.preventDefault();
  909. }
  910. var isMute = !mutedAudios[jid];
  911. connection.moderate.setMute(jid, isMute);
  912. popupmenuElement.setAttribute('style', 'display:none;');
  913. if (isMute) {
  914. this.innerHTML = mutedIndicator + ' Muted';
  915. this.className = 'mutelink disabled';
  916. }
  917. else {
  918. this.innerHTML = mutedIndicator + ' Mute';
  919. this.className = 'mutelink';
  920. }
  921. };
  922. muteMenuItem.appendChild(muteLinkItem);
  923. popupmenuElement.appendChild(muteMenuItem);
  924. var ejectIndicator = "<i class='fa fa-eject'></i>";
  925. var ejectMenuItem = document.createElement('li');
  926. var ejectLinkItem = document.createElement('a');
  927. ejectLinkItem.innerHTML = ejectIndicator + ' Kick out';
  928. ejectLinkItem.onclick = function(){
  929. connection.moderate.eject(jid);
  930. popupmenuElement.setAttribute('style', 'display:none;');
  931. };
  932. ejectMenuItem.appendChild(ejectLinkItem);
  933. popupmenuElement.appendChild(ejectMenuItem);
  934. }
  935. /**
  936. * On audio muted event.
  937. */
  938. $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
  939. var videoSpanId = null;
  940. if (jid === connection.emuc.myroomjid) {
  941. videoSpanId = 'localVideoContainer';
  942. } else {
  943. VideoLayout.ensurePeerContainerExists(jid);
  944. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  945. }
  946. if (focus) {
  947. mutedAudios[jid] = isMuted;
  948. VideoLayout.updateRemoteVideoMenu(jid, isMuted);
  949. }
  950. if (videoSpanId)
  951. VideoLayout.showAudioIndicator(videoSpanId, isMuted);
  952. });
  953. /**
  954. * On video muted event.
  955. */
  956. $(document).bind('videomuted.muc', function (event, jid, isMuted) {
  957. var videoSpanId = null;
  958. if (jid === connection.emuc.myroomjid) {
  959. videoSpanId = 'localVideoContainer';
  960. } else {
  961. VideoLayout.ensurePeerContainerExists(jid);
  962. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  963. }
  964. if (videoSpanId)
  965. VideoLayout.showVideoIndicator(videoSpanId, isMuted);
  966. });
  967. /**
  968. * Display name changed.
  969. */
  970. $(document).bind('displaynamechanged',
  971. function (event, jid, displayName, status) {
  972. if (jid === 'localVideoContainer'
  973. || jid === connection.emuc.myroomjid) {
  974. setDisplayName('localVideoContainer',
  975. displayName);
  976. } else {
  977. VideoLayout.ensurePeerContainerExists(jid);
  978. setDisplayName(
  979. 'participant_' + Strophe.getResourceFromJid(jid),
  980. displayName,
  981. status);
  982. }
  983. });
  984. /**
  985. * On dominant speaker changed event.
  986. */
  987. $(document).bind('dominantspeakerchanged', function (event, resourceJid) {
  988. // We ignore local user events.
  989. if (resourceJid
  990. === Strophe.getResourceFromJid(connection.emuc.myroomjid))
  991. return;
  992. // Update the current dominant speaker.
  993. if (resourceJid !== currentDominantSpeaker)
  994. currentDominantSpeaker = resourceJid;
  995. else
  996. return;
  997. // Obtain container for new dominant speaker.
  998. var container = document.getElementById(
  999. 'participant_' + resourceJid);
  1000. // Local video will not have container found, but that's ok
  1001. // since we don't want to switch to local video.
  1002. if (container && !focusedVideoSrc)
  1003. {
  1004. var video = container.getElementsByTagName("video");
  1005. // Update the large video if the video source is already available,
  1006. // otherwise wait for the "videoactive.jingle" event.
  1007. if (video.length && video[0].currentTime > 0)
  1008. VideoLayout.updateLargeVideo(video[0].src);
  1009. }
  1010. });
  1011. /**
  1012. * On last N change event.
  1013. *
  1014. * @param event the event that notified us
  1015. * @param lastNEndpoints the list of last N endpoints
  1016. * @param endpointsEnteringLastN the list currently entering last N
  1017. * endpoints
  1018. */
  1019. $(document).bind('lastnchanged', function ( event,
  1020. lastNEndpoints,
  1021. endpointsEnteringLastN,
  1022. stream) {
  1023. if (lastNCount !== lastNEndpoints.length)
  1024. lastNCount = lastNEndpoints.length;
  1025. lastNEndpointsCache = lastNEndpoints;
  1026. $('#remoteVideos>span').each(function( index, element ) {
  1027. var resourceJid = VideoLayout.getPeerContainerResourceJid(element);
  1028. if (resourceJid
  1029. && lastNEndpoints.length > 0
  1030. && lastNEndpoints.indexOf(resourceJid) < 0) {
  1031. console.log("Remove from last N", resourceJid);
  1032. showPeerContainer(resourceJid, false);
  1033. }
  1034. });
  1035. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  1036. endpointsEnteringLastN = lastNEndpoints;
  1037. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  1038. endpointsEnteringLastN.forEach(function (resourceJid) {
  1039. if (!$('#participant_' + resourceJid).is(':visible')) {
  1040. console.log("Add to last N", resourceJid);
  1041. showPeerContainer(resourceJid, true);
  1042. mediaStreams.some(function (mediaStream) {
  1043. if (mediaStream.peerjid
  1044. && Strophe.getResourceFromJid(mediaStream.peerjid)
  1045. === resourceJid
  1046. && mediaStream.type === mediaStream.VIDEO_TYPE) {
  1047. var sel = $('#participant_' + resourceJid + '>video');
  1048. var simulcast = new Simulcast();
  1049. var videoStream = simulcast.getReceivingVideoStream(mediaStream.stream);
  1050. RTC.attachMediaStream(sel, videoStream);
  1051. waitForRemoteVideo(
  1052. sel,
  1053. mediaStream.ssrc,
  1054. mediaStream.stream);
  1055. return true;
  1056. }
  1057. });
  1058. }
  1059. });
  1060. }
  1061. });
  1062. $(document).bind('videoactive.jingle', function (event, videoelem) {
  1063. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  1064. // ignore mixedmslabela0 and v0
  1065. videoelem.show();
  1066. VideoLayout.resizeThumbnails();
  1067. var videoParent = videoelem.parent();
  1068. var parentResourceJid = null;
  1069. if (videoParent)
  1070. parentResourceJid
  1071. = VideoLayout.getPeerContainerResourceJid(videoParent[0]);
  1072. // Update the large video to the last added video only if there's no
  1073. // current dominant or focused speaker or update it to the current
  1074. // dominant speaker.
  1075. if ((!focusedVideoSrc && !VideoLayout.getDominantSpeakerResourceJid())
  1076. || (parentResourceJid
  1077. && VideoLayout.getDominantSpeakerResourceJid()
  1078. === parentResourceJid)) {
  1079. VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
  1080. }
  1081. VideoLayout.showFocusIndicator();
  1082. }
  1083. });
  1084. /**
  1085. * On simulcast layers changed event.
  1086. */
  1087. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  1088. var simulcast = new Simulcast();
  1089. endpointSimulcastLayers.forEach(function (esl) {
  1090. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1091. simulcast.setReceivingVideoStream(primarySSRC);
  1092. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1093. // Get session and stream from msid.
  1094. var session, electedStream;
  1095. var i, j, k;
  1096. if (connection.jingle) {
  1097. var keys = Object.keys(connection.jingle.sessions);
  1098. for (i = 0; i < keys.length; i++) {
  1099. var sid = keys[i];
  1100. if (electedStream) {
  1101. // stream found, stop.
  1102. break;
  1103. }
  1104. session = connection.jingle.sessions[sid];
  1105. if (session.remoteStreams) {
  1106. for (j = 0; j < session.remoteStreams.length; j++) {
  1107. var remoteStream = session.remoteStreams[j];
  1108. if (electedStream) {
  1109. // stream found, stop.
  1110. break;
  1111. }
  1112. var tracks = remoteStream.getVideoTracks();
  1113. if (tracks) {
  1114. for (k = 0; k < tracks.length; k++) {
  1115. var track = tracks[k];
  1116. if (msid === [remoteStream.id, track.id].join(' ')) {
  1117. electedStream = new webkitMediaStream([track]);
  1118. // stream found, stop.
  1119. break;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. if (session && electedStream) {
  1128. console.info('Switching simulcast substream.');
  1129. console.info([esl, primarySSRC, msid, session, electedStream]);
  1130. var msidParts = msid.split(' ');
  1131. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1132. var updateLargeVideo = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1133. == ssrc2jid[videoSrcToSsrc[$('#largeVideo').attr('src')]]);
  1134. var updateFocusedVideoSrc = (selRemoteVideo.attr('src') == focusedVideoSrc);
  1135. var electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1136. selRemoteVideo.attr('src', electedStreamUrl);
  1137. videoSrcToSsrc[selRemoteVideo.attr('src')] = primarySSRC;
  1138. if (updateLargeVideo) {
  1139. VideoLayout.updateLargeVideo(electedStreamUrl);
  1140. }
  1141. if (updateFocusedVideoSrc) {
  1142. focusedVideoSrc = electedStreamUrl;
  1143. }
  1144. } else {
  1145. console.error('Could not find a stream or a session.');
  1146. }
  1147. });
  1148. });
  1149. return my;
  1150. }(VideoLayout || {}));