@atlaskit/media-ui 28.5.2 → 28.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/customMediaPlayer/index.js +1 -1
  3. package/dist/cjs/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  4. package/dist/cjs/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +81 -147
  5. package/dist/cjs/customMediaPlayer/mediaPlayer/types.js +5 -0
  6. package/dist/cjs/customMediaPlayer/mediaPlayer/useTextTracks.js +139 -66
  7. package/dist/es2019/customMediaPlayer/index.js +1 -1
  8. package/dist/es2019/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  9. package/dist/es2019/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +29 -111
  10. package/dist/es2019/customMediaPlayer/mediaPlayer/types.js +1 -0
  11. package/dist/es2019/customMediaPlayer/mediaPlayer/useTextTracks.js +129 -43
  12. package/dist/esm/customMediaPlayer/index.js +1 -1
  13. package/dist/esm/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  14. package/dist/esm/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +81 -147
  15. package/dist/esm/customMediaPlayer/mediaPlayer/types.js +1 -0
  16. package/dist/esm/customMediaPlayer/mediaPlayer/useTextTracks.js +140 -67
  17. package/dist/types/customMediaPlayer/mediaPlayer/index.d.ts +2 -1
  18. package/dist/types/customMediaPlayer/mediaPlayer/mediaPlayer.d.ts +2 -3
  19. package/dist/types/customMediaPlayer/mediaPlayer/mediaPlayerBase.d.ts +1 -34
  20. package/dist/types/customMediaPlayer/mediaPlayer/types.d.ts +38 -0
  21. package/dist/types/customMediaPlayer/mediaPlayer/useTextTracks.d.ts +8 -2
  22. package/dist/types/customMediaPlayer/react-video-renderer/text.d.ts +3 -2
  23. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/index.d.ts +2 -1
  24. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/mediaPlayer.d.ts +2 -3
  25. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/mediaPlayerBase.d.ts +1 -34
  26. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/types.d.ts +38 -0
  27. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/useTextTracks.d.ts +8 -2
  28. package/dist/types-ts4.5/customMediaPlayer/react-video-renderer/text.d.ts +3 -2
  29. package/package.json +2 -2
@@ -1,61 +1,147 @@
1
1
  import { hasArtifacts } from '@atlaskit/media-client';
2
- import { useState, useEffect } from 'react';
2
+ import { useState, useEffect, useMemo, useCallback, useRef } from 'react';
3
+ import { useMediaClient, useMediaSettings } from '@atlaskit/media-client-react';
4
+ import { getUserCaptionsEnabled, getUserCaptionsLocale, findPreselectedTrackIndex, setUserCaptionsEnabled, setUserCaptionsLocale } from './captions';
5
+ import { useIntl } from 'react-intl-next';
3
6
  const decodeMimetype = mimeType => {
4
7
  const keyValues = (mimeType === null || mimeType === void 0 ? void 0 : mimeType.split(';')) || [];
5
8
  const captionsRawMetadata = Object.fromEntries(keyValues.map(keyValue => keyValue.split('=')));
9
+ const fileName = captionsRawMetadata.n ? atob(captionsRawMetadata.n) : 'no-name';
10
+ const lang = captionsRawMetadata.l || 'en';
6
11
  return {
7
- lang: captionsRawMetadata.l || 'en',
8
- fileName: captionsRawMetadata.f || 'no-name.vtt',
9
- label: captionsRawMetadata.label || 'no-name'
12
+ lang,
13
+ fileName,
14
+ label: lang
10
15
  };
11
16
  };
