Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

videolayout.js 79KB

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