Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

videolayout.js 48KB

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