@atlaskit/media-ui 28.5.2 → 28.5.4

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 (32) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/customMediaPlayer/index.js +1 -1
  3. package/dist/cjs/customMediaPlayer/mediaPlayer/captions/captionDeleteConfirmationModal.js +1 -3
  4. package/dist/cjs/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  5. package/dist/cjs/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +81 -147
  6. package/dist/cjs/customMediaPlayer/mediaPlayer/types.js +5 -0
  7. package/dist/cjs/customMediaPlayer/mediaPlayer/useTextTracks.js +139 -66
  8. package/dist/es2019/customMediaPlayer/index.js +1 -1
  9. package/dist/es2019/customMediaPlayer/mediaPlayer/captions/captionDeleteConfirmationModal.js +1 -3
  10. package/dist/es2019/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  11. package/dist/es2019/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +29 -111
  12. package/dist/es2019/customMediaPlayer/mediaPlayer/types.js +1 -0
  13. package/dist/es2019/customMediaPlayer/mediaPlayer/useTextTracks.js +129 -43
  14. package/dist/esm/customMediaPlayer/index.js +1 -1
  15. package/dist/esm/customMediaPlayer/mediaPlayer/captions/captionDeleteConfirmationModal.js +1 -3
  16. package/dist/esm/customMediaPlayer/mediaPlayer/mediaPlayer.js +21 -6
  17. package/dist/esm/customMediaPlayer/mediaPlayer/mediaPlayerBase.js +81 -147
  18. package/dist/esm/customMediaPlayer/mediaPlayer/types.js +1 -0
  19. package/dist/esm/customMediaPlayer/mediaPlayer/useTextTracks.js +140 -67
  20. package/dist/types/customMediaPlayer/mediaPlayer/index.d.ts +2 -1
  21. package/dist/types/customMediaPlayer/mediaPlayer/mediaPlayer.d.ts +2 -3
  22. package/dist/types/customMediaPlayer/mediaPlayer/mediaPlayerBase.d.ts +1 -34
  23. package/dist/types/customMediaPlayer/mediaPlayer/types.d.ts +38 -0
  24. package/dist/types/customMediaPlayer/mediaPlayer/useTextTracks.d.ts +8 -2
  25. package/dist/types/customMediaPlayer/react-video-renderer/text.d.ts +3 -2
  26. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/index.d.ts +2 -1
  27. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/mediaPlayer.d.ts +2 -3
  28. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/mediaPlayerBase.d.ts +1 -34
  29. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/types.d.ts +38 -0
  30. package/dist/types-ts4.5/customMediaPlayer/mediaPlayer/useTextTracks.d.ts +8 -2
  31. package/dist/types-ts4.5/customMediaPlayer/react-video-renderer/text.d.ts +3 -2
  32. package/package.json +4 -5
@@ -5,93 +5,166 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.useTextTracks = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _mediaClient = require("@atlaskit/media-client");
12
12
  var _react = require("react");
13
+ var _mediaClientReact = require("@atlaskit/media-client-react");
14
+ var _captions = require("./captions");
15
+ var _reactIntlNext = require("react-intl-next");
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
18
  var decodeMimetype = function decodeMimetype(mimeType) {
14
19
  var keyValues = (mimeType === null || mimeType === void 0 ? void 0 : mimeType.split(';')) || [];
15
20
  var captionsRawMetadata = Object.fromEntries(keyValues.map(function (keyValue) {
16
21
  return keyValue.split('=');
17
22
  }));
23
+ var fileName = captionsRawMetadata.n ? atob(captionsRawMetadata.n) : 'no-name';
24
+ var lang = captionsRawMetadata.l || 'en';
18
25
  return {
19
- lang: captionsRawMetadata.l || 'en',
20
- fileName: captionsRawMetadata.f || 'no-name.vtt',
21
- label: captionsRawMetadata.label || 'no-name'
26
+ lang: lang,
27
+ fileName: fileName,
28
+ label: lang
22
29
  };
23
30
  };