12
- export const useTextTracks = (fileState, mediaClient, collectionName) => {
13
- const [textTracks, setTextTracks] = useState();
17
+ const NO_SELECTED_TRACKS_INDEX = -1;
18
+ export const useTextTracks = (fileState, collectionName) => {
19
+ const mediaClient = useMediaClient();
20
+ const isLoadingCaptionsObjectURLs = useRef(new Map());
21
+ const captionsObjectURLs = useRef(new Map());
22
+ const intl = useIntl();
23
+ const {
24
+ mediaUserPreferences
25
+ } = useMediaSettings() || {};
26
+ const [captionTracks, setCaptionTracks] = useState([]);
27
+ const [areCaptionsEnabled, setAreCaptionsEnabled] = useState(mediaUserPreferences ? getUserCaptionsEnabled(mediaUserPreferences) : false);
28
+ const [selectedTracksIndex, setSelectedTracksIndex] = useState(NO_SELECTED_TRACKS_INDEX);
29
+ const resolvedSelectedTracksIndex = useMemo(() => {
30
+ return areCaptionsEnabled ? selectedTracksIndex : NO_SELECTED_TRACKS_INDEX;
31
+ }, [areCaptionsEnabled, selectedTracksIndex]);
32
+
33
+ // When video starts playing, user settings might have changed
34
+ const verifyUserCaptionsEnabled = useCallback(() => {
35
+ if (mediaUserPreferences) {
36
+ setAreCaptionsEnabled(getUserCaptionsEnabled(mediaUserPreferences));
37
+ }
38
+ }, [mediaUserPreferences]);
39
+
40
+ // Converts file artifacts to base text tracks, i.e. text tracks with a source creator function.
41
+ // The src is resolved on every selected track change.
14
42
  useEffect(() => {
15
43
  if (!fileState || !hasArtifacts(fileState)) {
44
+ setCaptionTracks([]);
16
45
  return;
17
46
  }
18
- const captions = Object.entries(fileState.artifacts || {}).filter(caption => {
47
+ const captionsArtifacts = Object.entries(fileState.artifacts || {}).filter(caption => {
19
48
  const [key, value] = caption;
20
49
  return key.includes('ugc_caption') && !!value;
21
50
  });
22
- if (captions.length > 0) {
23
- Promise.all(captions.map(async ([artifactName, {
24
- mimeType
25
- }]) => {
26
- try {
27
- const {
28
- artifacts
29
- } = fileState;
30
- const baseUrl = artifacts && (await (mediaClient === null || mediaClient === void 0 ? void 0 : mediaClient.mediaStore.getArtifactBinary(artifacts, artifactName, {
31
- collectionName
32
- })));
33
- const src = baseUrl && URL.createObjectURL(baseUrl) || '';
34
- const {
35
- lang,
36
- label
37
- } = decodeMimetype(mimeType);
38
- return {
39
- src,
40
- lang,
41
- label,
42
- artifactName
43
- };
44
- } catch (error) {
45
- // TODO: Handle these errors
51
+ setCaptionTracks(captionsArtifacts.map(([artifactName, {
52
+ mimeType
53
+ }]) => {
54
+ const {
55
+ lang,
56
+ label
57
+ } = decodeMimetype(mimeType);
58
+ const src = captionsObjectURLs.current.get(artifactName);
59
+ return {
60
+ lang,
61
+ label,
62
+ artifactName,
63
+ src
64
+ };
65
+ })
66
+ // Sort based on current locale
67
+ .sort((a, b) => a.lang.localeCompare(b.lang, intl.locale)));
68
+ }, [fileState, intl.locale]);
69
+
70
+ // Update the user caption enabled preferences
71
+ useEffect(() => {
72
+ if (mediaUserPreferences) {
73
+ setUserCaptionsEnabled(mediaUserPreferences, areCaptionsEnabled);
74
+ }
75
+ }, [mediaUserPreferences, areCaptionsEnabled]);
76
+
77
+ // Update the user locale preferences
78
+ useEffect(() => {
79
+ const {
80
+ lang
81
+ } = captionTracks[resolvedSelectedTracksIndex] || {};
82
+ if (mediaUserPreferences && lang) {
83
+ setUserCaptionsLocale(mediaUserPreferences, lang);
84
+ }
85
+ }, [mediaUserPreferences, captionTracks, resolvedSelectedTracksIndex]);
86
+
87
+ // Reset the selected track index when the locale or text tracks change
88
+ useEffect(() => {
89
+ const preselectedTrackIndex = findPreselectedTrackIndex(captionTracks, intl.locale, mediaUserPreferences && getUserCaptionsLocale(mediaUserPreferences));
90
+ setSelectedTracksIndex(preselectedTrackIndex || 0);
91
+ }, [mediaUserPreferences, intl.locale, captionTracks]);
92
+ useEffect(() => {
93
+ if (fileState && hasArtifacts(fileState)) {
94
+ const {
95
+ artifactName,
96
+ src
97
+ } = captionTracks[resolvedSelectedTracksIndex] || {};
98
+ if (artifactName && !src && !isLoadingCaptionsObjectURLs.current.get(artifactName)) {
99
+ isLoadingCaptionsObjectURLs.current.set(artifactName, true);
100
+ mediaClient.mediaStore.getArtifactBinary(fileState.artifacts, artifactName, {
101
+ collectionName
102
+ }).then(blob => {
103
+ const objectUrl = URL.createObjectURL(blob);
104
+ captionsObjectURLs.current.set(artifactName, objectUrl);
105
+ setCaptionTracks(prevCaptionTracks => {
106
+ const newCaptionTracks = [...prevCaptionTracks];
107
+ newCaptionTracks[resolvedSelectedTracksIndex] = {
108
+ ...newCaptionTracks[resolvedSelectedTracksIndex],
109
+ src: objectUrl
110
+ };
111
+ return newCaptionTracks;
112
+ });
113
+ }).catch(error => {
114
+ // TODO: Handle this error
46
115
  // https://product-fabric.atlassian.net/browse/BMPT-6929
47
- }
48
- })).then(tracks => {
49
- setTextTracks({
50
- captions: {
51
- selectedTrackIndex: 1,
52
- tracks: tracks.filter(track => !!(track !== null && track !== void 0 && track.src))
53
- }
116
+ }).finally(() => {
117
+ isLoadingCaptionsObjectURLs.current.set(artifactName, false);
54
118
  });
55
- });
56
- } else {
57
- setTextTracks(undefined);
119
+ }
58
120
  }
59
- }, [fileState, collectionName, mediaClient]);
60
- return textTracks;
121
+ }, [resolvedSelectedTracksIndex, captionTracks, mediaClient, fileState, collectionName]);
122
+
123
+ // Revokes the object urls when the component unmounts.
124
+ useEffect(() => {
125
+ const currentCaptionsObjectURLs = captionsObjectURLs.current;
126
+ return () => {
127
+ currentCaptionsObjectURLs.forEach(objectUrl => {
128
+ URL.revokeObjectURL(objectUrl);
129
+ });
130
+ };
131
+ }, []);
132
+ const textTracks = useMemo(() => {
133
+ return {
134
+ captions: {
135
+ selectedTrackIndex: resolvedSelectedTracksIndex,
136
+ tracks: captionTracks
137
+ }
138
+ };
139
+ }, [captionTracks, resolvedSelectedTracksIndex]);
140
+ return {
141
+ textTracks,
142
+ verifyUserCaptionsEnabled,
143
+ areCaptionsEnabled,
144
+ setSelectedTracksIndex,
145
+ setAreCaptionsEnabled
146
+ };
61
147
  };
@@ -9,7 +9,7 @@ export var CustomMediaPlayerBase = function CustomMediaPlayerBase(props) {
9
9
  return fg('platform_media_compiled') ? /*#__PURE__*/React.createElement(CompiledCustomMediaPlayerBase, props) : /*#__PURE__*/React.createElement(EmotionCustomMediaPlayerBase, props);
10
10
  };
11
11
  var packageName = "@atlaskit/media-ui";
12
- var packageVersion = "28.5.1";
12
+ var packageVersion = "28.5.2";
13
13
 
14
14
  // @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
15
15
  export var CustomMediaPlayer = withMediaAnalyticsContext({
@@ -1,17 +1,20 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["onPlay"];
2
4
  import React from 'react';
3
5
  import { withMediaAnalyticsContext } from '@atlaskit/media-common';
4
- import { useFileState, useMediaClient, useMediaSettings } from '@atlaskit/media-client-react';
6
+ import { useFileState, useMediaSettings } from '@atlaskit/media-client-react';
5
7
  import { MediaPlayerBase } from './mediaPlayerBase';
6
8
  import { useTextTracks } from './useTextTracks';
7
9
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
8
10
  var packageName = "@atlaskit/media-ui";
9
- var packageVersion = "28.5.1";
10
- export var MediaPlayerWihtoutContext = function MediaPlayerWihtoutContext(props) {
11
+ var packageVersion = "28.5.2";
12
+ export var MediaPlayerWihtoutContext = function MediaPlayerWihtoutContext(_ref) {
13
+ var _onPlay = _ref.onPlay,
14
+ props = _objectWithoutProperties(_ref, _excluded);
11
15
  var _useAnalyticsEvents = useAnalyticsEvents(),
12
16
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
13
17
  var mediaSettings = useMediaSettings();
14
- var mediaClient = useMediaClient();
15
18
  var _props$identifier = props.identifier,
16
19
  id = _props$identifier.id,
17
20
  collectionName = _props$identifier.collectionName;
@@ -19,12 +22,24 @@ export var MediaPlayerWihtoutContext = function MediaPlayerWihtoutContext(props)
19
22
  collectionName: collectionName
20
23
  }),
21
24
  fileState = _useFileState.fileState;
22
- var textTracks = useTextTracks(fileState, mediaClient, collectionName);
25
+ var _useTextTracks = useTextTracks(fileState, collectionName),
26
+ textTracks = _useTextTracks.textTracks,
27
+ verifyUserCaptionsEnabled = _useTextTracks.verifyUserCaptionsEnabled,
28
+ setSelectedTracksIndex = _useTextTracks.setSelectedTracksIndex,
29
+ setAreCaptionsEnabled = _useTextTracks.setAreCaptionsEnabled,
30
+ areCaptionsEnabled = _useTextTracks.areCaptionsEnabled;
23
31
  return /*#__PURE__*/React.createElement(MediaPlayerBase, _extends({}, props, {
24
32
  fileState: fileState,
25
33
  mediaSettings: mediaSettings,
26
34
  textTracks: textTracks,
27
- createAnalyticsEvent: createAnalyticsEvent
35
+ createAnalyticsEvent: createAnalyticsEvent,
36
+ areCaptionsEnabled: areCaptionsEnabled,
37
+ onPlay: function onPlay() {
38
+ verifyUserCaptionsEnabled();
39
+ _onPlay === null || _onPlay === void 0 || _onPlay();
40
+ },
41
+ onTextTracksSelected: setSelectedTracksIndex,
42
+ onCaptionsEnabledChange: setAreCaptionsEnabled
28
43
  }));
29
44
  };
30
45
  export var MediaPlayer = withMediaAnalyticsContext({
@@ -50,7 +50,6 @@ import { SkipTenBackwardIcon, SkipTenForwardIcon } from '@atlaskit/legacy-custom
50
50
  import { fg } from '@atlaskit/platform-feature-flags';
51
51
  import VideoSkipForwardTenIcon from '@atlaskit/icon/core/video-skip-forward-ten';
52
52
  import VideoSkipBackwardTenIcon from '@atlaskit/icon/core/video-skip-backward-ten';
53
- import { getUserCaptionsLocale, setUserCaptionsLocale, findPreselectedTrackIndex, getUserCaptionsEnabled, setUserCaptionsEnabled } from './captions';
54
53
  import { CaptionsUploaderBrowser } from './captions/artifactUploader';
55
54
  import CaptionDeleteConfirmationModal from './captions/captionDeleteConfirmationModal';
56
55
  var MINIMUM_DURATION_BEFORE_SAVING_TIME = 60;
@@ -125,10 +124,13 @@ var spinnerWrapperStyles = {
125
124
  root: "_kqswstnw _154ize3t _1ltvze3t _1bsb1osq _4t3i1osq"
126
125
  };
127
126
  var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
128
- function _MediaPlayerBase(props) {
127
+ function _MediaPlayerBase() {
129
128
  var _this;
130
129
  _classCallCheck(this, _MediaPlayerBase);
131
- _this = _callSuper(this, _MediaPlayerBase, [props]);
130
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
131
+ args[_key] = arguments[_key];
132
+ }
133
+ _this = _callSuper(this, _MediaPlayerBase, [].concat(args));
132
134
  _defineProperty(_this, "videoWrapperRef", /*#__PURE__*/React.createRef());
133
135
  _defineProperty(_this, "videoState", {
134
136
  isLoading: true,
@@ -150,25 +152,9 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
150
152
  playerWidth: 100,
151
153
  // initial value for playerSize: 'small', i.e. width < 260px
152
154
  playbackSpeed: 1,
153
- selectedTracksIndex: -1,
154
- areCaptionsEnabled: false,
155
155
  isArtifactUploaderOpen: false,
156
156
  artifactToDelete: undefined
157
157
  });
158
- _defineProperty(_this, "findPreselectedTrackIndex", function (_ref) {
159
- var _textTracks$captions;
160
- var textTracks = _ref.textTracks,
161
- intl = _ref.intl;
162
- return findPreselectedTrackIndex((textTracks === null || textTracks === void 0 || (_textTracks$captions = textTracks.captions) === null || _textTracks$captions === void 0 ? void 0 : _textTracks$captions.tracks) || [], intl.locale, _this.getUserCaptionsPreference());
163
- });
164
- _defineProperty(_this, "getUserCaptionsPreference", function () {
165
- return _this.mediaUserPreferences && getUserCaptionsLocale(_this.mediaUserPreferences);
166
- });
167
- _defineProperty(_this, "setUserCaptionsPreference", function (selectedTracks) {
168
- if (_this.mediaUserPreferences) {
169
- setUserCaptionsLocale(_this.mediaUserPreferences, selectedTracks.lang);
170
- }
171
- });
172
158
  _defineProperty(_this, "fireFirstPlayedTrackEvent", function () {
173
159
  var _this$props = _this.props,
174
160
  type = _this$props.type,
@@ -367,11 +353,11 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
367
353
  })
368
354
  });
369
355
  });
370
- _defineProperty(_this, "renderShortcuts", function (_ref2) {
371
- var togglePlayPauseAction = _ref2.togglePlayPauseAction,
372
- toggleMute = _ref2.toggleMute,
373
- skipBackward = _ref2.skipBackward,
374
- skipForward = _ref2.skipForward;
356
+ _defineProperty(_this, "renderShortcuts", function (_ref) {
357
+ var togglePlayPauseAction = _ref.togglePlayPauseAction,
358
+ toggleMute = _ref.toggleMute,
359
+ skipBackward = _ref.skipBackward,
360
+ skipForward = _ref.skipForward;
375
361
  var isShortcutEnabled = _this.props.isShortcutEnabled;
376
362
  var isFullScreenEnabled = _this.state.isFullScreenEnabled;
377
363
  var shortcuts = (isShortcutEnabled || isFullScreenEnabled) && [/*#__PURE__*/React.createElement(Shortcut, {
@@ -495,7 +481,9 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
495
481
  (_this$props$onPause = (_this$props9 = _this.props).onPause) === null || _this$props$onPause === void 0 || _this$props$onPause.call(_this$props9);
496
482
  });
497
483
  _defineProperty(_this, "play", function () {
498
- var onFirstPlay = _this.props.onFirstPlay;
484
+ var _this$props0 = _this.props,
485
+ onFirstPlay = _this$props0.onFirstPlay,
486
+ onPlay = _this$props0.onPlay;
499
487
  if (_this.actions) {
500
488
  _this.actions.play();
501
489
  }
@@ -505,12 +493,7 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
505
493
  _this.wasPlayedOnce = true;
506
494
  onFirstPlay();
507
495
  }
508
- if (_this.mediaUserPreferences) {
509
- var userCaptionsEnabled = getUserCaptionsEnabled(_this.mediaUserPreferences);
510
- _this.setState({
511
- areCaptionsEnabled: userCaptionsEnabled
512
- });
513
- }
496
+ onPlay === null || onPlay === void 0 || onPlay();
514
497
  });
515
498
  _defineProperty(_this, "getMediaButtonClickHandler", function (action, buttonType) {
516
499
  return function () {
@@ -529,13 +512,13 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
529
512
  };
530
513
  });
531
514
  _defineProperty(_this, "onViewed", function (videoState) {
532
- var _this$props0 = _this.props,
533
- createAnalyticsEvent = _this$props0.createAnalyticsEvent,
534
- identifier = _this$props0.identifier,
535
- isAutoPlay = _this$props0.isAutoPlay,
536
- isHDAvailable = _this$props0.isHDAvailable,
537
- isHDActive = _this$props0.isHDActive,
538
- type = _this$props0.type;
515
+ var _this$props1 = _this.props,
516
+ createAnalyticsEvent = _this$props1.createAnalyticsEvent,
517
+ identifier = _this$props1.identifier,
518
+ isAutoPlay = _this$props1.isAutoPlay,
519
+ isHDAvailable = _this$props1.isHDAvailable,
520
+ isHDActive = _this$props1.isHDActive,
521
+ type = _this$props1.type;
539
522
  var _this$state2 = _this.state,
540
523
  isFullScreenEnabled = _this$state2.isFullScreenEnabled,
541
524
  playbackSpeed = _this$state2.playbackSpeed;
@@ -581,17 +564,12 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
581
564
  _defineProperty(_this, "startPlayByButtonClick", _this.getMediaButtonClickHandler(_this.play, 'playButton'));
582
565
  _defineProperty(_this, "pausePlayByButtonClick", _this.getMediaButtonClickHandler(_this.pause, 'pauseButton'));
583
566
  _defineProperty(_this, "onTextTracksSelected", function (selectedTracksIndex) {
584
- var _this$props$textTrack;
585
- var selectedTracks = (_this$props$textTrack = _this.props.textTracks) === null || _this$props$textTrack === void 0 || (_this$props$textTrack = _this$props$textTrack.captions) === null || _this$props$textTrack === void 0 ? void 0 : _this$props$textTrack.tracks[selectedTracksIndex];
586
- !!selectedTracks && _this.setUserCaptionsPreference(selectedTracks);
587
- _this.setState({
588
- selectedTracksIndex: selectedTracksIndex
589
- });
567
+ var _this$props$onTextTra, _this$props10;
568
+ (_this$props$onTextTra = (_this$props10 = _this.props).onTextTracksSelected) === null || _this$props$onTextTra === void 0 || _this$props$onTextTra.call(_this$props10, selectedTracksIndex);
590
569
  });
591
570
  _defineProperty(_this, "onCaptionsEnabledChange", function (areCaptionsEnabled) {
592
- _this.setState({
593
- areCaptionsEnabled: areCaptionsEnabled
594
- });
571
+ var _this$props$onCaption, _this$props11;
572
+ (_this$props$onCaption = (_this$props11 = _this.props).onCaptionsEnabledChange) === null || _this$props$onCaption === void 0 || _this$props$onCaption.call(_this$props11, areCaptionsEnabled);
595
573
  });
596
574
  _defineProperty(_this, "onCaptionDelete", function (artifactName) {
597
575
  // Modal is not supported in fullscreen mode (as it uses portals which are not in the same DOM tree),
@@ -603,37 +581,24 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
603
581
  artifactToDelete: artifactName
604
582
  });
605
583
  });
606
- _defineProperty(_this, "resolveSelectedTracksIndex", function () {
607
- var _this$state3 = _this.state,
608
- areCaptionsEnabled = _this$state3.areCaptionsEnabled,
609
- selectedTracksIndex = _this$state3.selectedTracksIndex;
610
- return areCaptionsEnabled ? selectedTracksIndex > -1 ? selectedTracksIndex : 0 : -1;
611
- });
612
- _defineProperty(_this, "resolveTextTracks", function () {
613
- var areCaptionsEnabled = _this.state.areCaptionsEnabled;
614
- var textTracks = _this.props.textTracks;
615
- var tracksKey = 'captions';
616
- if (areCaptionsEnabled && textTracks !== null && textTracks !== void 0 && textTracks[tracksKey]) {
617
- return _objectSpread(_objectSpread({}, textTracks), {}, _defineProperty({}, tracksKey, _objectSpread(_objectSpread({}, textTracks[tracksKey]), {}, {
618
- selectedTrackIndex: _this.resolveSelectedTracksIndex()
619
- })));
620
- }
621
- return undefined;
622
- });
623
584
  _defineProperty(_this, "shouldRenderCaptionsControls", function () {
585
+ var _textTracks$captions;
624
586
  var textTracks = _this.props.textTracks;
625
587
  var playerWidth = _this.state.playerWidth;
626
- return breakpointControls.captionsControls(playerWidth) && !!textTracks;
588
+ return breakpointControls.captionsControls(playerWidth) && !!textTracks && !!((_textTracks$captions = textTracks.captions) !== null && _textTracks$captions !== void 0 && (_textTracks$captions = _textTracks$captions.tracks) !== null && _textTracks$captions !== void 0 && _textTracks$captions.length);
627
589
  });
628
590
  _defineProperty(_this, "renderCaptionsControls", function () {
629
591
  var textTracks = _this.props.textTracks;
630
- var areCaptionsEnabled = _this.state.areCaptionsEnabled;
592
+ var _ref2 = (textTracks === null || textTracks === void 0 ? void 0 : textTracks.captions) || {},
593
+ _ref2$selectedTrackIn = _ref2.selectedTrackIndex,
594
+ selectedTrackIndex = _ref2$selectedTrackIn === void 0 ? -1 : _ref2$selectedTrackIn;
595
+ var areCaptionsEnabled = _this.props.areCaptionsEnabled;
631
596
  return textTracks && /*#__PURE__*/React.createElement(CaptionsSelectControls, {
632
597
  textTracks: textTracks,
633
598
  onSelected: _this.onTextTracksSelected,
634
599
  areCaptionsEnabled: !!areCaptionsEnabled,
635
600
  onCaptionsEnabledChange: _this.onCaptionsEnabledChange,
636
- selectedTracksIndex: _this.resolveSelectedTracksIndex()
601
+ selectedTracksIndex: selectedTrackIndex
637
602
  });
638
603
  });
639
604
  _defineProperty(_this, "shouldRenderCaptionsAdminControls", function () {
@@ -642,12 +607,12 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
642
607
  return (!_this.props.fileState || _this.props.fileState.status !== 'uploading') && breakpointControls.captionsAdminControls(playerWidth) && !!((_this$props$mediaSett = _this.props.mediaSettings) !== null && _this$props$mediaSett !== void 0 && _this$props$mediaSett.canUpdateVideoCaptions);
643
608
  });
644
609
  _defineProperty(_this, "renderCaptionsAdminControls", function () {
645
- var _this$state4 = _this.state,
646
- isArtifactUploaderOpen = _this$state4.isArtifactUploaderOpen,
647
- artifactToDelete = _this$state4.artifactToDelete;
648
- var _this$props1 = _this.props,
649
- textTracks = _this$props1.textTracks,
650
- identifier = _this$props1.identifier;
610
+ var _this$state3 = _this.state,
611
+ isArtifactUploaderOpen = _this$state3.isArtifactUploaderOpen,
612
+ artifactToDelete = _this$state3.artifactToDelete;
613
+ var _this$props12 = _this.props,
614
+ textTracks = _this$props12.textTracks,
615
+ identifier = _this$props12.identifier;
651
616
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CaptionsAdminControls, {
652
617
  textTracks: textTracks,
653
618
  onUpload: function onUpload() {
@@ -692,57 +657,23 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
692
657
  }
693
658
  }));
694
659
  });
695
- _this.state.selectedTracksIndex = _this.findPreselectedTrackIndex(_this.props);
696
- if (_this.mediaUserPreferences) {
697
- var userCaptionsEnabled = getUserCaptionsEnabled(_this.mediaUserPreferences);
698
- _this.state.areCaptionsEnabled = userCaptionsEnabled;
699
- }
700
660
  return _this;
701
661
  }
702
662
  _inherits(_MediaPlayerBase, _Component);
703
663
  return _createClass(_MediaPlayerBase, [{
704
- key: "componentDidUpdate",
705
- value: function componentDidUpdate(prevProps, prevState) {
706
- var _prevTextTracks$capti, _textTracks$captions2;
707
- var _this$props10 = this.props,
708
- intl = _this$props10.intl,
709
- textTracks = _this$props10.textTracks;
710
- var prevIntl = prevProps.intl,
711
- prevTextTracks = prevProps.textTracks;
712
- var didLocaleChange = prevIntl.locale !== intl.locale;
713
- var didTextTracksChange = (prevTextTracks === null || prevTextTracks === void 0 || (_prevTextTracks$capti = prevTextTracks.captions) === null || _prevTextTracks$capti === void 0 ? void 0 : _prevTextTracks$capti.tracks) !== (textTracks === null || textTracks === void 0 || (_textTracks$captions2 = textTracks.captions) === null || _textTracks$captions2 === void 0 ? void 0 : _textTracks$captions2.tracks);
714
- if (didLocaleChange || didTextTracksChange) {
715
- this.setState({
716
- selectedTracksIndex: this.findPreselectedTrackIndex(this.props)
717
- });
718
- }
719
- if (this.mediaUserPreferences && prevState.areCaptionsEnabled !== this.state.areCaptionsEnabled) {
720
- setUserCaptionsEnabled(this.mediaUserPreferences, !!this.state.areCaptionsEnabled);
721
- }
722
- }
723
- }, {
724
- key: "mediaUserPreferences",
725
- get: function get() {
726
- var _this$props$mediaSett2 = this.props.mediaSettings,
727
- _this$props$mediaSett3 = _this$props$mediaSett2 === void 0 ? {} : _this$props$mediaSett2,
728
- _this$props$mediaSett4 = _this$props$mediaSett3.mediaUserPreferences,
729
- mediaUserPreferences = _this$props$mediaSett4 === void 0 ? undefined : _this$props$mediaSett4;
730
- return mediaUserPreferences;
731
- }
732
- }, {
733
664
  key: "componentDidMount",
734
665
  value: function componentDidMount() {
735
- var _this$props11 = this.props,
736
- type = _this$props11.type,
737
- identifier = _this$props11.identifier,
738
- isAutoPlay = _this$props11.isAutoPlay,
739
- isHDAvailable = _this$props11.isHDAvailable,
740
- isHDActive = _this$props11.isHDActive,
741
- onFirstPlay = _this$props11.onFirstPlay,
742
- createAnalyticsEvent = _this$props11.createAnalyticsEvent;
743
- var _this$state5 = this.state,
744
- isFullScreenEnabled = _this$state5.isFullScreenEnabled,
745
- playbackSpeed = _this$state5.playbackSpeed;
666
+ var _this$props13 = this.props,
667
+ type = _this$props13.type,
668
+ identifier = _this$props13.identifier,
669
+ isAutoPlay = _this$props13.isAutoPlay,
670
+ isHDAvailable = _this$props13.isHDAvailable,
671
+ isHDActive = _this$props13.isHDActive,
672
+ onFirstPlay = _this$props13.onFirstPlay,
673
+ createAnalyticsEvent = _this$props13.createAnalyticsEvent;
674
+ var _this$state4 = this.state,
675
+ isFullScreenEnabled = _this$state4.isFullScreenEnabled,
676
+ playbackSpeed = _this$state4.playbackSpeed;
746
677
  var playerSize = this.playerSize;
747
678
  fireAnalyticsEvent(createCustomMediaPlayerScreenEvent(type, {
748
679
  isAutoPlay: isAutoPlay,
@@ -758,14 +689,14 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
758
689
  }
759
690
  simultaneousPlayManager.subscribe(this);
760
691
  if (isAutoPlay) {
761
- var _this$props$onPlay, _this$props12;
692
+ var _this$props$onPlay, _this$props14;
762
693
  simultaneousPlayManager.pauseOthers(this);
763
694
  if (onFirstPlay) {
764
695
  this.fireFirstPlayedTrackEvent();
765
696
  this.wasPlayedOnce = true;
766
697
  onFirstPlay();
767
698
  }
768
- (_this$props$onPlay = (_this$props12 = this.props).onPlay) === null || _this$props$onPlay === void 0 || _this$props$onPlay.call(_this$props12);
699
+ (_this$props$onPlay = (_this$props14 = this.props).onPlay) === null || _this$props$onPlay === void 0 || _this$props$onPlay.call(_this$props14);
769
700
  }
770
701
  }
771
702
  }, {
@@ -775,8 +706,8 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
775
706
  this.videoWrapperRef.current.removeEventListener('fullscreenchange', this.onFullScreenChange);
776
707
  }
777
708
  if (this.state.isFullScreenEnabled) {
778
- var _this$props$onFullscr2, _this$props13;
779
- (_this$props$onFullscr2 = (_this$props13 = this.props).onFullscreenChange) === null || _this$props$onFullscr2 === void 0 || _this$props$onFullscr2.call(_this$props13, false);
709
+ var _this$props$onFullscr2, _this$props15;
710
+ (_this$props$onFullscr2 = (_this$props15 = this.props).onFullscreenChange) === null || _this$props$onFullscr2 === void 0 || _this$props$onFullscr2.call(_this$props15, false);
780
711
  }
781
712
  simultaneousPlayManager.unsubscribe(this);
782
713
  }
@@ -797,16 +728,16 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
797
728
  }, {
798
729
  key: "createAndFireUIEvent",
799
730
  value: function createAndFireUIEvent(eventType, actionSubjectId) {
800
- var _this$props14 = this.props,
801
- type = _this$props14.type,
802
- identifier = _this$props14.identifier,
803
- isHDActive = _this$props14.isHDActive,
804
- isHDAvailable = _this$props14.isHDAvailable,
805
- isAutoPlay = _this$props14.isAutoPlay,
806
- createAnalyticsEvent = _this$props14.createAnalyticsEvent;
807
- var _this$state6 = this.state,
808
- isFullScreenEnabled = _this$state6.isFullScreenEnabled,
809
- playbackSpeed = _this$state6.playbackSpeed;
731
+ var _this$props16 = this.props,
732
+ type = _this$props16.type,
733
+ identifier = _this$props16.identifier,
734
+ isHDActive = _this$props16.isHDActive,
735
+ isHDAvailable = _this$props16.isHDAvailable,
736
+ isAutoPlay = _this$props16.isAutoPlay,
737
+ createAnalyticsEvent = _this$props16.createAnalyticsEvent;
738
+ var _this$state5 = this.state,
739
+ isFullScreenEnabled = _this$state5.isFullScreenEnabled,
740
+ playbackSpeed = _this$state5.playbackSpeed;
810
741
  var playerSize = this.playerSize;
811
742
  var playbackState = _objectSpread(_objectSpread({}, this.videoState), {}, {
812
743
  isAutoPlay: isAutoPlay,
@@ -849,13 +780,15 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
849
780
  }, {
850
781
  key: "baseAnalyticCaptionAttributes",
851
782
  value: function baseAnalyticCaptionAttributes() {
852
- var _textTracks$captions3, _textTracks$captions4;
783
+ var _textTracks$captions2, _textTracks$captions3;
853
784
  var textTracks = this.props.textTracks;
854
- var selectedTracksIndex = this.state.selectedTracksIndex;
785
+ var _ref3 = (textTracks === null || textTracks === void 0 ? void 0 : textTracks.captions) || {},
786
+ _ref3$selectedTrackIn = _ref3.selectedTrackIndex,
787
+ selectedTrackIndex = _ref3$selectedTrackIn === void 0 ? -1 : _ref3$selectedTrackIn;
855
788
  var captionAttributes = {
856
- selectedTrackIndex: selectedTracksIndex,
857
- availableCaptionTracks: (textTracks === null || textTracks === void 0 || (_textTracks$captions3 = textTracks.captions) === null || _textTracks$captions3 === void 0 || (_textTracks$captions3 = _textTracks$captions3.tracks) === null || _textTracks$captions3 === void 0 ? void 0 : _textTracks$captions3.length) || 0,
858
- selectedTrackLanguage: (textTracks === null || textTracks === void 0 || (_textTracks$captions4 = textTracks.captions) === null || _textTracks$captions4 === void 0 || (_textTracks$captions4 = _textTracks$captions4.tracks) === null || _textTracks$captions4 === void 0 || (_textTracks$captions4 = _textTracks$captions4[selectedTracksIndex]) === null || _textTracks$captions4 === void 0 ? void 0 : _textTracks$captions4.lang) || null
789
+ selectedTrackIndex: selectedTrackIndex,
790
+ availableCaptionTracks: (textTracks === null || textTracks === void 0 || (_textTracks$captions2 = textTracks.captions) === null || _textTracks$captions2 === void 0 || (_textTracks$captions2 = _textTracks$captions2.tracks) === null || _textTracks$captions2 === void 0 ? void 0 : _textTracks$captions2.length) || 0,
791
+ selectedTrackLanguage: (textTracks === null || textTracks === void 0 || (_textTracks$captions3 = textTracks.captions) === null || _textTracks$captions3 === void 0 || (_textTracks$captions3 = _textTracks$captions3.tracks) === null || _textTracks$captions3 === void 0 || (_textTracks$captions3 = _textTracks$captions3[selectedTrackIndex]) === null || _textTracks$captions3 === void 0 ? void 0 : _textTracks$captions3.lang) || null
859
792
  };
860
793
  return captionAttributes;
861
794
  }
@@ -897,15 +830,16 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
897
830
  key: "render",
898
831
  value: function render() {
899
832
  var _this4 = this;
900
- var _this$props15 = this.props,
901
- type = _this$props15.type,
902
- src = _this$props15.src,
903
- isAutoPlay = _this$props15.isAutoPlay,
904
- onCanPlay = _this$props15.onCanPlay,
905
- onError = _this$props15.onError,
906
- poster = _this$props15.poster,
907
- videoControlsWrapperRef = _this$props15.videoControlsWrapperRef,
908
- areControlsVisible = _this$props15.areControlsVisible;
833
+ var _this$props17 = this.props,
834
+ type = _this$props17.type,
835
+ src = _this$props17.src,
836
+ isAutoPlay = _this$props17.isAutoPlay,
837
+ onCanPlay = _this$props17.onCanPlay,
838
+ onError = _this$props17.onError,
839
+ poster = _this$props17.poster,
840
+ videoControlsWrapperRef = _this$props17.videoControlsWrapperRef,
841
+ areControlsVisible = _this$props17.areControlsVisible,
842
+ textTracks = _this$props17.textTracks;
909
843
  return /*#__PURE__*/React.createElement(Box, {
910
844
  xcss: customVideoWrapperStyles.root,
911
845
  ref: this.videoWrapperRef,
@@ -919,7 +853,7 @@ var _MediaPlayerBase = /*#__PURE__*/function (_Component) {
919
853
  onTimeChange: this.onCurrentTimeChange,
920
854
  onError: onError,
921
855
  poster: poster,
922
- textTracks: this.resolveTextTracks(),
856
+ textTracks: textTracks,
923
857
  textTracksPosition: areControlsVisible ? -3.7 : undefined
924
858
  }, function (video, videoState, actions) {
925
859
  _this4.onViewed(videoState);
@@ -0,0 +1 @@
1
+ export {};