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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. /* global $, APP, YT, interfaceConfig, onPlayerReady, onPlayerStateChange,
  2. onPlayerError */
  3. const logger = require('jitsi-meet-logger').getLogger(__filename);
  4. import UIUtil from '../util/UIUtil';
  5. import UIEvents from '../../../service/UI/UIEvents';
  6. import VideoLayout from '../videolayout/VideoLayout';
  7. import LargeContainer from '../videolayout/LargeContainer';
  8. import Filmstrip from '../videolayout/Filmstrip';
  9. import {
  10. createSharedVideoEvent as createEvent,
  11. sendAnalytics
  12. } from '../../../react/features/analytics';
  13. import {
  14. participantJoined,
  15. participantLeft,
  16. pinParticipant
  17. } from '../../../react/features/base/participants';
  18. import {
  19. dockToolbox,
  20. getToolboxHeight,
  21. showToolbox
  22. } from '../../../react/features/toolbox';
  23. export const SHARED_VIDEO_CONTAINER_TYPE = 'sharedvideo';
  24. /**
  25. * Example shared video link.
  26. * @type {string}
  27. */
  28. const defaultSharedVideoLink = 'https://www.youtube.com/watch?v=xNXN7CZk8X0';
  29. const updateInterval = 5000; // milliseconds
  30. /**
  31. * The dialog for user input (video link).
  32. * @type {null}
  33. */
  34. let dialog = null;
  35. window.glob_dbg.ytp_arr = window.glob_dbg.ytp_arr || []
  36. window.glob_dbg.opr_arr = window.glob_dbg.opr_arr || []
  37. window.glob_dbg.opsc_arr = window.glob_dbg.opsc_arr || []
  38. /**
  39. * Manager of shared video.
  40. */
  41. export default class SharedVideoManager {
  42. /**
  43. *
  44. */
  45. constructor(emitter) {
  46. this.emitter = emitter;
  47. this.isSharedVideoShown = false;
  48. this.isPlayerAPILoaded = false;
  49. this.mutedWithUserInteraction = false;
  50. }
  51. /**
  52. * Indicates if the player volume is currently on. This will return true if
  53. * we have an available player, which is currently in a PLAYING state,
  54. * which isn't muted and has it's volume greater than 0.
  55. *
  56. * @returns {boolean} indicating if the volume of the shared video is
  57. * currently on.
  58. */
  59. isSharedVideoVolumeOn() {
  60. return this.player
  61. && this.player.getPlayerState() === YT.PlayerState.PLAYING
  62. && !this.player.isMuted()
  63. && this.player.getVolume() > 0;
  64. }
  65. /**
  66. * Indicates if the local user is the owner of the shared video.
  67. * @returns {*|boolean}
  68. */
  69. isSharedVideoOwner() {
  70. return this.from && APP.conference.isLocalId(this.from);
  71. }
  72. /**
  73. * Starts shared video by asking user for url, or if its already working
  74. * asks whether the user wants to stop sharing the video.
  75. */
  76. toggleSharedVideo() {
  77. if (dialog) {
  78. return;
  79. }
  80. if (!this.isSharedVideoShown) {
  81. requestVideoLink().then(
  82. url => {
  83. this.emitter.emit(
  84. UIEvents.UPDATE_SHARED_VIDEO, url, 'start');
  85. sendAnalytics(createEvent('started'));
  86. },
  87. err => {
  88. logger.log('SHARED VIDEO CANCELED', err);
  89. sendAnalytics(createEvent('canceled'));
  90. }
  91. );
  92. return;
  93. }
  94. if (APP.conference.isLocalId(this.from)) {
  95. showStopVideoPropmpt().then(
  96. () => {
  97. // make sure we stop updates for playing before we send stop
  98. // if we stop it after receiving self presence, we can end
  99. // up sending stop playing, and on the other end it will not
  100. // stop
  101. if (this.intervalId) {
  102. clearInterval(this.intervalId);
  103. this.intervalId = null;
  104. }
  105. this.emitter.emit(
  106. UIEvents.UPDATE_SHARED_VIDEO, this.url, 'stop');
  107. sendAnalytics(createEvent('stopped'));
  108. },
  109. () => {}); // eslint-disable-line no-empty-function
  110. } else {
  111. APP.UI.messageHandler.showWarning({
  112. descriptionKey: 'dialog.alreadySharedVideoMsg',
  113. titleKey: 'dialog.alreadySharedVideoTitle'
  114. });
  115. sendAnalytics(createEvent('already.shared'));
  116. }
  117. }
  118. /**
  119. * Shows the player component and starts the process that will be sending
  120. * updates, if we are the one shared the video.
  121. *
  122. * @param id the id of the sender of the command
  123. * @param url the video url
  124. * @param attributes
  125. */
  126. onSharedVideoStart(id, url, attributes) {
  127. if (this.isSharedVideoShown) {
  128. return;
  129. }
  130. this.isSharedVideoShown = true;
  131. // the video url
  132. this.url = url;
  133. // the owner of the video
  134. this.from = id;
  135. this.mutedWithUserInteraction = APP.conference.isLocalAudioMuted();
  136. // listen for local audio mute events
  137. this.localAudioMutedListener = this.onLocalAudioMuted.bind(this);
  138. this.emitter.on(UIEvents.AUDIO_MUTED, this.localAudioMutedListener);
  139. // This code loads the IFrame Player API code asynchronously.
  140. const tag = document.createElement('script');
  141. tag.src = 'https://www.youtube.com/iframe_api';
  142. const firstScriptTag = document.getElementsByTagName('script')[0];
  143. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  144. // sometimes we receive errors like player not defined
  145. // or player.pauseVideo is not a function
  146. // we need to operate with player after start playing
  147. // self.player will be defined once it start playing
  148. // and will process any initial attributes if any
  149. this.initialAttributes = attributes;
  150. const self = this;
  151. if (self.isPlayerAPILoaded) {
  152. window.onYouTubeIframeAPIReady();
  153. } else {
  154. window.onYouTubeIframeAPIReady = function() {
  155. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onYouTubeIframeAPIReady"}) : 0
  156. self.isPlayerAPILoaded = true;
  157. const showControls
  158. = APP.conference.isLocalId(self.from) ? 1 : 0;
  159. const p = new YT.Player('sharedVideoIFrame', {
  160. height: '100%',
  161. width: '100%',
  162. videoId: self.url,
  163. playerVars: {
  164. 'origin': location.origin,
  165. 'fs': '0',
  166. 'autoplay': 0,
  167. 'controls': showControls,
  168. 'rel': 0
  169. },
  170. events: {
  171. 'onReady': onPlayerReady,
  172. 'onStateChange': onPlayerStateChange,
  173. 'onError': onPlayerError
  174. }
  175. });
  176. // add listener for volume changes
  177. p.addEventListener(
  178. 'onVolumeChange', 'onVolumeChange');
  179. if (APP.conference.isLocalId(self.from)) {
  180. // adds progress listener that will be firing events
  181. // while we are paused and we change the progress of the
  182. // video (seeking forward or backward on the video)
  183. p.addEventListener(
  184. 'onVideoProgress', 'onVideoProgress');
  185. }
  186. };
  187. }
  188. /**
  189. * Indicates that a change in state has occurred for the shared video.
  190. * @param event the event notifying us of the change
  191. */
  192. window.onPlayerStateChange = function(event) {
  193. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onPlayerStateChange"}) : 0
  194. // eslint-disable-next-line eqeqeq
  195. if (event.data == YT.PlayerState.PLAYING) {
  196. self.player = event.target;
  197. // window.glob_dbg.ytp_arr.push(self.player)
  198. // window.glob_dbg.opsc_arr.push(self.player)
  199. window.glob_dbg.ytp = self.player
  200. if (self.initialAttributes) {
  201. // If a network update has occurred already now is the
  202. // time to process it.
  203. self.processVideoUpdate(
  204. self.player,
  205. self.initialAttributes);
  206. self.initialAttributes = null;
  207. }
  208. self.smartAudioMute();
  209. // eslint-disable-next-line eqeqeq
  210. } else if (event.data == YT.PlayerState.PAUSED) {
  211. self.smartAudioUnmute();
  212. sendAnalytics(createEvent('paused'));
  213. }
  214. // eslint-disable-next-line eqeqeq
  215. self.fireSharedVideoEvent(event.data == YT.PlayerState.PAUSED);
  216. };
  217. /**
  218. * Track player progress while paused.
  219. * @param event
  220. */
  221. window.onVideoProgress = function(event) {
  222. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onVideoProgress"}) : 0
  223. const state = event.target.getPlayerState();
  224. // eslint-disable-next-line eqeqeq
  225. if (state == YT.PlayerState.PAUSED) {
  226. self.fireSharedVideoEvent(true);
  227. }
  228. };
  229. /**
  230. * Gets notified for volume state changed.
  231. * @param event
  232. */
  233. window.onVolumeChange = function(event) {
  234. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onVolumeChange"}) : 0
  235. self.fireSharedVideoEvent();
  236. // let's check, if player is not muted lets mute locally
  237. if (event.data.volume > 0 && !event.data.muted) {
  238. self.smartAudioMute();
  239. } else if (event.data.volume <= 0 || event.data.muted) {
  240. self.smartAudioUnmute();
  241. }
  242. sendAnalytics(createEvent(
  243. 'volume.changed',
  244. {
  245. volume: event.data.volume,
  246. muted: event.data.muted
  247. }));
  248. };
  249. window.onPlayerReady = function(event) {
  250. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onPlayerReady"}) : 0
  251. const player = event.target;
  252. // window.glob_dbg.ytp_arr.push(player)
  253. // window.glob_dbg.opr_arr.push(player)
  254. window.glob_dbg.ytp = player
  255. window.glob_dbg.ytp_pr = player
  256. window.glob_dbg.slf = self
  257. // clog("onPlayerReady...",self)
  258. self.ytp = player
  259. // do not relay on autoplay as it is not sending all of the events
  260. // in onPlayerStateChange
  261. window.glob_dbg.opr_pv = player.playVideo();
  262. const iframe = player.getIframe();
  263. // eslint-disable-next-line no-use-before-define
  264. self.sharedVideo = new SharedVideoContainer(
  265. { url,
  266. iframe,
  267. player });
  268. // prevents pausing participants not sharing the video
  269. // to pause the video
  270. if (!APP.conference.isLocalId(self.from)) {
  271. $('#sharedVideo').css('pointer-events', 'none');
  272. }
  273. VideoLayout.addLargeVideoContainer(
  274. SHARED_VIDEO_CONTAINER_TYPE, self.sharedVideo);
  275. APP.store.dispatch(participantJoined({
  276. // FIXME The cat is out of the bag already or rather _room is
  277. // not private because it is used in multiple other places
  278. // already such as AbstractPageReloadOverlay.
  279. conference: APP.conference._room,
  280. id: self.url,
  281. isFakeParticipant: true,
  282. name: 'YouTube'
  283. }));
  284. APP.store.dispatch(pinParticipant(self.url));
  285. // If we are sending the command and we are starting the player
  286. // we need to continuously send the player current time position
  287. if (APP.conference.isLocalId(self.from)) {
  288. self.intervalId = setInterval(
  289. self.fireSharedVideoEvent.bind(self),
  290. updateInterval);
  291. }
  292. };
  293. window.onPlayerError = function(event) {
  294. window.svm_win ? window.svm_win.svm({that:this,self,args:arguments,fn_name:"onPlayerError"}) : 0
  295. logger.error('Error in the player:', event.data);
  296. // store the error player, so we can remove it
  297. self.errorInPlayer = event.target;
  298. };
  299. }
  300. /**
  301. * Process attributes, whether player needs to be paused or seek.
  302. * @param player the player to operate over
  303. * @param attributes the attributes with the player state we want
  304. */
  305. processVideoUpdate(player, attributes) {
  306. if (!attributes) {
  307. return;
  308. }
  309. // eslint-disable-next-line eqeqeq
  310. if (attributes.state == 'playing') {
  311. const isPlayerPaused
  312. = this.player.getPlayerState() === YT.PlayerState.PAUSED;
  313. // If our player is currently paused force the seek.
  314. this.processTime(player, attributes, isPlayerPaused);
  315. // Process mute.
  316. const isAttrMuted = attributes.muted === 'true';
  317. if (player.isMuted() !== isAttrMuted) {
  318. this.smartPlayerMute(isAttrMuted, true);
  319. }
  320. // Process volume
  321. if (!isAttrMuted
  322. && attributes.volume !== undefined
  323. // eslint-disable-next-line eqeqeq
  324. && player.getVolume() != attributes.volume) {
  325. player.setVolume(attributes.volume);
  326. logger.info(`Player change of volume:${attributes.volume}`);
  327. }
  328. if (isPlayerPaused) {
  329. window.glob_dbg.pvu_pv = player.playVideo();
  330. }
  331. // eslint-disable-next-line eqeqeq
  332. } else if (attributes.state == 'pause') {
  333. // if its not paused, pause it
  334. player.pauseVideo();
  335. this.processTime(player, attributes, true);
  336. }
  337. }
  338. /**
  339. * Check for time in attributes and if needed seek in current player
  340. * @param player the player to operate over
  341. * @param attributes the attributes with the player state we want
  342. * @param forceSeek whether seek should be forced
  343. */
  344. processTime(player, attributes, forceSeek) {
  345. if (forceSeek) {
  346. logger.info('Player seekTo:', attributes.time);
  347. player.seekTo(attributes.time);
  348. return;
  349. }
  350. // check received time and current time
  351. const currentPosition = player.getCurrentTime();
  352. const diff = Math.abs(attributes.time - currentPosition);
  353. // if we drift more than the interval for checking
  354. // sync, the interval is in milliseconds
  355. if (diff > updateInterval / 1000) {
  356. logger.info('Player seekTo:', attributes.time,
  357. ' current time is:', currentPosition, ' diff:', diff);
  358. player.seekTo(attributes.time);
  359. }
  360. }
  361. /**
  362. * Checks current state of the player and fire an event with the values.
  363. */
  364. fireSharedVideoEvent(sendPauseEvent) {
  365. // ignore update checks if we are not the owner of the video
  366. // or there is still no player defined or we are stopped
  367. // (in a process of stopping)
  368. if (!APP.conference.isLocalId(this.from) || !this.player
  369. || !this.isSharedVideoShown) {
  370. return;
  371. }
  372. const state = this.player.getPlayerState();
  373. // if its paused and haven't been pause - send paused
  374. if (state === YT.PlayerState.PAUSED && sendPauseEvent) {
  375. this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
  376. this.url, 'pause', this.player.getCurrentTime());
  377. } else if (state === YT.PlayerState.PLAYING) {
  378. // if its playing and it was paused - send update with time
  379. // if its playing and was playing just send update with time
  380. this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
  381. this.url, 'playing',
  382. this.player.getCurrentTime(),
  383. this.player.isMuted(),
  384. this.player.getVolume());
  385. }
  386. }
  387. /**
  388. * Updates video, if it's not playing and needs starting or if it's playing
  389. * and needs to be paused.
  390. * @param id the id of the sender of the command
  391. * @param url the video url
  392. * @param attributes
  393. */
  394. onSharedVideoUpdate(id, url, attributes) {
  395. // if we are sending the event ignore
  396. if (APP.conference.isLocalId(this.from)) {
  397. return;
  398. }
  399. if (!this.isSharedVideoShown) {
  400. this.onSharedVideoStart(id, url, attributes);
  401. return;
  402. }
  403. // eslint-disable-next-line no-negated-condition
  404. this.attr_cache = attributes
  405. if (!this.player) {
  406. this.initialAttributes = attributes;
  407. } else {
  408. this.processVideoUpdate(this.player, attributes);
  409. }
  410. }
  411. /**
  412. * Stop shared video if it is currently showed. If the user started the
  413. * shared video is the one in the id (called when user
  414. * left and we want to remove video if the user sharing it left).
  415. * @param id the id of the sender of the command
  416. */
  417. onSharedVideoStop(id, attributes) {
  418. if (!this.isSharedVideoShown) {
  419. return;
  420. }
  421. if (this.from !== id) {
  422. return;
  423. }
  424. if (!this.player) {
  425. // if there is no error in the player till now,
  426. // store the initial attributes
  427. if (!this.errorInPlayer) {
  428. this.initialAttributes = attributes;
  429. return;
  430. }
  431. }
  432. this.emitter.removeListener(UIEvents.AUDIO_MUTED,
  433. this.localAudioMutedListener);
  434. this.localAudioMutedListener = null;
  435. APP.store.dispatch(participantLeft(this.url, APP.conference._room));
  436. VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
  437. .then(() => {
  438. VideoLayout.removeLargeVideoContainer(
  439. SHARED_VIDEO_CONTAINER_TYPE);
  440. if (this.player) {
  441. this.player.destroy();
  442. this.player = null;
  443. } else if (this.errorInPlayer) {
  444. // if there is an error in player, remove that instance
  445. this.errorInPlayer.destroy();
  446. this.errorInPlayer = null;
  447. }
  448. this.smartAudioUnmute();
  449. // revert to original behavior (prevents pausing
  450. // for participants not sharing the video to pause it)
  451. $('#sharedVideo').css('pointer-events', 'auto');
  452. this.emitter.emit(
  453. UIEvents.UPDATE_SHARED_VIDEO, null, 'removed');
  454. });
  455. this.url = null;
  456. this.isSharedVideoShown = false;
  457. this.initialAttributes = null;
  458. }
  459. /**
  460. * Receives events for local audio mute/unmute by local user.
  461. * @param muted boolena whether it is muted or not.
  462. * @param {boolean} indicates if this mute was a result of user interaction,
  463. * i.e. pressing the mute button or it was programatically triggerred
  464. */
  465. onLocalAudioMuted(muted, userInteraction) {
  466. if (!this.player) {
  467. return;
  468. }
  469. if (muted) {
  470. this.mutedWithUserInteraction = userInteraction;
  471. } else if (this.player.getPlayerState() !== YT.PlayerState.PAUSED) {
  472. this.smartPlayerMute(true, false);
  473. // Check if we need to update other participants
  474. this.fireSharedVideoEvent();
  475. }
  476. }
  477. /**
  478. * Mutes / unmutes the player.
  479. * @param mute true to mute the shared video, false - otherwise.
  480. * @param {boolean} Indicates if this mute is a consequence of a network
  481. * video update or is called locally.
  482. */
  483. smartPlayerMute(mute, isVideoUpdate) {
  484. if (!this.player.isMuted() && mute) {
  485. this.player.mute();
  486. if (isVideoUpdate) {
  487. this.smartAudioUnmute();
  488. }
  489. } else if (this.player.isMuted() && !mute) {
  490. this.player.unMute();
  491. if (isVideoUpdate) {
  492. this.smartAudioMute();
  493. }
  494. }
  495. }
  496. /**
  497. * Smart mike unmute. If the mike is currently muted and it wasn't muted
  498. * by the user via the mike button and the volume of the shared video is on
  499. * we're unmuting the mike automatically.
  500. */
  501. smartAudioUnmute() {
  502. if (APP.conference.isLocalAudioMuted()
  503. && !this.mutedWithUserInteraction
  504. && !this.isSharedVideoVolumeOn()) {
  505. sendAnalytics(createEvent('audio.unmuted'));
  506. logger.log('Shared video: audio unmuted');
  507. this.emitter.emit(UIEvents.AUDIO_MUTED, false, false);
  508. }
  509. }
  510. /**
  511. * Smart mike mute. If the mike isn't currently muted and the shared video
  512. * volume is on we mute the mike.
  513. */
  514. smartAudioMute() {
  515. if (!APP.conference.isLocalAudioMuted()
  516. && this.isSharedVideoVolumeOn()) {
  517. sendAnalytics(createEvent('audio.muted'));
  518. logger.log('Shared video: audio muted');
  519. this.emitter.emit(UIEvents.AUDIO_MUTED, true, false);
  520. }
  521. }
  522. }
  523. /**
  524. * Container for shared video iframe.
  525. */
  526. class SharedVideoContainer extends LargeContainer {
  527. /**
  528. *
  529. */
  530. constructor({ url, iframe, player }) {
  531. super();
  532. this.$iframe = $(iframe);
  533. this.url = url;
  534. this.player = player;
  535. }
  536. /**
  537. *
  538. */
  539. show() {
  540. const self = this;
  541. return new Promise(resolve => {
  542. this.$iframe.fadeIn(300, () => {
  543. self.bodyBackground = document.body.style.background;
  544. document.body.style.background = 'black';
  545. this.$iframe.css({ opacity: 1 });
  546. APP.store.dispatch(dockToolbox(true));
  547. resolve();
  548. });
  549. });
  550. }
  551. /**
  552. *
  553. */
  554. hide() {
  555. const self = this;
  556. APP.store.dispatch(dockToolbox(false));
  557. return new Promise(resolve => {
  558. this.$iframe.fadeOut(300, () => {
  559. document.body.style.background = self.bodyBackground;
  560. this.$iframe.css({ opacity: 0 });
  561. resolve();
  562. });
  563. });
  564. }
  565. /**
  566. *
  567. */
  568. onHoverIn() {
  569. try {
  570. var fn_name = "SVC_onHoverIn"
  571. var fn_ret
  572. glob_dev_fns[fn_name] ? fn_ret = glob_dev_fns[fn_name]({that:this,kv:{
  573. // ret,
  574. // _feedbackConfigured,_fullScreen,_screensharing,_sharingVideo,t,
  575. },args:[...arguments],fn_name,arg0:arguments}) : clog("NO EXIST....")
  576. if (fn_ret){ return fn_ret.ret };
  577. } catch (err) { clog(`react_fn fn_name:${fn_name} err:`,err) }
  578. APP.store.dispatch(showToolbox());
  579. }
  580. /**
  581. *
  582. */
  583. get id() {
  584. return this.url;
  585. }
  586. /**
  587. *
  588. */
  589. resize(containerWidth, containerHeight) {
  590. let height, width;
  591. if (interfaceConfig.VERTICAL_FILMSTRIP) {
  592. height = containerHeight - getToolboxHeight();
  593. width = containerWidth - Filmstrip.getVerticalFilmstripWidth();
  594. } else {
  595. height = containerHeight - Filmstrip.getFilmstripHeight();
  596. width = containerWidth;
  597. }
  598. this.$iframe.width(width).height(height);
  599. }
  600. /**
  601. * @return {boolean} do not switch on dominant speaker event if on stage.
  602. */
  603. stayOnStage() {
  604. return false;
  605. }
  606. }
  607. /**
  608. * Checks if given string is youtube url.
  609. * @param {string} url string to check.
  610. * @returns {boolean}
  611. */
  612. function getYoutubeLink(url) {
  613. const p = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;// eslint-disable-line max-len
  614. return url.match(p) ? RegExp.$1 : false;
  615. }
  616. /**
  617. * Ask user if he want to close shared video.
  618. */
  619. function showStopVideoPropmpt() {
  620. return new Promise((resolve, reject) => {
  621. const submitFunction = function(e, v) {
  622. if (v) {
  623. resolve();
  624. } else {
  625. reject();
  626. }
  627. };
  628. const closeFunction = function() {
  629. dialog = null;
  630. };
  631. dialog = APP.UI.messageHandler.openTwoButtonDialog({
  632. titleKey: 'dialog.removeSharedVideoTitle',
  633. msgKey: 'dialog.removeSharedVideoMsg',
  634. leftButtonKey: 'dialog.Remove',
  635. submitFunction,
  636. closeFunction
  637. });
  638. });
  639. }
  640. /**
  641. * Ask user for shared video url to share with others.
  642. * Dialog validates client input to allow only youtube urls.
  643. */
  644. function requestVideoLink() {
  645. const i18n = APP.translation;
  646. const cancelButton = i18n.generateTranslationHTML('dialog.Cancel');
  647. const shareButton = i18n.generateTranslationHTML('dialog.Share');
  648. const backButton = i18n.generateTranslationHTML('dialog.Back');
  649. const linkError
  650. = i18n.generateTranslationHTML('dialog.shareVideoLinkError');
  651. return new Promise((resolve, reject) => {
  652. dialog = APP.UI.messageHandler.openDialogWithStates({
  653. state0: {
  654. titleKey: 'dialog.shareVideoTitle',
  655. html: `
  656. <input name='sharedVideoUrl' type='text'
  657. class='input-control'
  658. data-i18n='[placeholder]defaultLink'
  659. autofocus>`,
  660. persistent: false,
  661. buttons: [
  662. { title: cancelButton,
  663. value: false },
  664. { title: shareButton,
  665. value: true }
  666. ],
  667. focus: ':input:first',
  668. defaultButton: 1,
  669. submit(e, v, m, f) { // eslint-disable-line max-params
  670. e.preventDefault();
  671. if (!v) {
  672. reject('cancelled');
  673. dialog.close();
  674. return;
  675. }
  676. const sharedVideoUrl = f.sharedVideoUrl;
  677. if (!sharedVideoUrl) {
  678. return;
  679. }
  680. const urlValue
  681. = encodeURI(UIUtil.escapeHtml(sharedVideoUrl));
  682. const yVideoId = getYoutubeLink(urlValue);
  683. if (!yVideoId) {
  684. dialog.goToState('state1');
  685. return false;
  686. }
  687. resolve(yVideoId);
  688. dialog.close();
  689. }
  690. },
  691. state1: {
  692. titleKey: 'dialog.shareVideoTitle',
  693. html: linkError,
  694. persistent: false,
  695. buttons: [
  696. { title: cancelButton,
  697. value: false },
  698. { title: backButton,
  699. value: true }
  700. ],
  701. focus: ':input:first',
  702. defaultButton: 1,
  703. submit(e, v) {
  704. e.preventDefault();
  705. if (v === 0) {
  706. reject();
  707. dialog.close();
  708. } else {
  709. dialog.goToState('state0');
  710. }
  711. }
  712. }
  713. }, {
  714. close() {
  715. dialog = null;
  716. }
  717. }, {
  718. url: defaultSharedVideoLink
  719. });
  720. });
  721. }
  722. window.glob_react.SharedVideoContainer=SharedVideoContainer