24
- var useTextTracks = exports.useTextTracks = function useTextTracks(fileState, mediaClient, collectionName) {
25
- var _useState = (0, _react.useState)(),
31
+ var NO_SELECTED_TRACKS_INDEX = -1;
32
+ var useTextTracks = exports.useTextTracks = function useTextTracks(fileState, collectionName) {
33
+ var mediaClient = (0, _mediaClientReact.useMediaClient)();
34
+ var isLoadingCaptionsObjectURLs = (0, _react.useRef)(new Map());
35
+ var captionsObjectURLs = (0, _react.useRef)(new Map());
36
+ var intl = (0, _reactIntlNext.useIntl)();
37
+ var _ref = (0, _mediaClientReact.useMediaSettings)() || {},
38
+ mediaUserPreferences = _ref.mediaUserPreferences;
39
+ var _useState = (0, _react.useState)([]),
26
40
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
27
- textTracks = _useState2[0],
28
- setTextTracks = _useState2[1];
41
+ captionTracks = _useState2[0],
42
+ setCaptionTracks = _useState2[1];
43
+ var _useState3 = (0, _react.useState)(mediaUserPreferences ? (0, _captions.getUserCaptionsEnabled)(mediaUserPreferences) : false),
44
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
45
+ areCaptionsEnabled = _useState4[0],
46
+ setAreCaptionsEnabled = _useState4[1];
47
+ var _useState5 = (0, _react.useState)(NO_SELECTED_TRACKS_INDEX),
48
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
49
+ selectedTracksIndex = _useState6[0],
50
+ setSelectedTracksIndex = _useState6[1];
51
+ var resolvedSelectedTracksIndex = (0, _react.useMemo)(function () {
52
+ return areCaptionsEnabled ? selectedTracksIndex : NO_SELECTED_TRACKS_INDEX;
53
+ }, [areCaptionsEnabled, selectedTracksIndex]);
54
+
55
+ // When video starts playing, user settings might have changed
56
+ var verifyUserCaptionsEnabled = (0, _react.useCallback)(function () {
57
+ if (mediaUserPreferences) {
58
+ setAreCaptionsEnabled((0, _captions.getUserCaptionsEnabled)(mediaUserPreferences));
59
+ }
60
+ }, [mediaUserPreferences]);
61
+
62
+ // Converts file artifacts to base text tracks, i.e. text tracks with a source creator function.
63
+ // The src is resolved on every selected track change.
29
64
  (0, _react.useEffect)(function () {
30
65
  if (!fileState || !(0, _mediaClient.hasArtifacts)(fileState)) {
66
+ setCaptionTracks([]);
31
67
  return;
32
68
  }
33
- var captions = Object.entries(fileState.artifacts || {}).filter(function (caption) {
69
+ var captionsArtifacts = Object.entries(fileState.artifacts || {}).filter(function (caption) {
34
70
  var _caption = (0, _slicedToArray2.default)(caption, 2),
35
71
  key = _caption[0],
36
72
  value = _caption[1];
37
73
  return key.includes('ugc_caption') && !!value;
38
74
  });
39
- if (captions.length > 0) {
40
- Promise.all(captions.map( /*#__PURE__*/function () {
41
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
42
- var _ref3, artifactName, mimeType, artifacts, baseUrl, src, _decodeMimetype, lang, label;
43
- return _regenerator.default.wrap(function _callee$(_context) {
44
- while (1) switch (_context.prev = _context.next) {
45
- case 0:
46
- _ref3 = (0, _slicedToArray2.default)(_ref, 2), artifactName = _ref3[0], mimeType = _ref3[1].mimeType;
47
- _context.prev = 1;
48
- artifacts = fileState.artifacts;
49
- _context.t0 = artifacts;
50
- if (!_context.t0) {
51
- _context.next = 8;
52
- break;
53
- }
54
- _context.next = 7;
55
- return mediaClient === null || mediaClient === void 0 ? void 0 : mediaClient.mediaStore.getArtifactBinary(artifacts, artifactName, {
56
- collectionName: collectionName
57
- });
58
- case 7:
59
- _context.t0 = _context.sent;
60
- case 8:
61
- baseUrl = _context.t0;
62
- src = baseUrl && URL.createObjectURL(baseUrl) || '';
63
- _decodeMimetype = decodeMimetype(mimeType), lang = _decodeMimetype.lang, label = _decodeMimetype.label;
64
- return _context.abrupt("return", {
65
- src: src,
66
- lang: lang,
67
- label: label,
68
- artifactName: artifactName
69
- });
70
- case 14:
71
- _context.prev = 14;
72
- _context.t1 = _context["catch"](1);
73
- case 16:
74
- case "end":
75
- return _context.stop();
76
- }
77
- }, _callee, null, [[1, 14]]);
78
- }));
79
- return function (_x) {
80
- return _ref2.apply(this, arguments);
81
- };
82
- }())).then(function (tracks) {
83
- setTextTracks({
84
- captions: {
85
- selectedTrackIndex: 1,
86
- tracks: tracks.filter(function (track) {
87
- return !!(track !== null && track !== void 0 && track.src);
88
- })
89
- }
75
+ setCaptionTracks(captionsArtifacts.map(function (_ref2) {
76
+ var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
77
+ artifactName = _ref3[0],
78
+ mimeType = _ref3[1].mimeType;
79
+ var _decodeMimetype = decodeMimetype(mimeType),
80
+ lang = _decodeMimetype.lang,
81
+ label = _decodeMimetype.label;
82
+ var src = captionsObjectURLs.current.get(artifactName);
83
+ return {
84
+ lang: lang,
85
+ label: label,
86
+ artifactName: artifactName,
87
+ src: src
88
+ };
89
+ })
90
+ // Sort based on current locale
91
+ .sort(function (a, b) {
92
+ return a.lang.localeCompare(b.lang, intl.locale);
93
+ }));
94
+ }, [fileState, intl.locale]);
95
+
96
+ // Update the user caption enabled preferences
97
+ (0, _react.useEffect)(function () {
98
+ if (mediaUserPreferences) {
99
+ (0, _captions.setUserCaptionsEnabled)(mediaUserPreferences, areCaptionsEnabled);
100
+ }
101
+ }, [mediaUserPreferences, areCaptionsEnabled]);
102
+
103
+ // Update the user locale preferences
104
+ (0, _react.useEffect)(function () {
105
+ var _ref4 = captionTracks[resolvedSelectedTracksIndex] || {},
106
+ lang = _ref4.lang;
107
+ if (mediaUserPreferences && lang) {
108
+ (0, _captions.setUserCaptionsLocale)(mediaUserPreferences, lang);
109
+ }
110
+ }, [mediaUserPreferences, captionTracks, resolvedSelectedTracksIndex]);
111
+
112
+ // Reset the selected track index when the locale or text tracks change
113
+ (0, _react.useEffect)(function () {
114
+ var preselectedTrackIndex = (0, _captions.findPreselectedTrackIndex)(captionTracks, intl.locale, mediaUserPreferences && (0, _captions.getUserCaptionsLocale)(mediaUserPreferences));
115
+ setSelectedTracksIndex(preselectedTrackIndex || 0);
116
+ }, [mediaUserPreferences, intl.locale, captionTracks]);
117
+ (0, _react.useEffect)(function () {
118
+ if (fileState && (0, _mediaClient.hasArtifacts)(fileState)) {
119
+ var _ref5 = captionTracks[resolvedSelectedTracksIndex] || {},
120
+ artifactName = _ref5.artifactName,
121
+ src = _ref5.src;
122
+ if (artifactName && !src && !isLoadingCaptionsObjectURLs.current.get(artifactName)) {
123
+ isLoadingCaptionsObjectURLs.current.set(artifactName, true);
124
+ mediaClient.mediaStore.getArtifactBinary(fileState.artifacts, artifactName, {
125
+ collectionName: collectionName
126
+ }).then(function (blob) {
127
+ var objectUrl = URL.createObjectURL(blob);
128
+ captionsObjectURLs.current.set(artifactName, objectUrl);
129
+ setCaptionTracks(function (prevCaptionTracks) {
130
+ var newCaptionTracks = (0, _toConsumableArray2.default)(prevCaptionTracks);
131
+ newCaptionTracks[resolvedSelectedTracksIndex] = _objectSpread(_objectSpread({}, newCaptionTracks[resolvedSelectedTracksIndex]), {}, {
132
+ src: objectUrl
133
+ });
134
+ return newCaptionTracks;
135
+ });
136
+ }).catch(function (error) {
137
+ // TODO: Handle this error
138
+ // https://product-fabric.atlassian.net/browse/BMPT-6929
139
+ }).finally(function () {
140
+ isLoadingCaptionsObjectURLs.current.set(artifactName, false);
90
141
  });
91
- });
92
- } else {
93
- setTextTracks(undefined);
142
+ }
94
143
  }
95
- }, [fileState, collectionName, mediaClient]);
96
- return textTracks;
144
+ }, [resolvedSelectedTracksIndex, captionTracks, mediaClient, fileState, collectionName]);
145
+
146
+ // Revokes the object urls when the component unmounts.
147
+ (0, _react.useEffect)(function () {
148
+ var currentCaptionsObjectURLs = captionsObjectURLs.current;
149
+ return function () {
150
+ currentCaptionsObjectURLs.forEach(function (objectUrl) {
151
+ URL.revokeObjectURL(objectUrl);
152
+ });
153
+ };
154
+ }, []);
155
+ var textTracks = (0, _react.useMemo)(function () {
156
+ return {
157
+ captions: {
158
+ selectedTrackIndex: resolvedSelectedTracksIndex,
159
+ tracks: captionTracks
160
+ }
161
+ };
162
+ }, [captionTracks, resolvedSelectedTracksIndex]);
163
+ return {
164
+ textTracks: textTracks,
165
+ verifyUserCaptionsEnabled: verifyUserCaptionsEnabled,
166
+ areCaptionsEnabled: areCaptionsEnabled,
167
+ setSelectedTracksIndex: setSelectedTracksIndex,
168
+ setAreCaptionsEnabled: setAreCaptionsEnabled
169
+ };
97
170
  };
@@ -7,7 +7,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { withMediaAnalyticsContext } from '@atlaskit/media-common';
8
8
  export const CustomMediaPlayerBase = props => fg('platform_media_compiled') ? /*#__PURE__*/React.createElement(CompiledCustomMediaPlayerBase, props) : /*#__PURE__*/React.createElement(EmotionCustomMediaPlayerBase, props);
9
9
  const packageName = "@atlaskit/media-ui";
10
- const packageVersion = "28.5.1";
10
+ const packageVersion = "28.5.3";
11
11
 
12
12
  // @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
13
13
  export const CustomMediaPlayer = withMediaAnalyticsContext({
@@ -56,9 +56,7 @@ const deleteCaption = async (mediaClient, identifier, artifactName, onStart, onE
56
56
  };
57
57
  onStart === null || onStart === void 0 ? void 0 : onStart(context);
58
58
  try {
59
- await mediaClient.file.deleteArtifact(identifier.id, {
60
- artifactName
61
- }, identifier.collectionName, {
59
+ await mediaClient.file.deleteArtifact(identifier.id, artifactName, identifier.collectionName, {
62
60
  traceId: context.traceId
63
61
  });
64
62
  onEnd === null || onEnd === void 0 ? void 0 : onEnd(context);
@@ -1,18 +1,20 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import { withMediaAnalyticsContext } from '@atlaskit/media-common';
4
- import { useFileState, useMediaClient, useMediaSettings } from '@atlaskit/media-client-react';
4
+ import { useFileState, useMediaSettings } from '@atlaskit/media-client-react';
5
5
  import { MediaPlayerBase } from './mediaPlayerBase';
6
6
  import { useTextTracks } from './useTextTracks';
7
7
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
8
8
  const packageName = "@atlaskit/media-ui";
9
- const packageVersion = "28.5.1";
10
- export const MediaPlayerWihtoutContext = props => {
9
+ const packageVersion = "28.5.3";
10
+ export const MediaPlayerWihtoutContext = ({
11
+ onPlay,
12
+ ...props
13
+ }) => {
11
14
  const {
12
15
  createAnalyticsEvent
13
16
  } = useAnalyticsEvents();
14
17
  const mediaSettings = useMediaSettings();
15
- const mediaClient = useMediaClient();
16
18
  const {
17
19
  id,
18
20
  collectionName
@@ -22,12 +24,25 @@ export const MediaPlayerWihtoutContext = props => {
22
24
  } = useFileState(id, {
23
25
  collectionName
24
26
  });
25
- const textTracks = useTextTracks(fileState, mediaClient, collectionName);
27
+ const {
28
+ textTracks,
29
+ verifyUserCaptionsEnabled,
30
+ setSelectedTracksIndex,
31
+ setAreCaptionsEnabled,
32
+ areCaptionsEnabled
33
+ } = useTextTracks(fileState, collectionName);
26
34
  return /*#__PURE__*/React.createElement(MediaPlayerBase, _extends({}, props, {
27
35
  fileState: fileState,
28
36
  mediaSettings: mediaSettings,
29
37
  textTracks: textTracks,
30
- createAnalyticsEvent: createAnalyticsEvent
38
+ createAnalyticsEvent: createAnalyticsEvent,
39
+ areCaptionsEnabled: areCaptionsEnabled,
40
+ onPlay: () => {
41
+ verifyUserCaptionsEnabled();
42
+ onPlay === null || onPlay === void 0 ? void 0 : onPlay();
43
+ },
44
+ onTextTracksSelected: setSelectedTracksIndex,
45
+ onCaptionsEnabledChange: setAreCaptionsEnabled
31
46
  }));
32
47
  };
33
48
  export const MediaPlayer = withMediaAnalyticsContext({
@@ -41,7 +41,6 @@ import { SkipTenBackwardIcon, SkipTenForwardIcon } from '@atlaskit/legacy-custom
41
41
  import { fg } from '@atlaskit/platform-feature-flags';
42
42
  import VideoSkipForwardTenIcon from '@atlaskit/icon/core/video-skip-forward-ten';
43
43
  import VideoSkipBackwardTenIcon from '@atlaskit/icon/core/video-skip-backward-ten';
44
- import { getUserCaptionsLocale, setUserCaptionsLocale, findPreselectedTrackIndex, getUserCaptionsEnabled, setUserCaptionsEnabled } from './captions';
45
44
  import { CaptionsUploaderBrowser } from './captions/artifactUploader';
46
45
  import CaptionDeleteConfirmationModal from './captions/captionDeleteConfirmationModal';
47
46
  const MINIMUM_DURATION_BEFORE_SAVING_TIME = 60;
@@ -94,8 +93,8 @@ const spinnerWrapperStyles = {
94
93
  root: "_kqswstnw _154ize3t _1ltvze3t _1bsb1osq _4t3i1osq"
95
94
  };
96
95
  class _MediaPlayerBase extends Component {
97
- constructor(props) {
98
- super(props);
96
+ constructor(...args) {
97
+ super(...args);
99
98
  _defineProperty(this, "videoWrapperRef", /*#__PURE__*/React.createRef());
100
99
  _defineProperty(this, "videoState", {
101
100
  isLoading: true,
@@ -115,26 +114,9 @@ class _MediaPlayerBase extends Component {
115
114
  playerWidth: 100,
116
115
  // initial value for playerSize: 'small', i.e. width < 260px
117
116
  playbackSpeed: 1,
118
- selectedTracksIndex: -1,
119
- areCaptionsEnabled: false,
120
117
  isArtifactUploaderOpen: false,
121
118
  artifactToDelete: undefined
122
119
  });
123
- _defineProperty(this, "findPreselectedTrackIndex", ({
124
- textTracks,
125
- intl
126
- }) => {
127
- var _textTracks$captions;
128
- return findPreselectedTrackIndex((textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions = textTracks.captions) === null || _textTracks$captions === void 0 ? void 0 : _textTracks$captions.tracks) || [], intl.locale, this.getUserCaptionsPreference());
129
- });
130
- _defineProperty(this, "getUserCaptionsPreference", () => {
131
- return this.mediaUserPreferences && getUserCaptionsLocale(this.mediaUserPreferences);
132
- });
133
- _defineProperty(this, "setUserCaptionsPreference", selectedTracks => {
134
- if (this.mediaUserPreferences) {
135
- setUserCaptionsLocale(this.mediaUserPreferences, selectedTracks.lang);
136
- }
137
- });
138
120
  _defineProperty(this, "fireFirstPlayedTrackEvent", () => {
139
121
  const {
140
122
  type,
@@ -465,7 +447,8 @@ class _MediaPlayerBase extends Component {
465
447
  });
466
448
  _defineProperty(this, "play", () => {
467
449
  const {
468
- onFirstPlay
450
+ onFirstPlay,
451
+ onPlay
469
452
  } = this.props;
470
453
  if (this.actions) {
471
454
  this.actions.play();
@@ -476,12 +459,7 @@ class _MediaPlayerBase extends Component {
476
459
  this.wasPlayedOnce = true;
477
460
  onFirstPlay();
478
461
  }
479
- if (this.mediaUserPreferences) {
480
- const userCaptionsEnabled = getUserCaptionsEnabled(this.mediaUserPreferences);
481
- this.setState({
482
- areCaptionsEnabled: userCaptionsEnabled
483
- });
484
- }
462
+ onPlay === null || onPlay === void 0 ? void 0 : onPlay();
485
463
  });
486
464
  _defineProperty(this, "getMediaButtonClickHandler", (action, buttonType) => () => {
487
465
  action();
@@ -556,17 +534,12 @@ class _MediaPlayerBase extends Component {
556
534
  _defineProperty(this, "startPlayByButtonClick", this.getMediaButtonClickHandler(this.play, 'playButton'));
557
535
  _defineProperty(this, "pausePlayByButtonClick", this.getMediaButtonClickHandler(this.pause, 'pauseButton'));
558
536
  _defineProperty(this, "onTextTracksSelected", selectedTracksIndex => {
559
- var _this$props$textTrack, _this$props$textTrack2;
560
- const selectedTracks = (_this$props$textTrack = this.props.textTracks) === null || _this$props$textTrack === void 0 ? void 0 : (_this$props$textTrack2 = _this$props$textTrack.captions) === null || _this$props$textTrack2 === void 0 ? void 0 : _this$props$textTrack2.tracks[selectedTracksIndex];
561
- !!selectedTracks && this.setUserCaptionsPreference(selectedTracks);
562
- this.setState({
563
- selectedTracksIndex
564
- });
537
+ var _this$props$onTextTra, _this$props6;
538
+ (_this$props$onTextTra = (_this$props6 = this.props).onTextTracksSelected) === null || _this$props$onTextTra === void 0 ? void 0 : _this$props$onTextTra.call(_this$props6, selectedTracksIndex);
565
539
  });
566
540
  _defineProperty(this, "onCaptionsEnabledChange", areCaptionsEnabled => {
567
- this.setState({
568
- areCaptionsEnabled
569
- });
541
+ var _this$props$onCaption, _this$props7;
542
+ (_this$props$onCaption = (_this$props7 = this.props).onCaptionsEnabledChange) === null || _this$props$onCaption === void 0 ? void 0 : _this$props$onCaption.call(_this$props7, areCaptionsEnabled);
570
543
  });
571
544
  _defineProperty(this, "onCaptionDelete", artifactName => {
572
545
  // Modal is not supported in fullscreen mode (as it uses portals which are not in the same DOM tree),
@@ -578,54 +551,32 @@ class _MediaPlayerBase extends Component {
578
551
  artifactToDelete: artifactName
579
552
  });
580
553
  });
581
- _defineProperty(this, "resolveSelectedTracksIndex", () => {
582
- const {
583
- areCaptionsEnabled,
584
- selectedTracksIndex
585
- } = this.state;
586
- return areCaptionsEnabled ? selectedTracksIndex > -1 ? selectedTracksIndex : 0 : -1;
587
- });
588
- _defineProperty(this, "resolveTextTracks", () => {
589
- const {
590
- areCaptionsEnabled
591
- } = this.state;
592
- const {
593
- textTracks
594
- } = this.props;
595
- const tracksKey = 'captions';
596
- if (areCaptionsEnabled && textTracks !== null && textTracks !== void 0 && textTracks[tracksKey]) {
597
- return {
598
- ...textTracks,
599
- [tracksKey]: {
600
- ...textTracks[tracksKey],
601
- selectedTrackIndex: this.resolveSelectedTracksIndex()
602
- }
603
- };
604
- }
605
- return undefined;
606
- });
607
554
  _defineProperty(this, "shouldRenderCaptionsControls", () => {
555
+ var _textTracks$captions, _textTracks$captions$;
608
556
  const {
609
557
  textTracks
610
558
  } = this.props;
611
559
  const {
612
560
  playerWidth
613
561
  } = this.state;
614
- return breakpointControls.captionsControls(playerWidth) && !!textTracks;
562
+ 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);
615
563
  });
616
564
  _defineProperty(this, "renderCaptionsControls", () => {
617
565
  const {
618
566
  textTracks
619
567
  } = this.props;
568
+ const {
569
+ selectedTrackIndex = -1
570
+ } = (textTracks === null || textTracks === void 0 ? void 0 : textTracks.captions) || {};
620
571
  const {
621
572
  areCaptionsEnabled
622
- } = this.state;
573
+ } = this.props;
623
574
  return textTracks && /*#__PURE__*/React.createElement(CaptionsSelectControls, {
624
575
  textTracks: textTracks,
625
576
  onSelected: this.onTextTracksSelected,
626
577
  areCaptionsEnabled: !!areCaptionsEnabled,
627
578
  onCaptionsEnabledChange: this.onCaptionsEnabledChange,
628
- selectedTracksIndex: this.resolveSelectedTracksIndex()
579
+ selectedTracksIndex: selectedTrackIndex
629
580
  });
630
581
  });
631
582
  _defineProperty(this, "shouldRenderCaptionsAdminControls", () => {
@@ -682,40 +633,6 @@ class _MediaPlayerBase extends Component {
682
633
  }
683
634
  }));
684
635
  });
685
- this.state.selectedTracksIndex = this.findPreselectedTrackIndex(this.props);
686
- if (this.mediaUserPreferences) {
687
- const userCaptionsEnabled = getUserCaptionsEnabled(this.mediaUserPreferences);
688
- this.state.areCaptionsEnabled = userCaptionsEnabled;
689
- }
690
- }
691
- componentDidUpdate(prevProps, prevState) {
692
- var _prevTextTracks$capti, _textTracks$captions2;
693
- const {
694
- intl,
695
- textTracks
696
- } = this.props;
697
- const {
698
- intl: prevIntl,
699
- textTracks: prevTextTracks
700
- } = prevProps;
701
- const didLocaleChange = prevIntl.locale !== intl.locale;
702
- const didTextTracksChange = (prevTextTracks === null || prevTextTracks === void 0 ? void 0 : (_prevTextTracks$capti = prevTextTracks.captions) === null || _prevTextTracks$capti === void 0 ? void 0 : _prevTextTracks$capti.tracks) !== (textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions2 = textTracks.captions) === null || _textTracks$captions2 === void 0 ? void 0 : _textTracks$captions2.tracks);
703
- if (didLocaleChange || didTextTracksChange) {
704
- this.setState({
705
- selectedTracksIndex: this.findPreselectedTrackIndex(this.props)
706
- });
707
- }
708
- if (this.mediaUserPreferences && prevState.areCaptionsEnabled !== this.state.areCaptionsEnabled) {
709
- setUserCaptionsEnabled(this.mediaUserPreferences, !!this.state.areCaptionsEnabled);
710
- }
711
- }
712
- get mediaUserPreferences() {
713
- const {
714
- mediaSettings: {
715
- mediaUserPreferences = undefined
716
- } = {}
717
- } = this.props;
718
- return mediaUserPreferences;
719
636
  }
720
637
  componentDidMount() {
721
638
  const {
@@ -748,14 +665,14 @@ class _MediaPlayerBase extends Component {
748
665
  }
749
666
  simultaneousPlayManager.subscribe(this);
750
667
  if (isAutoPlay) {
751
- var _this$props$onPlay, _this$props6;
668
+ var _this$props$onPlay, _this$props8;
752
669
  simultaneousPlayManager.pauseOthers(this);
753
670
  if (onFirstPlay) {
754
671
  this.fireFirstPlayedTrackEvent();
755
672
  this.wasPlayedOnce = true;
756
673
  onFirstPlay();
757
674
  }
758
- (_this$props$onPlay = (_this$props6 = this.props).onPlay) === null || _this$props$onPlay === void 0 ? void 0 : _this$props$onPlay.call(_this$props6);
675
+ (_this$props$onPlay = (_this$props8 = this.props).onPlay) === null || _this$props$onPlay === void 0 ? void 0 : _this$props$onPlay.call(_this$props8);
759
676
  }
760
677
  }
761
678
  componentWillUnmount() {
@@ -763,8 +680,8 @@ class _MediaPlayerBase extends Component {
763
680
  this.videoWrapperRef.current.removeEventListener('fullscreenchange', this.onFullScreenChange);
764
681
  }
765
682
  if (this.state.isFullScreenEnabled) {
766
- var _this$props$onFullscr2, _this$props7;
767
- (_this$props$onFullscr2 = (_this$props7 = this.props).onFullscreenChange) === null || _this$props$onFullscr2 === void 0 ? void 0 : _this$props$onFullscr2.call(_this$props7, false);
683
+ var _this$props$onFullscr2, _this$props9;
684
+ (_this$props$onFullscr2 = (_this$props9 = this.props).onFullscreenChange) === null || _this$props$onFullscr2 === void 0 ? void 0 : _this$props$onFullscr2.call(_this$props9, false);
768
685
  }
769
686
  simultaneousPlayManager.unsubscribe(this);
770
687
  }
@@ -834,17 +751,17 @@ class _MediaPlayerBase extends Component {
834
751
  fireAnalyticsEvent(analyticsEvent, createAnalyticsEvent);
835
752
  }
836
753
  baseAnalyticCaptionAttributes() {
837
- var _textTracks$captions3, _textTracks$captions4, _textTracks$captions5, _textTracks$captions6, _textTracks$captions7;
754
+ var _textTracks$captions2, _textTracks$captions3, _textTracks$captions4, _textTracks$captions5, _textTracks$captions6;
838
755
  const {
839
756
  textTracks
840
757
  } = this.props;
841
758
  const {
842
- selectedTracksIndex
843
- } = this.state;
759
+ selectedTrackIndex = -1
760
+ } = (textTracks === null || textTracks === void 0 ? void 0 : textTracks.captions) || {};
844
761
  const captionAttributes = {
845
- selectedTrackIndex: selectedTracksIndex,
846
- availableCaptionTracks: (textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions3 = textTracks.captions) === null || _textTracks$captions3 === void 0 ? void 0 : (_textTracks$captions4 = _textTracks$captions3.tracks) === null || _textTracks$captions4 === void 0 ? void 0 : _textTracks$captions4.length) || 0,
847
- selectedTrackLanguage: (textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions5 = textTracks.captions) === null || _textTracks$captions5 === void 0 ? void 0 : (_textTracks$captions6 = _textTracks$captions5.tracks) === null || _textTracks$captions6 === void 0 ? void 0 : (_textTracks$captions7 = _textTracks$captions6[selectedTracksIndex]) === null || _textTracks$captions7 === void 0 ? void 0 : _textTracks$captions7.lang) || null
762
+ selectedTrackIndex,
763
+ availableCaptionTracks: (textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions2 = textTracks.captions) === null || _textTracks$captions2 === void 0 ? void 0 : (_textTracks$captions3 = _textTracks$captions2.tracks) === null || _textTracks$captions3 === void 0 ? void 0 : _textTracks$captions3.length) || 0,
764
+ selectedTrackLanguage: (textTracks === null || textTracks === void 0 ? void 0 : (_textTracks$captions4 = textTracks.captions) === null || _textTracks$captions4 === void 0 ? void 0 : (_textTracks$captions5 = _textTracks$captions4.tracks) === null || _textTracks$captions5 === void 0 ? void 0 : (_textTracks$captions6 = _textTracks$captions5[selectedTrackIndex]) === null || _textTracks$captions6 === void 0 ? void 0 : _textTracks$captions6.lang) || null
848
765
  };
849
766
  return captionAttributes;
850
767
  }
@@ -881,7 +798,8 @@ class _MediaPlayerBase extends Component {
881
798
  onError,
882
799
  poster,
883
800
  videoControlsWrapperRef,
884
- areControlsVisible
801
+ areControlsVisible,
802
+ textTracks
885
803
  } = this.props;
886
804
  return /*#__PURE__*/React.createElement(Box, {
887
805
  xcss: customVideoWrapperStyles.root,
@@ -896,7 +814,7 @@ class _MediaPlayerBase extends Component {
896
814
  onTimeChange: this.onCurrentTimeChange,
897
815
  onError: onError,
898
816
  poster: poster,
899
- textTracks: this.resolveTextTracks(),
817
+ textTracks: textTracks,
900
818
  textTracksPosition: areControlsVisible ? -3.7 : undefined
901
819
  }, (video, videoState, actions) => {
902
820
  this.onViewed(videoState);
@@ -0,0 +1 @@
1
+ export {};