Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

videolayout.js 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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.type = 'text';
  455. editableText.id = 'editDisplayName';
  456. if (displayName && displayName.length) {
  457. editableText.value
  458. = displayName.substring(0, displayName.indexOf(' (me)'));
  459. }
  460. editableText.setAttribute('style', 'display:none;');
  461. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  462. $('#' + videoSpanId)[0].appendChild(editableText);
  463. $('#localVideoContainer .displayname')
  464. .bind("click", function (e) {
  465. e.preventDefault();
  466. $('#localDisplayName').hide();
  467. $('#editDisplayName').show();
  468. $('#editDisplayName').focus();
  469. $('#editDisplayName').select();
  470. var inputDisplayNameHandler = function (name) {
  471. if (nickname !== name) {
  472. nickname = name;
  473. window.localStorage.displayname = nickname;
  474. connection.emuc.addDisplayNameToPresence(nickname);
  475. connection.emuc.sendPresence();
  476. Chat.setChatConversationMode(true);
  477. }
  478. if (!$('#localDisplayName').is(":visible")) {
  479. if (nickname)
  480. $('#localDisplayName').text(nickname + " (me)");
  481. else
  482. $('#localDisplayName')
  483. .text(defaultLocalDisplayName);
  484. $('#localDisplayName').show();
  485. }
  486. $('#editDisplayName').hide();
  487. };
  488. $('#editDisplayName').one("focusout", function (e) {
  489. inputDisplayNameHandler(this.value);
  490. });
  491. $('#editDisplayName').on('keydown', function (e) {
  492. if (e.keyCode === 13) {
  493. e.preventDefault();
  494. inputDisplayNameHandler(this.value);
  495. }
  496. });
  497. });
  498. }
  499. }
  500. };
  501. /**
  502. * Shows/hides the display name on the remote video.
  503. * @param videoSpanId the identifier of the video span element
  504. * @param isShow indicates if the display name should be shown or hidden
  505. */
  506. my.showDisplayName = function(videoSpanId, isShow) {
  507. var nameSpan = $('#' + videoSpanId + '>span.displayname').get(0);
  508. if (isShow) {
  509. if (nameSpan && nameSpan.innerHTML && nameSpan.innerHTML.length)
  510. nameSpan.setAttribute("style", "display:inline-block;");
  511. }
  512. else {
  513. if (nameSpan)
  514. nameSpan.setAttribute("style", "display:none;");
  515. }
  516. };
  517. /**
  518. * Shows the presence status message for the given video.
  519. */
  520. my.setPresenceStatus = function (videoSpanId, statusMsg) {
  521. if (!$('#' + videoSpanId).length) {
  522. // No container
  523. return;
  524. }
  525. var statusSpan = $('#' + videoSpanId + '>span.status');
  526. if (!statusSpan.length) {
  527. //Add status span
  528. statusSpan = document.createElement('span');
  529. statusSpan.className = 'status';
  530. statusSpan.id = videoSpanId + '_status';
  531. $('#' + videoSpanId)[0].appendChild(statusSpan);
  532. statusSpan = $('#' + videoSpanId + '>span.status');
  533. }
  534. // Display status
  535. if (statusMsg && statusMsg.length) {
  536. $('#' + videoSpanId + '_status').text(statusMsg);
  537. statusSpan.get(0).setAttribute("style", "display:inline-block;");
  538. }
  539. else {
  540. // Hide
  541. statusSpan.get(0).setAttribute("style", "display:none;");
  542. }
  543. };
  544. /**
  545. * Shows a visual indicator for the focus of the conference.
  546. * Currently if we're not the owner of the conference we obtain the focus
  547. * from the connection.jingle.sessions.
  548. */
  549. my.showFocusIndicator = function() {
  550. if (focus !== null) {
  551. var indicatorSpan = $('#localVideoContainer .focusindicator');
  552. if (indicatorSpan.children().length === 0)
  553. {
  554. createFocusIndicatorElement(indicatorSpan[0]);
  555. }
  556. }
  557. else if (Object.keys(connection.jingle.sessions).length > 0) {
  558. // If we're only a participant the focus will be the only session we have.
  559. var session
  560. = connection.jingle.sessions
  561. [Object.keys(connection.jingle.sessions)[0]];
  562. var focusId
  563. = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
  564. var focusContainer = document.getElementById(focusId);
  565. if (!focusContainer) {
  566. console.error("No focus container!");
  567. return;
  568. }
  569. var indicatorSpan = $('#' + focusId + ' .focusindicator');
  570. if (!indicatorSpan || indicatorSpan.length === 0) {
  571. indicatorSpan = document.createElement('span');
  572. indicatorSpan.className = 'focusindicator';
  573. focusContainer.appendChild(indicatorSpan);
  574. createFocusIndicatorElement(indicatorSpan);
  575. }
  576. }
  577. };
  578. /**
  579. * Shows video muted indicator over small videos.
  580. */
  581. my.showVideoIndicator = function(videoSpanId, isMuted) {
  582. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  583. if (isMuted === 'false') {
  584. if (videoMutedSpan.length > 0) {
  585. videoMutedSpan.remove();
  586. }
  587. }
  588. else {
  589. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  590. videoMutedSpan = document.createElement('span');
  591. videoMutedSpan.className = 'videoMuted';
  592. if (audioMutedSpan) {
  593. videoMutedSpan.right = '30px';
  594. }
  595. $('#' + videoSpanId)[0].appendChild(videoMutedSpan);
  596. var mutedIndicator = document.createElement('i');
  597. mutedIndicator.className = 'icon-camera-disabled';
  598. Util.setTooltip(mutedIndicator,
  599. "Participant has<br/>stopped the camera.",
  600. "top");
  601. videoMutedSpan.appendChild(mutedIndicator);
  602. }
  603. };
  604. /**
  605. * Shows audio muted indicator over small videos.
  606. */
  607. my.showAudioIndicator = function(videoSpanId, isMuted) {
  608. var audioMutedSpan = $('#' + videoSpanId + '>span.audioMuted');
  609. if (isMuted === 'false') {
  610. if (audioMutedSpan.length > 0) {
  611. audioMutedSpan.popover('hide');
  612. audioMutedSpan.remove();
  613. }
  614. }
  615. else {
  616. var videoMutedSpan = $('#' + videoSpanId + '>span.videoMuted');
  617. audioMutedSpan = document.createElement('span');
  618. audioMutedSpan.className = 'audioMuted';
  619. Util.setTooltip(audioMutedSpan,
  620. "Participant is muted",
  621. "top");
  622. if (videoMutedSpan) {
  623. audioMutedSpan.right = '30px';
  624. }
  625. $('#' + videoSpanId)[0].appendChild(audioMutedSpan);
  626. var mutedIndicator = document.createElement('i');
  627. mutedIndicator.className = 'icon-mic-disabled';
  628. audioMutedSpan.appendChild(mutedIndicator);
  629. }
  630. };
  631. /**
  632. * Resizes the large video container.
  633. */
  634. my.resizeLargeVideoContainer = function () {
  635. Chat.resizeChat();
  636. var availableHeight = window.innerHeight;
  637. var availableWidth = Util.getAvailableVideoWidth();
  638. if (availableWidth < 0 || availableHeight < 0) return;
  639. $('#videospace').width(availableWidth);
  640. $('#videospace').height(availableHeight);
  641. $('#largeVideoContainer').width(availableWidth);
  642. $('#largeVideoContainer').height(availableHeight);
  643. VideoLayout.resizeThumbnails();
  644. };
  645. /**
  646. * Resizes thumbnails.
  647. */
  648. my.resizeThumbnails = function() {
  649. var videoSpaceWidth = $('#remoteVideos').width();
  650. var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
  651. var width = thumbnailSize[0];
  652. var height = thumbnailSize[1];
  653. // size videos so that while keeping AR and max height, we have a
  654. // nice fit
  655. $('#remoteVideos').height(height);
  656. $('#remoteVideos>span').width(width);
  657. $('#remoteVideos>span').height(height);
  658. $(document).trigger("remotevideo.resized", [width, height]);
  659. };
  660. /**
  661. * Enables the dominant speaker UI.
  662. *
  663. * @param resourceJid the jid indicating the video element to
  664. * activate/deactivate
  665. * @param isEnable indicates if the dominant speaker should be enabled or
  666. * disabled
  667. */
  668. my.enableDominantSpeaker = function(resourceJid, isEnable) {
  669. var displayName = resourceJid;
  670. var nameSpan = $('#participant_' + resourceJid + '>span.displayname');
  671. if (nameSpan.length > 0)
  672. displayName = nameSpan.text();
  673. console.log("UI enable dominant speaker",
  674. displayName,
  675. resourceJid,
  676. isEnable);
  677. var videoSpanId = null;
  678. var videoContainerId = null;
  679. if (resourceJid
  680. === Strophe.getResourceFromJid(connection.emuc.myroomjid)) {
  681. videoSpanId = 'localVideoWrapper';
  682. videoContainerId = 'localVideoContainer';
  683. }
  684. else {
  685. videoSpanId = 'participant_' + resourceJid;
  686. videoContainerId = videoSpanId;
  687. }
  688. videoSpan = document.getElementById(videoContainerId);
  689. if (!videoSpan) {
  690. console.error("No video element for jid", resourceJid);
  691. return;
  692. }
  693. var video = $('#' + videoSpanId + '>video');
  694. if (video && video.length > 0) {
  695. if (isEnable) {
  696. VideoLayout.showDisplayName(videoContainerId, true);
  697. if (!videoSpan.classList.contains("dominantspeaker"))
  698. videoSpan.classList.add("dominantspeaker");
  699. video.css({visibility: 'hidden'});
  700. }
  701. else {
  702. VideoLayout.showDisplayName(videoContainerId, false);
  703. if (videoSpan.classList.contains("dominantspeaker"))
  704. videoSpan.classList.remove("dominantspeaker");
  705. video.css({visibility: 'visible'});
  706. }
  707. }
  708. };
  709. /**
  710. * Gets the selector of video thumbnail container for the user identified by
  711. * given <tt>userJid</tt>
  712. * @param userJid user's Jid for whom we want to get the video container.
  713. */
  714. function getParticipantContainer(userJid)
  715. {
  716. if (!userJid)
  717. return null;
  718. if (userJid === connection.emuc.myroomjid)
  719. return $("#localVideoContainer");
  720. else
  721. return $("#participant_" + Strophe.getResourceFromJid(userJid));
  722. }
  723. /**
  724. * Sets the size and position of the given video element.
  725. *
  726. * @param video the video element to position
  727. * @param width the desired video width
  728. * @param height the desired video height
  729. * @param horizontalIndent the left and right indent
  730. * @param verticalIndent the top and bottom indent
  731. */
  732. function positionVideo(video,
  733. width,
  734. height,
  735. horizontalIndent,
  736. verticalIndent) {
  737. video.width(width);
  738. video.height(height);
  739. video.css({ top: verticalIndent + 'px',
  740. bottom: verticalIndent + 'px',
  741. left: horizontalIndent + 'px',
  742. right: horizontalIndent + 'px'});
  743. }
  744. /**
  745. * Calculates the thumbnail size.
  746. *
  747. * @param videoSpaceWidth the width of the video space
  748. */
  749. my.calculateThumbnailSize = function (videoSpaceWidth) {
  750. // Calculate the available height, which is the inner window height minus
  751. // 39px for the header minus 2px for the delimiter lines on the top and
  752. // bottom of the large video, minus the 36px space inside the remoteVideos
  753. // container used for highlighting shadow.
  754. var availableHeight = 100;
  755. var numvids = 0;
  756. if (lastNCount && lastNCount > 0)
  757. numvids = lastNCount + 1;
  758. else
  759. numvids = $('#remoteVideos>span:visible').length;
  760. // Remove the 3px borders arround videos and border around the remote
  761. // videos area
  762. var availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70;
  763. var availableWidth = availableWinWidth / numvids;
  764. var aspectRatio = 16.0 / 9.0;
  765. var maxHeight = Math.min(160, availableHeight);
  766. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  767. if (availableHeight < availableWidth / aspectRatio) {
  768. availableWidth = Math.floor(availableHeight * aspectRatio);
  769. }
  770. return [availableWidth, availableHeight];
  771. };
  772. /**
  773. * Returns an array of the video dimensions, so that it keeps it's aspect
  774. * ratio and fits available area with it's larger dimension. This method
  775. * ensures that whole video will be visible and can leave empty areas.
  776. *
  777. * @return an array with 2 elements, the video width and the video height
  778. */
  779. function getDesktopVideoSize(videoWidth,
  780. videoHeight,
  781. videoSpaceWidth,
  782. videoSpaceHeight) {
  783. if (!videoWidth)
  784. videoWidth = currentVideoWidth;
  785. if (!videoHeight)
  786. videoHeight = currentVideoHeight;
  787. var aspectRatio = videoWidth / videoHeight;
  788. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  789. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  790. videoSpaceHeight -= $('#remoteVideos').outerHeight();
  791. if (availableWidth / aspectRatio >= videoSpaceHeight)
  792. {
  793. availableHeight = videoSpaceHeight;
  794. availableWidth = availableHeight * aspectRatio;
  795. }
  796. if (availableHeight * aspectRatio >= videoSpaceWidth)
  797. {
  798. availableWidth = videoSpaceWidth;
  799. availableHeight = availableWidth / aspectRatio;
  800. }
  801. return [availableWidth, availableHeight];
  802. }
  803. /**
  804. * Creates the edit display name button.
  805. *
  806. * @returns the edit button
  807. */
  808. function createEditDisplayNameButton() {
  809. var editButton = document.createElement('a');
  810. editButton.className = 'displayname';
  811. Util.setTooltip(editButton,
  812. 'Click to edit your<br/>display name',
  813. "top");
  814. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  815. return editButton;
  816. }
  817. /**
  818. * Creates the element indicating the focus of the conference.
  819. *
  820. * @param parentElement the parent element where the focus indicator will
  821. * be added
  822. */
  823. function createFocusIndicatorElement(parentElement) {
  824. var focusIndicator = document.createElement('i');
  825. focusIndicator.className = 'fa fa-star';
  826. parentElement.appendChild(focusIndicator);
  827. Util.setTooltip(parentElement,
  828. "The owner of<br/>this conference",
  829. "top");
  830. }
  831. /**
  832. * Updates the remote video menu.
  833. *
  834. * @param jid the jid indicating the video for which we're adding a menu.
  835. * @param isMuted indicates the current mute state
  836. */
  837. my.updateRemoteVideoMenu = function(jid, isMuted) {
  838. var muteMenuItem
  839. = $('#remote_popupmenu_'
  840. + Strophe.getResourceFromJid(jid)
  841. + '>li>a.mutelink');
  842. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  843. if (muteMenuItem.length) {
  844. var muteLink = muteMenuItem.get(0);
  845. if (isMuted === 'true') {
  846. muteLink.innerHTML = mutedIndicator + ' Muted';
  847. muteLink.className = 'mutelink disabled';
  848. }
  849. else {
  850. muteLink.innerHTML = mutedIndicator + ' Mute';
  851. muteLink.className = 'mutelink';
  852. }
  853. }
  854. };
  855. /**
  856. * Returns the current dominant speaker resource jid.
  857. */
  858. my.getDominantSpeakerResourceJid = function () {
  859. return currentDominantSpeaker;
  860. };
  861. /**
  862. * Returns the corresponding resource jid to the given peer container
  863. * DOM element.
  864. *
  865. * @return the corresponding resource jid to the given peer container
  866. * DOM element
  867. */
  868. my.getPeerContainerResourceJid = function (containerElement) {
  869. var i = containerElement.id.indexOf('participant_');
  870. if (i >= 0)
  871. return containerElement.id.substring(i + 12);
  872. };
  873. /**
  874. * Adds the remote video menu element for the given <tt>jid</tt> in the
  875. * given <tt>parentElement</tt>.
  876. *
  877. * @param jid the jid indicating the video for which we're adding a menu.
  878. * @param parentElement the parent element where this menu will be added
  879. */
  880. function addRemoteVideoMenu(jid, parentElement) {
  881. var spanElement = document.createElement('span');
  882. spanElement.className = 'remotevideomenu';
  883. parentElement.appendChild(spanElement);
  884. var menuElement = document.createElement('i');
  885. menuElement.className = 'fa fa-angle-down';
  886. menuElement.title = 'Remote user controls';
  887. spanElement.appendChild(menuElement);
  888. // <ul class="popupmenu">
  889. // <li><a href="#">Mute</a></li>
  890. // <li><a href="#">Eject</a></li>
  891. // </ul>
  892. var popupmenuElement = document.createElement('ul');
  893. popupmenuElement.className = 'popupmenu';
  894. popupmenuElement.id
  895. = 'remote_popupmenu_' + Strophe.getResourceFromJid(jid);
  896. spanElement.appendChild(popupmenuElement);
  897. var muteMenuItem = document.createElement('li');
  898. var muteLinkItem = document.createElement('a');
  899. var mutedIndicator = "<i class='icon-mic-disabled'></i>";
  900. if (!mutedAudios[jid]) {
  901. muteLinkItem.innerHTML = mutedIndicator + 'Mute';
  902. muteLinkItem.className = 'mutelink';
  903. }
  904. else {
  905. muteLinkItem.innerHTML = mutedIndicator + ' Muted';
  906. muteLinkItem.className = 'mutelink disabled';
  907. }
  908. muteLinkItem.onclick = function(){
  909. if ($(this).attr('disabled') != undefined) {
  910. event.preventDefault();
  911. }
  912. var isMute = !mutedAudios[jid];
  913. connection.moderate.setMute(jid, isMute);
  914. popupmenuElement.setAttribute('style', 'display:none;');
  915. if (isMute) {
  916. this.innerHTML = mutedIndicator + ' Muted';
  917. this.className = 'mutelink disabled';
  918. }
  919. else {
  920. this.innerHTML = mutedIndicator + ' Mute';
  921. this.className = 'mutelink';
  922. }
  923. };
  924. muteMenuItem.appendChild(muteLinkItem);
  925. popupmenuElement.appendChild(muteMenuItem);
  926. var ejectIndicator = "<i class='fa fa-eject'></i>";
  927. var ejectMenuItem = document.createElement('li');
  928. var ejectLinkItem = document.createElement('a');
  929. ejectLinkItem.innerHTML = ejectIndicator + ' Kick out';
  930. ejectLinkItem.onclick = function(){
  931. connection.moderate.eject(jid);
  932. popupmenuElement.setAttribute('style', 'display:none;');
  933. };
  934. ejectMenuItem.appendChild(ejectLinkItem);
  935. popupmenuElement.appendChild(ejectMenuItem);
  936. }
  937. /**
  938. * On audio muted event.
  939. */
  940. $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
  941. var videoSpanId = null;
  942. if (jid === connection.emuc.myroomjid) {
  943. videoSpanId = 'localVideoContainer';
  944. } else {
  945. VideoLayout.ensurePeerContainerExists(jid);
  946. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  947. }
  948. if (focus) {
  949. mutedAudios[jid] = isMuted;
  950. VideoLayout.updateRemoteVideoMenu(jid, isMuted);
  951. }
  952. if (videoSpanId)
  953. VideoLayout.showAudioIndicator(videoSpanId, isMuted);
  954. });
  955. /**
  956. * On video muted event.
  957. */
  958. $(document).bind('videomuted.muc', function (event, jid, isMuted) {
  959. var videoSpanId = null;
  960. if (jid === connection.emuc.myroomjid) {
  961. videoSpanId = 'localVideoContainer';
  962. } else {
  963. VideoLayout.ensurePeerContainerExists(jid);
  964. videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  965. }
  966. if (videoSpanId)
  967. VideoLayout.showVideoIndicator(videoSpanId, isMuted);
  968. });
  969. /**
  970. * Display name changed.
  971. */
  972. $(document).bind('displaynamechanged',
  973. function (event, jid, displayName, status) {
  974. if (jid === 'localVideoContainer'
  975. || jid === connection.emuc.myroomjid) {
  976. setDisplayName('localVideoContainer',
  977. displayName);
  978. } else {
  979. VideoLayout.ensurePeerContainerExists(jid);
  980. setDisplayName(
  981. 'participant_' + Strophe.getResourceFromJid(jid),
  982. displayName,
  983. status);
  984. }
  985. });
  986. /**
  987. * On dominant speaker changed event.
  988. */
  989. $(document).bind('dominantspeakerchanged', function (event, resourceJid) {
  990. // We ignore local user events.
  991. if (resourceJid
  992. === Strophe.getResourceFromJid(connection.emuc.myroomjid))
  993. return;
  994. // Update the current dominant speaker.
  995. if (resourceJid !== currentDominantSpeaker)
  996. currentDominantSpeaker = resourceJid;
  997. else
  998. return;
  999. // Obtain container for new dominant speaker.
  1000. var container = document.getElementById(
  1001. 'participant_' + resourceJid);
  1002. // Local video will not have container found, but that's ok
  1003. // since we don't want to switch to local video.
  1004. if (container && !focusedVideoSrc)
  1005. {
  1006. var video = container.getElementsByTagName("video");
  1007. // Update the large video if the video source is already available,
  1008. // otherwise wait for the "videoactive.jingle" event.
  1009. if (video.length && video[0].currentTime > 0)
  1010. VideoLayout.updateLargeVideo(video[0].src);
  1011. }
  1012. });
  1013. /**
  1014. * On last N change event.
  1015. *
  1016. * @param event the event that notified us
  1017. * @param lastNEndpoints the list of last N endpoints
  1018. * @param endpointsEnteringLastN the list currently entering last N
  1019. * endpoints
  1020. */
  1021. $(document).bind('lastnchanged', function ( event,
  1022. lastNEndpoints,
  1023. endpointsEnteringLastN,
  1024. stream) {
  1025. if (lastNCount !== lastNEndpoints.length)
  1026. lastNCount = lastNEndpoints.length;
  1027. lastNEndpointsCache = lastNEndpoints;
  1028. $('#remoteVideos>span').each(function( index, element ) {
  1029. var resourceJid = VideoLayout.getPeerContainerResourceJid(element);
  1030. if (resourceJid
  1031. && lastNEndpoints.length > 0
  1032. && lastNEndpoints.indexOf(resourceJid) < 0) {
  1033. console.log("Remove from last N", resourceJid);
  1034. showPeerContainer(resourceJid, false);
  1035. }
  1036. });
  1037. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  1038. endpointsEnteringLastN = lastNEndpoints;
  1039. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  1040. endpointsEnteringLastN.forEach(function (resourceJid) {
  1041. if (!$('#participant_' + resourceJid).is(':visible')) {
  1042. console.log("Add to last N", resourceJid);
  1043. showPeerContainer(resourceJid, true);
  1044. mediaStreams.some(function (mediaStream) {
  1045. if (mediaStream.peerjid
  1046. && Strophe.getResourceFromJid(mediaStream.peerjid)
  1047. === resourceJid
  1048. && mediaStream.type === mediaStream.VIDEO_TYPE) {
  1049. var sel = $('#participant_' + resourceJid + '>video');
  1050. var simulcast = new Simulcast();
  1051. var videoStream = simulcast.getReceivingVideoStream(mediaStream.stream);
  1052. RTC.attachMediaStream(sel, videoStream);
  1053. waitForRemoteVideo(
  1054. sel,
  1055. mediaStream.ssrc,
  1056. mediaStream.stream);
  1057. return true;
  1058. }
  1059. });
  1060. }
  1061. });
  1062. }
  1063. });
  1064. $(document).bind('videoactive.jingle', function (event, videoelem) {
  1065. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  1066. // ignore mixedmslabela0 and v0
  1067. videoelem.show();
  1068. VideoLayout.resizeThumbnails();
  1069. var videoParent = videoelem.parent();
  1070. var parentResourceJid = null;
  1071. if (videoParent)
  1072. parentResourceJid
  1073. = VideoLayout.getPeerContainerResourceJid(videoParent[0]);
  1074. // Update the large video to the last added video only if there's no
  1075. // current dominant or focused speaker or update it to the current
  1076. // dominant speaker.
  1077. if ((!focusedVideoSrc && !VideoLayout.getDominantSpeakerResourceJid())
  1078. || (parentResourceJid
  1079. && VideoLayout.getDominantSpeakerResourceJid()
  1080. === parentResourceJid)) {
  1081. VideoLayout.updateLargeVideo(videoelem.attr('src'), 1);
  1082. }
  1083. VideoLayout.showFocusIndicator();
  1084. }
  1085. });
  1086. /**
  1087. * On simulcast layers changed event.
  1088. */
  1089. $(document).bind('simulcastlayerschanged', function (event, endpointSimulcastLayers) {
  1090. var simulcast = new Simulcast();
  1091. endpointSimulcastLayers.forEach(function (esl) {
  1092. var primarySSRC = esl.simulcastLayer.primarySSRC;
  1093. simulcast.setReceivingVideoStream(primarySSRC);
  1094. var msid = simulcast.getRemoteVideoStreamIdBySSRC(primarySSRC);
  1095. // Get session and stream from msid.
  1096. var session, electedStream;
  1097. var i, j, k;
  1098. if (connection.jingle) {
  1099. var keys = Object.keys(connection.jingle.sessions);
  1100. for (i = 0; i < keys.length; i++) {
  1101. var sid = keys[i];
  1102. if (electedStream) {
  1103. // stream found, stop.
  1104. break;
  1105. }
  1106. session = connection.jingle.sessions[sid];
  1107. if (session.remoteStreams) {
  1108. for (j = 0; j < session.remoteStreams.length; j++) {
  1109. var remoteStream = session.remoteStreams[j];
  1110. if (electedStream) {
  1111. // stream found, stop.
  1112. break;
  1113. }
  1114. var tracks = remoteStream.getVideoTracks();
  1115. if (tracks) {
  1116. for (k = 0; k < tracks.length; k++) {
  1117. var track = tracks[k];
  1118. if (msid === [remoteStream.id, track.id].join(' ')) {
  1119. electedStream = new webkitMediaStream([track]);
  1120. // stream found, stop.
  1121. break;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. if (session && electedStream) {
  1130. console.info('Switching simulcast substream.');
  1131. console.info([esl, primarySSRC, msid, session, electedStream]);
  1132. var msidParts = msid.split(' ');
  1133. var selRemoteVideo = $(['#', 'remoteVideo_', session.sid, '_', msidParts[0]].join(''));
  1134. var updateLargeVideo = (ssrc2jid[videoSrcToSsrc[selRemoteVideo.attr('src')]]
  1135. == ssrc2jid[videoSrcToSsrc[$('#largeVideo').attr('src')]]);
  1136. var updateFocusedVideoSrc = (selRemoteVideo.attr('src') == focusedVideoSrc);
  1137. var electedStreamUrl = webkitURL.createObjectURL(electedStream);
  1138. selRemoteVideo.attr('src', electedStreamUrl);
  1139. videoSrcToSsrc[selRemoteVideo.attr('src')] = primarySSRC;
  1140. if (updateLargeVideo) {
  1141. VideoLayout.updateLargeVideo(electedStreamUrl);
  1142. }
  1143. if (updateFocusedVideoSrc) {
  1144. focusedVideoSrc = electedStreamUrl;
  1145. }
  1146. } else {
  1147. console.error('Could not find a stream or a session.');
  1148. }
  1149. });
  1150. });
  1151. return my;
  1152. }(VideoLayout || {}));