@folklore/hooks 0.0.54 → 0.0.55
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/dist/cjs.js +50 -21
- package/dist/es.js +50 -21
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -167,6 +167,7 @@ function useDailymotionPlayer() {
|
|
|
167
167
|
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
168
168
|
const [muted, setMuted] = react.useState(initialMuted);
|
|
169
169
|
const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
|
|
170
|
+
const [currentTime, setCurrentTime] = react.useState(0);
|
|
170
171
|
const [playState, setPlayState] = react.useState({
|
|
171
172
|
playing: false,
|
|
172
173
|
paused: false,
|
|
@@ -264,20 +265,34 @@ function useDailymotionPlayer() {
|
|
|
264
265
|
setLoaded(true);
|
|
265
266
|
debug('onPlaybackReady [ID: %s]', videoId);
|
|
266
267
|
}
|
|
267
|
-
function onDurationChange() {
|
|
268
|
+
function onDurationChange(_ref) {
|
|
269
|
+
let {
|
|
270
|
+
videoTime,
|
|
271
|
+
videoDuration
|
|
272
|
+
} = _ref;
|
|
268
273
|
currentMetadata = {
|
|
269
274
|
...currentMetadata,
|
|
270
|
-
duration:
|
|
275
|
+
duration: videoDuration
|
|
271
276
|
};
|
|
272
277
|
setMetadata(currentMetadata);
|
|
278
|
+
setCurrentTime(videoTime);
|
|
273
279
|
debug('onDurationChange [ID: %s]', videoId);
|
|
274
280
|
}
|
|
275
|
-
function onVolumeChange() {
|
|
276
|
-
|
|
277
|
-
|
|
281
|
+
function onVolumeChange(_ref2) {
|
|
282
|
+
let {
|
|
283
|
+
playerIsMuted,
|
|
284
|
+
playerVolume,
|
|
285
|
+
videoTime
|
|
286
|
+
} = _ref2;
|
|
287
|
+
setMuted(playerIsMuted);
|
|
288
|
+
setVolumeState(playerVolume);
|
|
289
|
+
setCurrentTime(videoTime);
|
|
278
290
|
debug('onVolumeChange [ID: %s]', videoId);
|
|
279
291
|
}
|
|
280
|
-
function onPlay() {
|
|
292
|
+
function onPlay(_ref3) {
|
|
293
|
+
let {
|
|
294
|
+
videoTime
|
|
295
|
+
} = _ref3;
|
|
281
296
|
currentPlayState = {
|
|
282
297
|
...currentPlayState,
|
|
283
298
|
playing: true,
|
|
@@ -285,9 +300,13 @@ function useDailymotionPlayer() {
|
|
|
285
300
|
ended: false
|
|
286
301
|
};
|
|
287
302
|
setPlayState(currentPlayState);
|
|
303
|
+
setCurrentTime(videoTime);
|
|
288
304
|
debug('onPlay [ID: %s]', videoId);
|
|
289
305
|
}
|
|
290
|
-
function onPause() {
|
|
306
|
+
function onPause(_ref4) {
|
|
307
|
+
let {
|
|
308
|
+
videoTime
|
|
309
|
+
} = _ref4;
|
|
291
310
|
currentPlayState = {
|
|
292
311
|
...currentPlayState,
|
|
293
312
|
playing: false,
|
|
@@ -295,9 +314,13 @@ function useDailymotionPlayer() {
|
|
|
295
314
|
ended: false
|
|
296
315
|
};
|
|
297
316
|
setPlayState(currentPlayState);
|
|
317
|
+
setCurrentTime(videoTime);
|
|
298
318
|
debug('onPause [ID: %s]', videoId);
|
|
299
319
|
}
|
|
300
|
-
function onEnd() {
|
|
320
|
+
function onEnd(_ref5) {
|
|
321
|
+
let {
|
|
322
|
+
videoTime
|
|
323
|
+
} = _ref5;
|
|
301
324
|
currentPlayState = {
|
|
302
325
|
...currentPlayState,
|
|
303
326
|
playing: false,
|
|
@@ -305,24 +328,39 @@ function useDailymotionPlayer() {
|
|
|
305
328
|
ended: true
|
|
306
329
|
};
|
|
307
330
|
setPlayState(currentPlayState);
|
|
331
|
+
setCurrentTime(videoTime);
|
|
308
332
|
debug('onEnd [ID: %s]', videoId);
|
|
309
333
|
}
|
|
310
|
-
function onPlaying() {
|
|
334
|
+
function onPlaying(_ref6) {
|
|
335
|
+
let {
|
|
336
|
+
videoTime
|
|
337
|
+
} = _ref6;
|
|
311
338
|
currentPlayState = {
|
|
312
339
|
...currentPlayState,
|
|
313
340
|
buffering: false
|
|
314
341
|
};
|
|
315
342
|
setPlayState(currentPlayState);
|
|
343
|
+
setCurrentTime(videoTime);
|
|
316
344
|
debug('onPlaying [ID: %s]', videoId);
|
|
317
345
|
}
|
|
318
|
-
function onWaiting() {
|
|
346
|
+
function onWaiting(_ref7) {
|
|
347
|
+
let {
|
|
348
|
+
videoTime
|
|
349
|
+
} = _ref7;
|
|
319
350
|
currentPlayState = {
|
|
320
351
|
...currentPlayState,
|
|
321
352
|
buffering: true
|
|
322
353
|
};
|
|
323
354
|
setPlayState(currentPlayState);
|
|
355
|
+
setCurrentTime(videoTime);
|
|
324
356
|
debug('onWaiting [ID: %s]', videoId);
|
|
325
357
|
}
|
|
358
|
+
function onTimeChange(_ref8) {
|
|
359
|
+
let {
|
|
360
|
+
videoTime
|
|
361
|
+
} = _ref8;
|
|
362
|
+
setCurrentTime(videoTime);
|
|
363
|
+
}
|
|
326
364
|
function onAdStart() {
|
|
327
365
|
currentPlayState = {
|
|
328
366
|
...currentPlayState,
|
|
@@ -347,6 +385,7 @@ function useDailymotionPlayer() {
|
|
|
347
385
|
player.on(dailymotion.events.VIDEO_END, onEnd);
|
|
348
386
|
player.on(dailymotion.events.VIDEO_PLAYING, onPlaying);
|
|
349
387
|
player.on(dailymotion.events.VIDEO_BUFFERING, onWaiting);
|
|
388
|
+
player.on(dailymotion.events.VIDEO_TIMECHANGE, onTimeChange);
|
|
350
389
|
player.on(dailymotion.events.AD_START, onAdStart);
|
|
351
390
|
player.on(dailymotion.events.AD_END, onAdEnd);
|
|
352
391
|
return () => {
|
|
@@ -358,6 +397,7 @@ function useDailymotionPlayer() {
|
|
|
358
397
|
player.off(dailymotion.events.VIDEO_END, onEnd);
|
|
359
398
|
player.off(dailymotion.events.VIDEO_PLAYING, onPlaying);
|
|
360
399
|
player.off(dailymotion.events.VIDEO_BUFFERING, onWaiting);
|
|
400
|
+
player.off(dailymotion.events.VIDEO_TIMECHANGE, onTimeChange);
|
|
361
401
|
player.off(dailymotion.events.AD_START, onAdStart);
|
|
362
402
|
player.off(dailymotion.events.AD_END, onAdEnd);
|
|
363
403
|
};
|
|
@@ -398,17 +438,6 @@ function useDailymotionPlayer() {
|
|
|
398
438
|
} = playerRef;
|
|
399
439
|
return player !== null ? player.seek(time) : Promise.reject(NO_PLAYER_ERROR$3);
|
|
400
440
|
}, []);
|
|
401
|
-
const {
|
|
402
|
-
playing
|
|
403
|
-
} = playState;
|
|
404
|
-
const getCurrentTime = react.useCallback(player => player.videoTime || 0, []);
|
|
405
|
-
const currentTime = usePlayerCurrentTime(playerRef.current, {
|
|
406
|
-
id: videoId,
|
|
407
|
-
disabled: !playing || timeUpdateInterval === null,
|
|
408
|
-
updateInterval: timeUpdateInterval,
|
|
409
|
-
onUpdate: customOnTimeUpdate,
|
|
410
|
-
getCurrentTime
|
|
411
|
-
});
|
|
412
441
|
return {
|
|
413
442
|
ref: elementRef,
|
|
414
443
|
player: playerRef.current,
|
package/dist/es.js
CHANGED
|
@@ -156,6 +156,7 @@ function useDailymotionPlayer() {
|
|
|
156
156
|
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
157
157
|
const [muted, setMuted] = useState(initialMuted);
|
|
158
158
|
const [volume, setVolumeState] = useState(initialMuted ? 0 : 1);
|
|
159
|
+
const [currentTime, setCurrentTime] = useState(0);
|
|
159
160
|
const [playState, setPlayState] = useState({
|
|
160
161
|
playing: false,
|
|
161
162
|
paused: false,
|
|
@@ -253,20 +254,34 @@ function useDailymotionPlayer() {
|
|
|
253
254
|
setLoaded(true);
|
|
254
255
|
debug('onPlaybackReady [ID: %s]', videoId);
|
|
255
256
|
}
|
|
256
|
-
function onDurationChange() {
|
|
257
|
+
function onDurationChange(_ref) {
|
|
258
|
+
let {
|
|
259
|
+
videoTime,
|
|
260
|
+
videoDuration
|
|
261
|
+
} = _ref;
|
|
257
262
|
currentMetadata = {
|
|
258
263
|
...currentMetadata,
|
|
259
|
-
duration:
|
|
264
|
+
duration: videoDuration
|
|
260
265
|
};
|
|
261
266
|
setMetadata(currentMetadata);
|
|
267
|
+
setCurrentTime(videoTime);
|
|
262
268
|
debug('onDurationChange [ID: %s]', videoId);
|
|
263
269
|
}
|
|
264
|
-
function onVolumeChange() {
|
|
265
|
-
|
|
266
|
-
|
|
270
|
+
function onVolumeChange(_ref2) {
|
|
271
|
+
let {
|
|
272
|
+
playerIsMuted,
|
|
273
|
+
playerVolume,
|
|
274
|
+
videoTime
|
|
275
|
+
} = _ref2;
|
|
276
|
+
setMuted(playerIsMuted);
|
|
277
|
+
setVolumeState(playerVolume);
|
|
278
|
+
setCurrentTime(videoTime);
|
|
267
279
|
debug('onVolumeChange [ID: %s]', videoId);
|
|
268
280
|
}
|
|
269
|
-
function onPlay() {
|
|
281
|
+
function onPlay(_ref3) {
|
|
282
|
+
let {
|
|
283
|
+
videoTime
|
|
284
|
+
} = _ref3;
|
|
270
285
|
currentPlayState = {
|
|
271
286
|
...currentPlayState,
|
|
272
287
|
playing: true,
|
|
@@ -274,9 +289,13 @@ function useDailymotionPlayer() {
|
|
|
274
289
|
ended: false
|
|
275
290
|
};
|
|
276
291
|
setPlayState(currentPlayState);
|
|
292
|
+
setCurrentTime(videoTime);
|
|
277
293
|
debug('onPlay [ID: %s]', videoId);
|
|
278
294
|
}
|
|
279
|
-
function onPause() {
|
|
295
|
+
function onPause(_ref4) {
|
|
296
|
+
let {
|
|
297
|
+
videoTime
|
|
298
|
+
} = _ref4;
|
|
280
299
|
currentPlayState = {
|
|
281
300
|
...currentPlayState,
|
|
282
301
|
playing: false,
|
|
@@ -284,9 +303,13 @@ function useDailymotionPlayer() {
|
|
|
284
303
|
ended: false
|
|
285
304
|
};
|
|
286
305
|
setPlayState(currentPlayState);
|
|
306
|
+
setCurrentTime(videoTime);
|
|
287
307
|
debug('onPause [ID: %s]', videoId);
|
|
288
308
|
}
|
|
289
|
-
function onEnd() {
|
|
309
|
+
function onEnd(_ref5) {
|
|
310
|
+
let {
|
|
311
|
+
videoTime
|
|
312
|
+
} = _ref5;
|
|
290
313
|
currentPlayState = {
|
|
291
314
|
...currentPlayState,
|
|
292
315
|
playing: false,
|
|
@@ -294,24 +317,39 @@ function useDailymotionPlayer() {
|
|
|
294
317
|
ended: true
|
|
295
318
|
};
|
|
296
319
|
setPlayState(currentPlayState);
|
|
320
|
+
setCurrentTime(videoTime);
|
|
297
321
|
debug('onEnd [ID: %s]', videoId);
|
|
298
322
|
}
|
|
299
|
-
function onPlaying() {
|
|
323
|
+
function onPlaying(_ref6) {
|
|
324
|
+
let {
|
|
325
|
+
videoTime
|
|
326
|
+
} = _ref6;
|
|
300
327
|
currentPlayState = {
|
|
301
328
|
...currentPlayState,
|
|
302
329
|
buffering: false
|
|
303
330
|
};
|
|
304
331
|
setPlayState(currentPlayState);
|
|
332
|
+
setCurrentTime(videoTime);
|
|
305
333
|
debug('onPlaying [ID: %s]', videoId);
|
|
306
334
|
}
|
|
307
|
-
function onWaiting() {
|
|
335
|
+
function onWaiting(_ref7) {
|
|
336
|
+
let {
|
|
337
|
+
videoTime
|
|
338
|
+
} = _ref7;
|
|
308
339
|
currentPlayState = {
|
|
309
340
|
...currentPlayState,
|
|
310
341
|
buffering: true
|
|
311
342
|
};
|
|
312
343
|
setPlayState(currentPlayState);
|
|
344
|
+
setCurrentTime(videoTime);
|
|
313
345
|
debug('onWaiting [ID: %s]', videoId);
|
|
314
346
|
}
|
|
347
|
+
function onTimeChange(_ref8) {
|
|
348
|
+
let {
|
|
349
|
+
videoTime
|
|
350
|
+
} = _ref8;
|
|
351
|
+
setCurrentTime(videoTime);
|
|
352
|
+
}
|
|
315
353
|
function onAdStart() {
|
|
316
354
|
currentPlayState = {
|
|
317
355
|
...currentPlayState,
|
|
@@ -336,6 +374,7 @@ function useDailymotionPlayer() {
|
|
|
336
374
|
player.on(dailymotion.events.VIDEO_END, onEnd);
|
|
337
375
|
player.on(dailymotion.events.VIDEO_PLAYING, onPlaying);
|
|
338
376
|
player.on(dailymotion.events.VIDEO_BUFFERING, onWaiting);
|
|
377
|
+
player.on(dailymotion.events.VIDEO_TIMECHANGE, onTimeChange);
|
|
339
378
|
player.on(dailymotion.events.AD_START, onAdStart);
|
|
340
379
|
player.on(dailymotion.events.AD_END, onAdEnd);
|
|
341
380
|
return () => {
|
|
@@ -347,6 +386,7 @@ function useDailymotionPlayer() {
|
|
|
347
386
|
player.off(dailymotion.events.VIDEO_END, onEnd);
|
|
348
387
|
player.off(dailymotion.events.VIDEO_PLAYING, onPlaying);
|
|
349
388
|
player.off(dailymotion.events.VIDEO_BUFFERING, onWaiting);
|
|
389
|
+
player.off(dailymotion.events.VIDEO_TIMECHANGE, onTimeChange);
|
|
350
390
|
player.off(dailymotion.events.AD_START, onAdStart);
|
|
351
391
|
player.off(dailymotion.events.AD_END, onAdEnd);
|
|
352
392
|
};
|
|
@@ -387,17 +427,6 @@ function useDailymotionPlayer() {
|
|
|
387
427
|
} = playerRef;
|
|
388
428
|
return player !== null ? player.seek(time) : Promise.reject(NO_PLAYER_ERROR$3);
|
|
389
429
|
}, []);
|
|
390
|
-
const {
|
|
391
|
-
playing
|
|
392
|
-
} = playState;
|
|
393
|
-
const getCurrentTime = useCallback(player => player.videoTime || 0, []);
|
|
394
|
-
const currentTime = usePlayerCurrentTime(playerRef.current, {
|
|
395
|
-
id: videoId,
|
|
396
|
-
disabled: !playing || timeUpdateInterval === null,
|
|
397
|
-
updateInterval: timeUpdateInterval,
|
|
398
|
-
onUpdate: customOnTimeUpdate,
|
|
399
|
-
getCurrentTime
|
|
400
|
-
});
|
|
401
430
|
return {
|
|
402
431
|
ref: elementRef,
|
|
403
432
|
player: playerRef.current,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.55",
|
|
4
4
|
"description": "React hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "27737f20865cc496b94c42c75f908f4dce5018fa",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@folklore/events": "^0.0.5",
|
|
55
55
|
"@folklore/services": "^0.1.40",
|