@zohodesk/dot 1.7.22 → 1.7.23
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.
- package/README.md +5 -0
- package/assets/Appearance/dark/mode/Dot_DarkMode.module.css +7 -0
- package/assets/Appearance/light/mode/Dot_LightMode.module.css +7 -0
- package/assets/Appearance/pureDark/mode/Dot_PureDarkMode.module.css +7 -0
- package/es/AudioPlayer/AudioPlayer.js +580 -0
- package/es/AudioPlayer/AudioPlayer.module.css +146 -0
- package/es/AudioPlayer/Timer/Timer.js +67 -0
- package/es/AudioPlayer/Timer/Timer.module.css +5 -0
- package/es/AudioPlayer/Timer/__tests__/Timer.spec.js +20 -0
- package/es/AudioPlayer/Timer/__tests__/__snapshots__/Timer.spec.js.snap +14 -0
- package/es/AudioPlayer/Timer/propTypes/defaultProps.js +4 -0
- package/es/AudioPlayer/Timer/propTypes/propTypes.js +11 -0
- package/es/AudioPlayer/__tests__/AudioPlayer.spec.js +44 -0
- package/es/AudioPlayer/__tests__/__snapshots__/AudioPlayer.spec.js.snap +145 -0
- package/es/AudioPlayer/propTypes/defaultProps.js +14 -0
- package/es/AudioPlayer/propTypes/propTypes.js +33 -0
- package/es/AudioPlayer/utils/utils.js +24 -0
- package/lib/AudioPlayer/AudioPlayer.js +662 -0
- package/lib/AudioPlayer/AudioPlayer.module.css +146 -0
- package/lib/AudioPlayer/Timer/Timer.js +117 -0
- package/lib/AudioPlayer/Timer/Timer.module.css +5 -0
- package/lib/AudioPlayer/Timer/__tests__/Timer.spec.js +26 -0
- package/lib/AudioPlayer/Timer/__tests__/__snapshots__/Timer.spec.js.snap +14 -0
- package/lib/AudioPlayer/Timer/propTypes/defaultProps.js +11 -0
- package/lib/AudioPlayer/Timer/propTypes/propTypes.js +22 -0
- package/lib/AudioPlayer/__tests__/AudioPlayer.spec.js +50 -0
- package/lib/AudioPlayer/__tests__/__snapshots__/AudioPlayer.spec.js.snap +145 -0
- package/lib/AudioPlayer/propTypes/defaultProps.js +24 -0
- package/lib/AudioPlayer/propTypes/propTypes.js +44 -0
- package/lib/AudioPlayer/utils/utils.js +33 -0
- package/package.json +1 -1
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _Layout = require("@zohodesk/components/lib/Layout");
|
|
13
|
+
|
|
14
|
+
var _Timer = _interopRequireDefault(require("./Timer/Timer"));
|
|
15
|
+
|
|
16
|
+
var _Icon = _interopRequireDefault(require("@zohodesk/icons/lib/Icon"));
|
|
17
|
+
|
|
18
|
+
var _propTypes = require("./propTypes/propTypes");
|
|
19
|
+
|
|
20
|
+
var _defaultProps = require("./propTypes/defaultProps");
|
|
21
|
+
|
|
22
|
+
var _utils = require("./utils/utils");
|
|
23
|
+
|
|
24
|
+
var _Attachment = require("./../AttachmentViewer/Attachment");
|
|
25
|
+
|
|
26
|
+
var _AudioPlayerModule = _interopRequireDefault(require("./AudioPlayer.module.css"));
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
+
|
|
30
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
+
|
|
32
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
33
|
+
|
|
34
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
35
|
+
|
|
36
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
|
+
|
|
38
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
39
|
+
|
|
40
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
41
|
+
|
|
42
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
43
|
+
|
|
44
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
45
|
+
|
|
46
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
|
+
|
|
48
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
49
|
+
|
|
50
|
+
var AudioPlayer = /*#__PURE__*/function (_React$Component) {
|
|
51
|
+
_inherits(AudioPlayer, _React$Component);
|
|
52
|
+
|
|
53
|
+
var _super = _createSuper(AudioPlayer);
|
|
54
|
+
|
|
55
|
+
function AudioPlayer(props) {
|
|
56
|
+
var _this;
|
|
57
|
+
|
|
58
|
+
_classCallCheck(this, AudioPlayer);
|
|
59
|
+
|
|
60
|
+
_this = _super.call(this, props);
|
|
61
|
+
_this.audioPlayer = null;
|
|
62
|
+
_this.removeEventListeners = _this.removeEventListeners.bind(_assertThisInitialized(_this));
|
|
63
|
+
_this.setAudioPlayerRef = _this.setAudioPlayerRef.bind(_assertThisInitialized(_this));
|
|
64
|
+
return _this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_createClass(AudioPlayer, [{
|
|
68
|
+
key: "componentDidMount",
|
|
69
|
+
value: function componentDidMount() {
|
|
70
|
+
var AudioPlayerChild = this.refs.AudioPlayerChild;
|
|
71
|
+
this.audioPlayer.addEventListener('keydown', AudioPlayerChild.handleKeyDown);
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "componentWillUnmount",
|
|
75
|
+
value: function componentWillUnmount() {
|
|
76
|
+
this.removeEventListeners();
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "removeEventListeners",
|
|
80
|
+
value: function removeEventListeners() {
|
|
81
|
+
var AudioPlayerChild = this.refs.AudioPlayerChild;
|
|
82
|
+
this.audioPlayer.removeEventListener('keydown', AudioPlayerChild.handleKeyDown);
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "setAudioPlayerRef",
|
|
86
|
+
value: function setAudioPlayerRef(ele) {
|
|
87
|
+
this.audioPlayer = ele;
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "render",
|
|
91
|
+
value: function render() {
|
|
92
|
+
var _this$props = this.props,
|
|
93
|
+
id = _this$props.id,
|
|
94
|
+
isPlay = _this$props.isPlay,
|
|
95
|
+
onClose = _this$props.onClose,
|
|
96
|
+
src = _this$props.src,
|
|
97
|
+
timerFormat = _this$props.timerFormat,
|
|
98
|
+
forwardStepInSec = _this$props.forwardStepInSec,
|
|
99
|
+
backwardStepInSec = _this$props.backwardStepInSec,
|
|
100
|
+
getAudioDuration = _this$props.getAudioDuration,
|
|
101
|
+
needClose = _this$props.needClose,
|
|
102
|
+
needDownload = _this$props.needDownload,
|
|
103
|
+
needMuteIcon = _this$props.needMuteIcon,
|
|
104
|
+
onPlay = _this$props.onPlay,
|
|
105
|
+
onPause = _this$props.onPause,
|
|
106
|
+
onDownloading = _this$props.onDownloading,
|
|
107
|
+
onAudioSeeking = _this$props.onAudioSeeking,
|
|
108
|
+
onAudioLoading = _this$props.onAudioLoading,
|
|
109
|
+
onError = _this$props.onError,
|
|
110
|
+
onMuteUnmute = _this$props.onMuteUnmute,
|
|
111
|
+
duration = _this$props.duration,
|
|
112
|
+
i18nKeys = _this$props.i18nKeys,
|
|
113
|
+
dataId = _this$props.dataId,
|
|
114
|
+
customClass = _this$props.customClass,
|
|
115
|
+
range = _this$props.range;
|
|
116
|
+
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
117
|
+
dataId: dataId,
|
|
118
|
+
eleRef: this.setAudioPlayerRef,
|
|
119
|
+
tabIndex: 0,
|
|
120
|
+
isCover: false,
|
|
121
|
+
className: "".concat(customClass)
|
|
122
|
+
}, /*#__PURE__*/_react["default"].createElement(AudioPlayerChild, {
|
|
123
|
+
ref: "AudioPlayerChild",
|
|
124
|
+
id: id,
|
|
125
|
+
src: src,
|
|
126
|
+
isPlay: isPlay,
|
|
127
|
+
onClose: onClose,
|
|
128
|
+
timerFormat: timerFormat,
|
|
129
|
+
duration: duration,
|
|
130
|
+
forwardStepInSec: forwardStepInSec,
|
|
131
|
+
backwardStepInSec: backwardStepInSec,
|
|
132
|
+
getAudioDuration: getAudioDuration,
|
|
133
|
+
needClose: needClose,
|
|
134
|
+
needDownload: needDownload,
|
|
135
|
+
needMuteIcon: needMuteIcon,
|
|
136
|
+
onPlay: onPlay,
|
|
137
|
+
onPause: onPause,
|
|
138
|
+
onDownloading: onDownloading,
|
|
139
|
+
onAudioSeeking: onAudioSeeking,
|
|
140
|
+
onAudioLoading: onAudioLoading,
|
|
141
|
+
onError: onError,
|
|
142
|
+
onMuteUnmute: onMuteUnmute,
|
|
143
|
+
i18nKeys: i18nKeys,
|
|
144
|
+
dataId: dataId,
|
|
145
|
+
range: range
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
}]);
|
|
149
|
+
|
|
150
|
+
return AudioPlayer;
|
|
151
|
+
}(_react["default"].Component);
|
|
152
|
+
|
|
153
|
+
exports["default"] = AudioPlayer;
|
|
154
|
+
AudioPlayer.defaultProps = _defaultProps.AudioPlayer_defaultProps;
|
|
155
|
+
AudioPlayer.propTypes = _propTypes.AudioPlayer_propTypes;
|
|
156
|
+
|
|
157
|
+
var AudioPlayerChild = /*#__PURE__*/function (_React$Component2) {
|
|
158
|
+
_inherits(AudioPlayerChild, _React$Component2);
|
|
159
|
+
|
|
160
|
+
var _super2 = _createSuper(AudioPlayerChild);
|
|
161
|
+
|
|
162
|
+
function AudioPlayerChild(props) {
|
|
163
|
+
var _this2;
|
|
164
|
+
|
|
165
|
+
_classCallCheck(this, AudioPlayerChild);
|
|
166
|
+
|
|
167
|
+
_this2 = _super2.call(this, props);
|
|
168
|
+
_this2.audio = null;
|
|
169
|
+
_this2.intervalId = props.intervalId || '';
|
|
170
|
+
_this2.state = {
|
|
171
|
+
isPlay: props.isPlay,
|
|
172
|
+
currentHour: '00',
|
|
173
|
+
currentMinute: '00',
|
|
174
|
+
currentSecond: '00',
|
|
175
|
+
sliderRangeValue: 0,
|
|
176
|
+
audioHours: '00',
|
|
177
|
+
audioMinutes: '00',
|
|
178
|
+
audioSeconds: '00',
|
|
179
|
+
overallSeconds: 0,
|
|
180
|
+
minValue: 0,
|
|
181
|
+
step: '1',
|
|
182
|
+
audioType: 'audio/mpeg',
|
|
183
|
+
isMuted: false,
|
|
184
|
+
disableControlIcons: true,
|
|
185
|
+
isShowDuration: false,
|
|
186
|
+
disableRangeSlider: false,
|
|
187
|
+
loadingRange: props.range || 0
|
|
188
|
+
}; // Bind all methods
|
|
189
|
+
|
|
190
|
+
_this2.getAudioDetails = _this2.getAudioDetails.bind(_assertThisInitialized(_this2));
|
|
191
|
+
_this2.onPlayAudio = _this2.onPlayAudio.bind(_assertThisInitialized(_this2));
|
|
192
|
+
_this2.onPauseAudio = _this2.onPauseAudio.bind(_assertThisInitialized(_this2));
|
|
193
|
+
_this2.togglePlayPause = _this2.togglePlayPause.bind(_assertThisInitialized(_this2));
|
|
194
|
+
_this2.updatePlayer = _this2.updatePlayer.bind(_assertThisInitialized(_this2));
|
|
195
|
+
_this2.updateRangeValue = _this2.updateRangeValue.bind(_assertThisInitialized(_this2));
|
|
196
|
+
_this2.updateTimerValues = _this2.updateTimerValues.bind(_assertThisInitialized(_this2));
|
|
197
|
+
_this2.togglePlayer = _this2.togglePlayer.bind(_assertThisInitialized(_this2));
|
|
198
|
+
_this2.getAudioDurationDetails = _this2.getAudioDurationDetails.bind(_assertThisInitialized(_this2));
|
|
199
|
+
_this2.browserCompatible = _this2.browserCompatible.bind(_assertThisInitialized(_this2));
|
|
200
|
+
_this2.onMuteUnmute = _this2.onMuteUnmute.bind(_assertThisInitialized(_this2));
|
|
201
|
+
_this2.handleAudioSeeking = _this2.handleAudioSeeking.bind(_assertThisInitialized(_this2));
|
|
202
|
+
_this2.handleError = _this2.handleError.bind(_assertThisInitialized(_this2));
|
|
203
|
+
_this2.handleAudioLoading = _this2.handleAudioLoading.bind(_assertThisInitialized(_this2));
|
|
204
|
+
_this2.removeEventListeners = _this2.removeEventListeners.bind(_assertThisInitialized(_this2));
|
|
205
|
+
_this2.downloadFile = _this2.downloadFile.bind(_assertThisInitialized(_this2));
|
|
206
|
+
_this2.handleKeyDown = _this2.handleKeyDown.bind(_assertThisInitialized(_this2));
|
|
207
|
+
_this2.handleClosePlayer = _this2.handleClosePlayer.bind(_assertThisInitialized(_this2));
|
|
208
|
+
_this2.updateRange = _this2.updateRange.bind(_assertThisInitialized(_this2));
|
|
209
|
+
_this2.setInputRangeRef = _this2.setInputRangeRef.bind(_assertThisInitialized(_this2));
|
|
210
|
+
_this2.removeEvent = _this2.removeEvent.bind(_assertThisInitialized(_this2));
|
|
211
|
+
return _this2;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_createClass(AudioPlayerChild, [{
|
|
215
|
+
key: "componentDidMount",
|
|
216
|
+
value: function componentDidMount() {
|
|
217
|
+
this.audio.addEventListener('loadedmetadata', this.getAudioDetails);
|
|
218
|
+
this.audio.addEventListener('canplay', this.browserCompatible);
|
|
219
|
+
this.audio.addEventListener('seeking', this.handleAudioSeeking);
|
|
220
|
+
this.audio.addEventListener('waiting', this.handleAudioLoading);
|
|
221
|
+
this.audio.addEventListener('error', this.handleError);
|
|
222
|
+
this.audio.addEventListener('ended', this.removeEvent);
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "componentDidUpdate",
|
|
226
|
+
value: function componentDidUpdate(prevProps) {
|
|
227
|
+
if (prevProps.isPlay !== this.props.isPlay && this.props.isPlay === false) {
|
|
228
|
+
this.onPauseAudio();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}, {
|
|
232
|
+
key: "componentWillUnmount",
|
|
233
|
+
value: function componentWillUnmount() {
|
|
234
|
+
this.audio.pause();
|
|
235
|
+
clearInterval(this.intervalId);
|
|
236
|
+
this.removeEventListeners();
|
|
237
|
+
}
|
|
238
|
+
}, {
|
|
239
|
+
key: "removeEventListeners",
|
|
240
|
+
value: function removeEventListeners() {
|
|
241
|
+
this.audio.removeEventListener('loadedmetadata', this.getAudioDetails);
|
|
242
|
+
this.audio.removeEventListener('canplay', this.browserCompatible);
|
|
243
|
+
this.audio.removeEventListener('seeking', this.handleAudioSeeking);
|
|
244
|
+
this.audio.removeEventListener('waiting', this.handleAudioLoading);
|
|
245
|
+
this.audio.removeEventListener('error', this.handleError);
|
|
246
|
+
this.audio.removeEventListener('ended', this.removeEvent);
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "removeEvent",
|
|
250
|
+
value: function removeEvent() {
|
|
251
|
+
setTimeout(this.onPauseAudio, 1000);
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
key: "getAudioDetails",
|
|
255
|
+
value: function getAudioDetails(event) {
|
|
256
|
+
var _this$props2 = this.props,
|
|
257
|
+
getAudioDuration = _this$props2.getAudioDuration,
|
|
258
|
+
src = _this$props2.src,
|
|
259
|
+
fallbackDuration = _this$props2.duration;
|
|
260
|
+
var audioType = (0, _Attachment.getExtensionFromFileName)(src);
|
|
261
|
+
var durationCalc = Math.ceil(event.target.duration);
|
|
262
|
+
var isDurationValid = Number.isFinite(durationCalc) && !Number.isNaN(durationCalc);
|
|
263
|
+
durationCalc = isDurationValid ? durationCalc : fallbackDuration ? fallbackDuration : 0;
|
|
264
|
+
|
|
265
|
+
var _this$getAudioDuratio = this.getAudioDurationDetails(durationCalc),
|
|
266
|
+
hours = _this$getAudioDuratio.hours,
|
|
267
|
+
minutes = _this$getAudioDuratio.minutes,
|
|
268
|
+
seconds = _this$getAudioDuratio.seconds;
|
|
269
|
+
|
|
270
|
+
var isShowDuration = isDurationValid || fallbackDuration !== undefined;
|
|
271
|
+
this.setState({
|
|
272
|
+
overallSeconds: durationCalc,
|
|
273
|
+
audioHours: hours,
|
|
274
|
+
audioMinutes: minutes,
|
|
275
|
+
audioSeconds: seconds,
|
|
276
|
+
audioType: audioType,
|
|
277
|
+
disableControlIcons: false,
|
|
278
|
+
isShowDuration: isShowDuration,
|
|
279
|
+
disableRangeSlider: !isDurationValid
|
|
280
|
+
});
|
|
281
|
+
getAudioDuration && getAudioDuration(hours, minutes, seconds);
|
|
282
|
+
}
|
|
283
|
+
}, {
|
|
284
|
+
key: "getAudioDurationDetails",
|
|
285
|
+
value: function getAudioDurationDetails(valueInSec) {
|
|
286
|
+
var hours = 0,
|
|
287
|
+
minutes = 0,
|
|
288
|
+
seconds = 0;
|
|
289
|
+
|
|
290
|
+
if (valueInSec > 0) {
|
|
291
|
+
hours = Math.floor(valueInSec / 3600);
|
|
292
|
+
valueInSec %= 3600;
|
|
293
|
+
minutes = Math.floor(valueInSec / 60);
|
|
294
|
+
seconds = Math.floor(valueInSec % 60);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
hours: hours <= 9 ? "0".concat(hours) : "".concat(hours),
|
|
299
|
+
minutes: minutes <= 9 ? "0".concat(minutes) : "".concat(minutes),
|
|
300
|
+
seconds: seconds <= 9 ? "0".concat(seconds) : "".concat(seconds)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}, {
|
|
304
|
+
key: "togglePlayPause",
|
|
305
|
+
value: function togglePlayPause() {
|
|
306
|
+
this.state.isPlay ? this.onPauseAudio() : this.onPlayAudio();
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "onPlayAudio",
|
|
310
|
+
value: function onPlayAudio() {
|
|
311
|
+
var _this$props3 = this.props,
|
|
312
|
+
onPlay = _this$props3.onPlay,
|
|
313
|
+
id = _this$props3.id;
|
|
314
|
+
var _this$state = this.state,
|
|
315
|
+
sliderRangeValue = _this$state.sliderRangeValue,
|
|
316
|
+
overallSeconds = _this$state.overallSeconds;
|
|
317
|
+
var isRestart = sliderRangeValue === overallSeconds;
|
|
318
|
+
this.audio.play();
|
|
319
|
+
this.intervalId = setInterval(this.updatePlayer, 1000);
|
|
320
|
+
this.setState({
|
|
321
|
+
isPlay: true,
|
|
322
|
+
isRestart: isRestart
|
|
323
|
+
});
|
|
324
|
+
onPlay && onPlay(id, 'playing');
|
|
325
|
+
}
|
|
326
|
+
}, {
|
|
327
|
+
key: "onPauseAudio",
|
|
328
|
+
value: function onPauseAudio() {
|
|
329
|
+
var _this$props4 = this.props,
|
|
330
|
+
onPause = _this$props4.onPause,
|
|
331
|
+
id = _this$props4.id;
|
|
332
|
+
this.audio.pause();
|
|
333
|
+
clearInterval(this.intervalId);
|
|
334
|
+
this.setState({
|
|
335
|
+
isPlay: false
|
|
336
|
+
});
|
|
337
|
+
onPause && onPause(id, 'paused');
|
|
338
|
+
}
|
|
339
|
+
}, {
|
|
340
|
+
key: "handleClosePlayer",
|
|
341
|
+
value: function handleClosePlayer() {
|
|
342
|
+
var _this$props5 = this.props,
|
|
343
|
+
onClose = _this$props5.onClose,
|
|
344
|
+
id = _this$props5.id;
|
|
345
|
+
this.togglePlayer();
|
|
346
|
+
this.onPauseAudio();
|
|
347
|
+
onClose && onClose(id, 'closed');
|
|
348
|
+
}
|
|
349
|
+
}, {
|
|
350
|
+
key: "handleAudioSeeking",
|
|
351
|
+
value: function handleAudioSeeking() {
|
|
352
|
+
var onAudioSeeking = this.props.onAudioSeeking;
|
|
353
|
+
onAudioSeeking && onAudioSeeking(this.audio.seeking);
|
|
354
|
+
}
|
|
355
|
+
}, {
|
|
356
|
+
key: "handleAudioLoading",
|
|
357
|
+
value: function handleAudioLoading() {
|
|
358
|
+
var onAudioLoading = this.props.onAudioLoading;
|
|
359
|
+
onAudioLoading && onAudioLoading();
|
|
360
|
+
}
|
|
361
|
+
}, {
|
|
362
|
+
key: "handleError",
|
|
363
|
+
value: function handleError() {
|
|
364
|
+
var onError = this.props.onError;
|
|
365
|
+
onError && onError(this.audio.error.code);
|
|
366
|
+
}
|
|
367
|
+
}, {
|
|
368
|
+
key: "browserCompatible",
|
|
369
|
+
value: function browserCompatible(playable) {
|
|
370
|
+
if (playable === '') alert('Your browser is unable to play the audio');
|
|
371
|
+
}
|
|
372
|
+
}, {
|
|
373
|
+
key: "onMuteUnmute",
|
|
374
|
+
value: function onMuteUnmute(e) {
|
|
375
|
+
e && e.preventDefault();
|
|
376
|
+
var isMuted = this.state.isMuted;
|
|
377
|
+
this.audio.muted = !isMuted;
|
|
378
|
+
var onMuteUnmute = this.props.onMuteUnmute;
|
|
379
|
+
this.setState({
|
|
380
|
+
isMuted: !isMuted
|
|
381
|
+
});
|
|
382
|
+
onMuteUnmute && onMuteUnmute(!isMuted);
|
|
383
|
+
}
|
|
384
|
+
}, {
|
|
385
|
+
key: "setInputRangeRef",
|
|
386
|
+
value: function setInputRangeRef(ele) {
|
|
387
|
+
var getRef = this.props.getRef;
|
|
388
|
+
this.inputRange = ele;
|
|
389
|
+
getRef && getRef(ele);
|
|
390
|
+
}
|
|
391
|
+
}, {
|
|
392
|
+
key: "updateRange",
|
|
393
|
+
value: function updateRange(e) {
|
|
394
|
+
this.props.updateRange(e.target.value);
|
|
395
|
+
}
|
|
396
|
+
}, {
|
|
397
|
+
key: "updatePlayer",
|
|
398
|
+
value: function updatePlayer(e) {
|
|
399
|
+
var _e$target;
|
|
400
|
+
|
|
401
|
+
this.updateRangeValue(e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value, this.updateTimerValues);
|
|
402
|
+
}
|
|
403
|
+
}, {
|
|
404
|
+
key: "updateRangeValue",
|
|
405
|
+
value: function updateRangeValue(value, afterUpdateCallback) {
|
|
406
|
+
var _this$state2 = this.state,
|
|
407
|
+
isPlay = _this$state2.isPlay,
|
|
408
|
+
sliderRangeValue = _this$state2.sliderRangeValue,
|
|
409
|
+
overallSeconds = _this$state2.overallSeconds,
|
|
410
|
+
isRestart = _this$state2.isRestart;
|
|
411
|
+
sliderRangeValue = Math.max(0, sliderRangeValue);
|
|
412
|
+
var rangeValue = value || ++sliderRangeValue;
|
|
413
|
+
|
|
414
|
+
if (rangeValue > overallSeconds && !isRestart) {
|
|
415
|
+
if (isPlay) {
|
|
416
|
+
this.audio.pause();
|
|
417
|
+
this.setState({
|
|
418
|
+
isPlay: false
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.audio.currentTime = overallSeconds;
|
|
423
|
+
clearInterval(this.intervalId);
|
|
424
|
+
rangeValue = overallSeconds;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (isRestart) {
|
|
428
|
+
this.audio.currentTime = 0;
|
|
429
|
+
rangeValue = 0;
|
|
430
|
+
this.setState({
|
|
431
|
+
sliderRangeValue: rangeValue,
|
|
432
|
+
isRestart: false,
|
|
433
|
+
isPlay: true
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (rangeValue <= overallSeconds) {
|
|
438
|
+
value && (this.audio.currentTime = value);
|
|
439
|
+
this.setState({
|
|
440
|
+
sliderRangeValue: rangeValue
|
|
441
|
+
}, function () {
|
|
442
|
+
return afterUpdateCallback(rangeValue);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}, {
|
|
447
|
+
key: "updateTimerValues",
|
|
448
|
+
value: function updateTimerValues(sliderRangeValue) {
|
|
449
|
+
var _this$getAudioDuratio2 = this.getAudioDurationDetails(Number(sliderRangeValue)),
|
|
450
|
+
hours = _this$getAudioDuratio2.hours,
|
|
451
|
+
minutes = _this$getAudioDuratio2.minutes,
|
|
452
|
+
seconds = _this$getAudioDuratio2.seconds;
|
|
453
|
+
|
|
454
|
+
this.setState({
|
|
455
|
+
currentHour: hours,
|
|
456
|
+
currentMinute: minutes,
|
|
457
|
+
currentSecond: seconds
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}, {
|
|
461
|
+
key: "togglePlayer",
|
|
462
|
+
value: function togglePlayer() {
|
|
463
|
+
this.audio.pause();
|
|
464
|
+
this.setState({
|
|
465
|
+
isPlay: false
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}, {
|
|
469
|
+
key: "handleKeyDown",
|
|
470
|
+
value: function handleKeyDown(e) {
|
|
471
|
+
var keyCode = e.keyCode;
|
|
472
|
+
var sliderRangeValue = this.state.sliderRangeValue;
|
|
473
|
+
var _this$props6 = this.props,
|
|
474
|
+
forwardStepInSec = _this$props6.forwardStepInSec,
|
|
475
|
+
backwardStepInSec = _this$props6.backwardStepInSec;
|
|
476
|
+
if (keyCode === 32) this.togglePlayPause();else if (keyCode === 39) this.updatePlayer(sliderRangeValue + forwardStepInSec);else if (keyCode === 37) this.updatePlayer(sliderRangeValue - backwardStepInSec);else if (keyCode === 27) this.togglePlayer();
|
|
477
|
+
}
|
|
478
|
+
}, {
|
|
479
|
+
key: "downloadFile",
|
|
480
|
+
value: function downloadFile() {
|
|
481
|
+
var _this$props7 = this.props,
|
|
482
|
+
onDownloading = _this$props7.onDownloading,
|
|
483
|
+
src = _this$props7.src,
|
|
484
|
+
requestOptions = _this$props7.requestOptions;
|
|
485
|
+
|
|
486
|
+
var getFileName = function getFileName(url, ext) {
|
|
487
|
+
var parts = url.split('/');
|
|
488
|
+
var name = parts[parts.length - 1].split('?')[0];
|
|
489
|
+
return name.includes('.') ? name : "".concat(name, ".").concat(ext);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
var reqOptions = requestOptions || {
|
|
493
|
+
credentials: 'include'
|
|
494
|
+
};
|
|
495
|
+
fetch(src, reqOptions).then(function (resp) {
|
|
496
|
+
return resp.blob();
|
|
497
|
+
}).then(function (blob) {
|
|
498
|
+
var url = window.URL.createObjectURL(blob);
|
|
499
|
+
var extnsn = blob.type.split('-')[1] || blob.type.split('/')[1];
|
|
500
|
+
var fileName = getFileName(src, extnsn);
|
|
501
|
+
var a = document.createElement('a');
|
|
502
|
+
a.style.display = 'none';
|
|
503
|
+
a.href = url;
|
|
504
|
+
a.download = fileName;
|
|
505
|
+
document.body.appendChild(a);
|
|
506
|
+
a.click();
|
|
507
|
+
window.URL.revokeObjectURL(url);
|
|
508
|
+
})["catch"](function () {
|
|
509
|
+
return (0, _utils.openInNewTabWithNoopener)(src);
|
|
510
|
+
});
|
|
511
|
+
onDownloading && onDownloading();
|
|
512
|
+
}
|
|
513
|
+
}, {
|
|
514
|
+
key: "render",
|
|
515
|
+
value: function render() {
|
|
516
|
+
var _this3 = this;
|
|
517
|
+
|
|
518
|
+
var _this$state3 = this.state,
|
|
519
|
+
isPlay = _this$state3.isPlay,
|
|
520
|
+
currentHour = _this$state3.currentHour,
|
|
521
|
+
currentMinute = _this$state3.currentMinute,
|
|
522
|
+
currentSecond = _this$state3.currentSecond,
|
|
523
|
+
audioHours = _this$state3.audioHours,
|
|
524
|
+
audioMinutes = _this$state3.audioMinutes,
|
|
525
|
+
audioSeconds = _this$state3.audioSeconds,
|
|
526
|
+
isMuted = _this$state3.isMuted,
|
|
527
|
+
disableControlIcons = _this$state3.disableControlIcons,
|
|
528
|
+
isShowDuration = _this$state3.isShowDuration,
|
|
529
|
+
disableRangeSlider = _this$state3.disableRangeSlider,
|
|
530
|
+
sliderRangeValue = _this$state3.sliderRangeValue,
|
|
531
|
+
overallSeconds = _this$state3.overallSeconds,
|
|
532
|
+
minValue = _this$state3.minValue,
|
|
533
|
+
step = _this$state3.step;
|
|
534
|
+
var _this$props8 = this.props,
|
|
535
|
+
src = _this$props8.src,
|
|
536
|
+
needDownload = _this$props8.needDownload,
|
|
537
|
+
needClose = _this$props8.needClose,
|
|
538
|
+
needMuteIcon = _this$props8.needMuteIcon,
|
|
539
|
+
id = _this$props8.id,
|
|
540
|
+
i18nKeys = _this$props8.i18nKeys,
|
|
541
|
+
dataId = _this$props8.dataId;
|
|
542
|
+
var timerFormat = audioHours ? 'hh:mm:ss' : 'mm:ss';
|
|
543
|
+
var loadingRange = (sliderRangeValue - minValue) * 100 / (overallSeconds - minValue);
|
|
544
|
+
var _i18nKeys$playTitle = i18nKeys.playTitle,
|
|
545
|
+
playTitle = _i18nKeys$playTitle === void 0 ? 'Play' : _i18nKeys$playTitle,
|
|
546
|
+
_i18nKeys$pauseTitle = i18nKeys.pauseTitle,
|
|
547
|
+
pauseTitle = _i18nKeys$pauseTitle === void 0 ? 'Pause' : _i18nKeys$pauseTitle,
|
|
548
|
+
_i18nKeys$downloadTit = i18nKeys.downloadTitle,
|
|
549
|
+
downloadTitle = _i18nKeys$downloadTit === void 0 ? 'Download' : _i18nKeys$downloadTit,
|
|
550
|
+
_i18nKeys$closeTitle = i18nKeys.closeTitle,
|
|
551
|
+
closeTitle = _i18nKeys$closeTitle === void 0 ? 'Close' : _i18nKeys$closeTitle,
|
|
552
|
+
_i18nKeys$muteTitle = i18nKeys.muteTitle,
|
|
553
|
+
muteTitle = _i18nKeys$muteTitle === void 0 ? 'Mute' : _i18nKeys$muteTitle,
|
|
554
|
+
_i18nKeys$unmuteTitle = i18nKeys.unmuteTitle,
|
|
555
|
+
unmuteTitle = _i18nKeys$unmuteTitle === void 0 ? 'Unmute' : _i18nKeys$unmuteTitle;
|
|
556
|
+
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
557
|
+
align: "vertical",
|
|
558
|
+
alignBox: "row",
|
|
559
|
+
className: _AudioPlayerModule["default"].container,
|
|
560
|
+
isCover: false
|
|
561
|
+
}, /*#__PURE__*/_react["default"].createElement("audio", {
|
|
562
|
+
id: id,
|
|
563
|
+
controls: true,
|
|
564
|
+
preload: "auto",
|
|
565
|
+
className: _AudioPlayerModule["default"].audioHid,
|
|
566
|
+
ref: function ref(ele) {
|
|
567
|
+
return _this3.audio = ele;
|
|
568
|
+
}
|
|
569
|
+
}, /*#__PURE__*/_react["default"].createElement("source", {
|
|
570
|
+
src: src,
|
|
571
|
+
type: this.state.audioType
|
|
572
|
+
})), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
573
|
+
className: "".concat(_AudioPlayerModule["default"].rightBox, " ").concat(_AudioPlayerModule["default"].downloadBox, " ").concat(_AudioPlayerModule["default"].boxLeftRadius)
|
|
574
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
575
|
+
className: disableControlIcons ? _AudioPlayerModule["default"].disable : '',
|
|
576
|
+
align: "both",
|
|
577
|
+
onClick: this.togglePlayPause,
|
|
578
|
+
"data-title": isPlay ? pauseTitle : playTitle,
|
|
579
|
+
dataId: "".concat(dataId, "_playpause")
|
|
580
|
+
}, /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
581
|
+
name: isPlay ? 'ZD-commentTimerPause' : 'ZD-bcarr',
|
|
582
|
+
iconClass: "".concat(_AudioPlayerModule["default"].downloadIcon, " ").concat(_AudioPlayerModule["default"].iconColor)
|
|
583
|
+
}))), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
584
|
+
className: _AudioPlayerModule["default"].timerBox
|
|
585
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
586
|
+
align: "vertical",
|
|
587
|
+
alignBox: "row"
|
|
588
|
+
}, /*#__PURE__*/_react["default"].createElement(_Timer["default"], {
|
|
589
|
+
timerFormat: timerFormat,
|
|
590
|
+
hour: currentHour,
|
|
591
|
+
minute: currentMinute,
|
|
592
|
+
second: currentSecond,
|
|
593
|
+
separator: "colon",
|
|
594
|
+
className: _AudioPlayerModule["default"].iconColor
|
|
595
|
+
}), isShowDuration && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
596
|
+
className: _AudioPlayerModule["default"].line
|
|
597
|
+
}, /*#__PURE__*/_react["default"].createElement("span", null, "\xA0"), "/", /*#__PURE__*/_react["default"].createElement("span", null, "\xA0")), /*#__PURE__*/_react["default"].createElement(_Timer["default"], {
|
|
598
|
+
timerFormat: timerFormat,
|
|
599
|
+
hour: audioHours,
|
|
600
|
+
minute: audioMinutes,
|
|
601
|
+
second: audioSeconds,
|
|
602
|
+
separator: "colon",
|
|
603
|
+
className: _AudioPlayerModule["default"].iconColor
|
|
604
|
+
})))), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
605
|
+
className: "".concat(_AudioPlayerModule["default"].dragtag, " ").concat(disableControlIcons || disableRangeSlider ? _AudioPlayerModule["default"].disable : _AudioPlayerModule["default"].cursor),
|
|
606
|
+
flexible: true
|
|
607
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
608
|
+
className: _AudioPlayerModule["default"].audioRangeContainer
|
|
609
|
+
}, /*#__PURE__*/_react["default"].createElement("span", {
|
|
610
|
+
className: _AudioPlayerModule["default"].loading,
|
|
611
|
+
style: {
|
|
612
|
+
width: "".concat(loadingRange, "%")
|
|
613
|
+
}
|
|
614
|
+
}), /*#__PURE__*/_react["default"].createElement("input", {
|
|
615
|
+
"data-id": dataId,
|
|
616
|
+
ref: this.setInputRangeRef,
|
|
617
|
+
className: _AudioPlayerModule["default"].input,
|
|
618
|
+
type: "range",
|
|
619
|
+
value: sliderRangeValue,
|
|
620
|
+
min: minValue,
|
|
621
|
+
max: overallSeconds,
|
|
622
|
+
step: step,
|
|
623
|
+
onChange: this.updatePlayer
|
|
624
|
+
}))), needDownload && /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
625
|
+
className: "".concat(_AudioPlayerModule["default"].rightBox, " ").concat(_AudioPlayerModule["default"].downloadBox, " ").concat(!needClose && !needMuteIcon ? _AudioPlayerModule["default"].boxRightRadius : '')
|
|
626
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
627
|
+
className: disableControlIcons ? _AudioPlayerModule["default"].disable : '',
|
|
628
|
+
align: "both",
|
|
629
|
+
onClick: this.downloadFile,
|
|
630
|
+
"data-title": downloadTitle,
|
|
631
|
+
dataId: "".concat(dataId, "_download")
|
|
632
|
+
}, /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
633
|
+
name: "ZD-downloadNew",
|
|
634
|
+
iconClass: "".concat(_AudioPlayerModule["default"].downloadIcon, " ").concat(_AudioPlayerModule["default"].iconColor)
|
|
635
|
+
}))), needMuteIcon && /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
636
|
+
className: "".concat(_AudioPlayerModule["default"].rightBox, " ").concat(_AudioPlayerModule["default"].downloadBox, " ").concat(!needClose ? _AudioPlayerModule["default"].boxRightRadius : '')
|
|
637
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
638
|
+
className: disableControlIcons ? _AudioPlayerModule["default"].disable : '',
|
|
639
|
+
align: "both",
|
|
640
|
+
onClick: this.onMuteUnmute,
|
|
641
|
+
"data-title": isMuted ? unmuteTitle : muteTitle,
|
|
642
|
+
dataId: "".concat(dataId, "_muteUnmute")
|
|
643
|
+
}, /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
644
|
+
name: isMuted ? 'ZD-mute1New' : 'ZD-kbcatlogovolume',
|
|
645
|
+
iconClass: "".concat(_AudioPlayerModule["default"].downloadIcon, " ").concat(_AudioPlayerModule["default"].iconColor)
|
|
646
|
+
}))), needClose && /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
|
|
647
|
+
className: "".concat(_AudioPlayerModule["default"].closeBox, " ").concat(_AudioPlayerModule["default"].boxRightRadius)
|
|
648
|
+
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
|
|
649
|
+
className: disableControlIcons ? _AudioPlayerModule["default"].disable : '',
|
|
650
|
+
align: "both",
|
|
651
|
+
onClick: this.handleClosePlayer,
|
|
652
|
+
"data-title": closeTitle,
|
|
653
|
+
dataId: "".concat(dataId, "_close")
|
|
654
|
+
}, /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
|
|
655
|
+
name: "ZD-cross",
|
|
656
|
+
iconClass: "".concat(_AudioPlayerModule["default"].pauseIcon, " ").concat(_AudioPlayerModule["default"].iconColor)
|
|
657
|
+
}))));
|
|
658
|
+
}
|
|
659
|
+
}]);
|
|
660
|
+
|
|
661
|
+
return AudioPlayerChild;
|
|
662
|
+
}(_react["default"].Component);
|