You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SharedVideo.js 24KB

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