您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SharedVideo.js 25KB

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