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