@folklore/hooks 0.0.56 → 0.0.58

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 (3) hide show
  1. package/dist/cjs.js +57 -67
  2. package/dist/es.js +58 -68
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -68,55 +68,6 @@ function useCounter(desiredValue, _ref) {
68
68
  return currentValue;
69
69
  }
70
70
 
71
- function usePlayerCurrentTime(player) {
72
- let {
73
- id = null,
74
- disabled = false,
75
- updateInterval = 1000,
76
- onUpdate: customOnUpdate = null,
77
- getCurrentTime = p => p.currentTime
78
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
79
- const [currentTime, setCurrentTime] = react.useState(0);
80
- const realCurrentTime = react.useRef(currentTime);
81
- const lastIdRef = react.useRef(id);
82
- const idChanged = lastIdRef.current !== id;
83
- if (idChanged) {
84
- realCurrentTime.current = 0;
85
- lastIdRef.current = id;
86
- }
87
-
88
- // Check time update
89
- react.useEffect(() => {
90
- if (disabled || player === null) {
91
- return () => {};
92
- }
93
- let canceled = false;
94
- const updateTime = time => {
95
- if (canceled) {
96
- return;
97
- }
98
- realCurrentTime.current = time;
99
- setCurrentTime(time);
100
- if (customOnUpdate !== null) {
101
- customOnUpdate(time);
102
- }
103
- };
104
- const interval = setInterval(() => {
105
- const time = getCurrentTime(player);
106
- if (typeof time.then !== 'undefined') {
107
- time.then(updateTime);
108
- } else {
109
- updateTime(time);
110
- }
111
- }, updateInterval);
112
- return () => {
113
- canceled = true;
114
- clearInterval(interval);
115
- };
116
- }, [id, player, setCurrentTime, disabled, updateInterval, getCurrentTime]);
117
- return realCurrentTime.current;
118
- }
119
-
120
71
  const NO_PLAYER_ERROR$3 = new Error('No player');
121
72
  function useDailymotionPlayer() {
122
73
  let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
@@ -125,16 +76,8 @@ function useDailymotionPlayer() {
125
76
  width = 0,
126
77
  height = 0,
127
78
  duration = 0,
128
- autoplay = false,
129
79
  muted: initialMuted = false,
130
80
  start = 0,
131
- controls = true,
132
- queueAutoplayNext = false,
133
- queueEnable = false,
134
- sharingEnable = false,
135
- uiLogo = false,
136
- uiStartScreenInfo = true,
137
- timeUpdateInterval = 1000,
138
81
  embedPlayerId = null,
139
82
  onTimeUpdate: customOnTimeUpdate = null,
140
83
  getVideoId = url => {
@@ -218,15 +161,8 @@ function useDailymotionPlayer() {
218
161
  return;
219
162
  }
220
163
  const playerParams = {
221
- 'autoplay-d': autoplay,
222
- // muted,
223
- start,
224
- controls,
225
- 'queue-autoplay-next': queueAutoplayNext,
226
- 'queue-enable': queueEnable,
227
- 'sharing-enable': sharingEnable,
228
- 'ui-logo': uiLogo,
229
- 'ui-start-screen-info': uiStartScreenInfo
164
+ startTime: start,
165
+ aspectRatio: 'inherit'
230
166
  };
231
167
  let player = currentPlayer;
232
168
  if (player !== null) {
@@ -249,7 +185,7 @@ function useDailymotionPlayer() {
249
185
  debug('Create player [ID: %s]', videoId);
250
186
  }
251
187
  playerElementRef.current = element;
252
- }, [apiLoaded, elementHasChanged, videoId, width, height, autoplay, start, controls, queueAutoplayNext, queueEnable, sharingEnable, uiLogo, uiStartScreenInfo]);
188
+ }, [apiLoaded, elementHasChanged, videoId, width, height, start]);
253
189
  react.useEffect(() => {
254
190
  const {
255
191
  current: player = null
@@ -439,6 +375,11 @@ function useDailymotionPlayer() {
439
375
  } = playerRef;
440
376
  return player !== null ? player.seek(time) : Promise.reject(NO_PLAYER_ERROR$3);
441
377
  }, []);
378
+ react.useEffect(() => {
379
+ if (customOnTimeUpdate !== null) {
380
+ customOnTimeUpdate(currentTime);
381
+ }
382
+ }, [currentTime, customOnTimeUpdate]);
442
383
  return {
443
384
  ref: elementRef,
444
385
  player: playerRef.current,
@@ -940,6 +881,55 @@ const useItemsPaginated = function (loader) {
940
881
  };
941
882
  };
942
883
 
884
+ function usePlayerCurrentTime(player) {
885
+ let {
886
+ id = null,
887
+ disabled = false,
888
+ updateInterval = 1000,
889
+ onUpdate: customOnUpdate = null,
890
+ getCurrentTime = p => p.currentTime
891
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
892
+ const [currentTime, setCurrentTime] = react.useState(0);
893
+ const realCurrentTime = react.useRef(currentTime);
894
+ const lastIdRef = react.useRef(id);
895
+ const idChanged = lastIdRef.current !== id;
896
+ if (idChanged) {
897
+ realCurrentTime.current = 0;
898
+ lastIdRef.current = id;
899
+ }
900
+
901
+ // Check time update
902
+ react.useEffect(() => {
903
+ if (disabled || player === null) {
904
+ return () => {};
905
+ }
906
+ let canceled = false;
907
+ const updateTime = time => {
908
+ if (canceled) {
909
+ return;
910
+ }
911
+ realCurrentTime.current = time;
912
+ setCurrentTime(time);
913
+ if (customOnUpdate !== null) {
914
+ customOnUpdate(time);
915
+ }
916
+ };
917
+ const interval = setInterval(() => {
918
+ const time = getCurrentTime(player);
919
+ if (typeof time.then !== 'undefined') {
920
+ time.then(updateTime);
921
+ } else {
922
+ updateTime(time);
923
+ }
924
+ }, updateInterval);
925
+ return () => {
926
+ canceled = true;
927
+ clearInterval(interval);
928
+ };
929
+ }, [id, player, setCurrentTime, disabled, updateInterval, getCurrentTime]);
930
+ return realCurrentTime.current;
931
+ }
932
+
943
933
  const NO_PLAYER_ERROR$2 = new Error('No player');
944
934
  function useNativeVideoPlayer(url) {
945
935
  let {
package/dist/es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import raf from 'raf';
2
- import { useState, useEffect, useRef, useMemo, useCallback } from 'react';
2
+ import { useState, useEffect, useMemo, useRef, useCallback } from 'react';
3
3
  import { loadDailymotion, loadVimeo, loadYouTube } from '@folklore/services';
4
4
  import createDebug from 'debug';
5
5
  import EventsManager from '@folklore/events';
@@ -57,55 +57,6 @@ function useCounter(desiredValue, _ref) {
57
57
  return currentValue;
58
58
  }
59
59
 
60
- function usePlayerCurrentTime(player) {
61
- let {
62
- id = null,
63
- disabled = false,
64
- updateInterval = 1000,
65
- onUpdate: customOnUpdate = null,
66
- getCurrentTime = p => p.currentTime
67
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
68
- const [currentTime, setCurrentTime] = useState(0);
69
- const realCurrentTime = useRef(currentTime);
70
- const lastIdRef = useRef(id);
71
- const idChanged = lastIdRef.current !== id;
72
- if (idChanged) {
73
- realCurrentTime.current = 0;
74
- lastIdRef.current = id;
75
- }
76
-
77
- // Check time update
78
- useEffect(() => {
79
- if (disabled || player === null) {
80
- return () => {};
81
- }
82
- let canceled = false;
83
- const updateTime = time => {
84
- if (canceled) {
85
- return;
86
- }
87
- realCurrentTime.current = time;
88
- setCurrentTime(time);
89
- if (customOnUpdate !== null) {
90
- customOnUpdate(time);
91
- }
92
- };
93
- const interval = setInterval(() => {
94
- const time = getCurrentTime(player);
95
- if (typeof time.then !== 'undefined') {
96
- time.then(updateTime);
97
- } else {
98
- updateTime(time);
99
- }
100
- }, updateInterval);
101
- return () => {
102
- canceled = true;
103
- clearInterval(interval);
104
- };
105
- }, [id, player, setCurrentTime, disabled, updateInterval, getCurrentTime]);
106
- return realCurrentTime.current;
107
- }
108
-
109
60
  const NO_PLAYER_ERROR$3 = new Error('No player');
110
61
  function useDailymotionPlayer() {
111
62
  let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
@@ -114,16 +65,8 @@ function useDailymotionPlayer() {
114
65
  width = 0,
115
66
  height = 0,
116
67
  duration = 0,
117
- autoplay = false,
118
68
  muted: initialMuted = false,
119
69
  start = 0,
120
- controls = true,
121
- queueAutoplayNext = false,
122
- queueEnable = false,
123
- sharingEnable = false,
124
- uiLogo = false,
125
- uiStartScreenInfo = true,
126
- timeUpdateInterval = 1000,
127
70
  embedPlayerId = null,
128
71
  onTimeUpdate: customOnTimeUpdate = null,
129
72
  getVideoId = url => {
@@ -207,15 +150,8 @@ function useDailymotionPlayer() {
207
150
  return;
208
151
  }
209
152
  const playerParams = {
210
- 'autoplay-d': autoplay,
211
- // muted,
212
- start,
213
- controls,
214
- 'queue-autoplay-next': queueAutoplayNext,
215
- 'queue-enable': queueEnable,
216
- 'sharing-enable': sharingEnable,
217
- 'ui-logo': uiLogo,
218
- 'ui-start-screen-info': uiStartScreenInfo
153
+ startTime: start,
154
+ aspectRatio: 'inherit'
219
155
  };
220
156
  let player = currentPlayer;
221
157
  if (player !== null) {
@@ -238,7 +174,7 @@ function useDailymotionPlayer() {
238
174
  debug('Create player [ID: %s]', videoId);
239
175
  }
240
176
  playerElementRef.current = element;
241
- }, [apiLoaded, elementHasChanged, videoId, width, height, autoplay, start, controls, queueAutoplayNext, queueEnable, sharingEnable, uiLogo, uiStartScreenInfo]);
177
+ }, [apiLoaded, elementHasChanged, videoId, width, height, start]);
242
178
  useEffect(() => {
243
179
  const {
244
180
  current: player = null
@@ -428,6 +364,11 @@ function useDailymotionPlayer() {
428
364
  } = playerRef;
429
365
  return player !== null ? player.seek(time) : Promise.reject(NO_PLAYER_ERROR$3);
430
366
  }, []);
367
+ useEffect(() => {
368
+ if (customOnTimeUpdate !== null) {
369
+ customOnTimeUpdate(currentTime);
370
+ }
371
+ }, [currentTime, customOnTimeUpdate]);
431
372
  return {
432
373
  ref: elementRef,
433
374
  player: playerRef.current,
@@ -929,6 +870,55 @@ const useItemsPaginated = function (loader) {
929
870
  };
930
871
  };
931
872
 
873
+ function usePlayerCurrentTime(player) {
874
+ let {
875
+ id = null,
876
+ disabled = false,
877
+ updateInterval = 1000,
878
+ onUpdate: customOnUpdate = null,
879
+ getCurrentTime = p => p.currentTime
880
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
881
+ const [currentTime, setCurrentTime] = useState(0);
882
+ const realCurrentTime = useRef(currentTime);
883
+ const lastIdRef = useRef(id);
884
+ const idChanged = lastIdRef.current !== id;
885
+ if (idChanged) {
886
+ realCurrentTime.current = 0;
887
+ lastIdRef.current = id;
888
+ }
889
+
890
+ // Check time update
891
+ useEffect(() => {
892
+ if (disabled || player === null) {
893
+ return () => {};
894
+ }
895
+ let canceled = false;
896
+ const updateTime = time => {
897
+ if (canceled) {
898
+ return;
899
+ }
900
+ realCurrentTime.current = time;
901
+ setCurrentTime(time);
902
+ if (customOnUpdate !== null) {
903
+ customOnUpdate(time);
904
+ }
905
+ };
906
+ const interval = setInterval(() => {
907
+ const time = getCurrentTime(player);
908
+ if (typeof time.then !== 'undefined') {
909
+ time.then(updateTime);
910
+ } else {
911
+ updateTime(time);
912
+ }
913
+ }, updateInterval);
914
+ return () => {
915
+ canceled = true;
916
+ clearInterval(interval);
917
+ };
918
+ }, [id, player, setCurrentTime, disabled, updateInterval, getCurrentTime]);
919
+ return realCurrentTime.current;
920
+ }
921
+
932
922
  const NO_PLAYER_ERROR$2 = new Error('No player');
933
923
  function useNativeVideoPlayer(url) {
934
924
  let {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/hooks",
3
- "version": "0.0.56",
3
+ "version": "0.0.58",
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": "075c1674bbedc9d3a0aea9facf98fdb2391105ce",
52
+ "gitHead": "eec9d8318fc17f4a40396ee05e15bb93a48c40cc",
53
53
  "dependencies": {
54
54
  "@folklore/events": "^0.0.5",
55
55
  "@folklore/services": "^0.1.40",