@folklore/hooks 0.0.46 → 0.0.47
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 +11 -5
- package/dist/es.js +11 -5
- package/package.json +3 -3
package/dist/cjs.js
CHANGED
|
@@ -152,15 +152,18 @@ function useDailymotionPlayer() {
|
|
|
152
152
|
}
|
|
153
153
|
} = params;
|
|
154
154
|
const debug = react.useMemo(() => createDebug__default["default"]('folklore:video:dailymotion'), []);
|
|
155
|
-
const [apiLoaded, setApiLoaded] = react.useState(typeof window !== 'undefined' && typeof window.
|
|
155
|
+
const [apiLoaded, setApiLoaded] = react.useState(typeof window !== 'undefined' && typeof window.dailymotion !== 'undefined');
|
|
156
156
|
const [playerReady, setPlayerReady] = react.useState(false);
|
|
157
157
|
const [loaded, setLoaded] = react.useState(false);
|
|
158
|
-
const apiRef = react.useRef(typeof window !== 'undefined' && typeof window.
|
|
158
|
+
const apiRef = react.useRef(typeof window !== 'undefined' && typeof window.dailymotion !== 'undefined' ? window.dailymotion : null);
|
|
159
159
|
const ready = apiLoaded && playerReady;
|
|
160
160
|
const videoId = react.useMemo(() => getVideoId(id), [id]);
|
|
161
161
|
const elementRef = react.useRef(null);
|
|
162
162
|
const playerRef = react.useRef(null);
|
|
163
163
|
const playerElementRef = react.useRef(elementRef.current);
|
|
164
|
+
if (elementRef.current !== null && playerElementRef.current === null) {
|
|
165
|
+
playerElementRef.current = elementRef.current;
|
|
166
|
+
}
|
|
164
167
|
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
165
168
|
const [muted, setMuted] = react.useState(initialMuted);
|
|
166
169
|
const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
|
|
@@ -182,7 +185,10 @@ function useDailymotionPlayer() {
|
|
|
182
185
|
let canceled = false;
|
|
183
186
|
if (!apiLoaded && videoId !== null) {
|
|
184
187
|
debug('Load API');
|
|
185
|
-
services.loadDailymotion(
|
|
188
|
+
services.loadDailymotion({
|
|
189
|
+
url: 'https://geo.dailymotion.com/libs/player.js',
|
|
190
|
+
callback: null
|
|
191
|
+
}).then(api => {
|
|
186
192
|
if (!canceled) {
|
|
187
193
|
apiRef.current = api;
|
|
188
194
|
setApiLoaded(true);
|
|
@@ -198,7 +204,7 @@ function useDailymotionPlayer() {
|
|
|
198
204
|
// Create or update player
|
|
199
205
|
react.useEffect(() => {
|
|
200
206
|
const {
|
|
201
|
-
current:
|
|
207
|
+
current: dailymotion = null
|
|
202
208
|
} = apiRef;
|
|
203
209
|
const {
|
|
204
210
|
current: currentPlayer = null
|
|
@@ -227,7 +233,7 @@ function useDailymotionPlayer() {
|
|
|
227
233
|
});
|
|
228
234
|
debug('Load video [ID: %s]', videoId);
|
|
229
235
|
} else {
|
|
230
|
-
player =
|
|
236
|
+
player = dailymotion.createPlayer(element, {
|
|
231
237
|
video: videoId,
|
|
232
238
|
width,
|
|
233
239
|
height,
|
package/dist/es.js
CHANGED
|
@@ -141,15 +141,18 @@ function useDailymotionPlayer() {
|
|
|
141
141
|
}
|
|
142
142
|
} = params;
|
|
143
143
|
const debug = useMemo(() => createDebug('folklore:video:dailymotion'), []);
|
|
144
|
-
const [apiLoaded, setApiLoaded] = useState(typeof window !== 'undefined' && typeof window.
|
|
144
|
+
const [apiLoaded, setApiLoaded] = useState(typeof window !== 'undefined' && typeof window.dailymotion !== 'undefined');
|
|
145
145
|
const [playerReady, setPlayerReady] = useState(false);
|
|
146
146
|
const [loaded, setLoaded] = useState(false);
|
|
147
|
-
const apiRef = useRef(typeof window !== 'undefined' && typeof window.
|
|
147
|
+
const apiRef = useRef(typeof window !== 'undefined' && typeof window.dailymotion !== 'undefined' ? window.dailymotion : null);
|
|
148
148
|
const ready = apiLoaded && playerReady;
|
|
149
149
|
const videoId = useMemo(() => getVideoId(id), [id]);
|
|
150
150
|
const elementRef = useRef(null);
|
|
151
151
|
const playerRef = useRef(null);
|
|
152
152
|
const playerElementRef = useRef(elementRef.current);
|
|
153
|
+
if (elementRef.current !== null && playerElementRef.current === null) {
|
|
154
|
+
playerElementRef.current = elementRef.current;
|
|
155
|
+
}
|
|
153
156
|
const elementHasChanged = elementRef.current !== playerElementRef.current;
|
|
154
157
|
const [muted, setMuted] = useState(initialMuted);
|
|
155
158
|
const [volume, setVolumeState] = useState(initialMuted ? 0 : 1);
|
|
@@ -171,7 +174,10 @@ function useDailymotionPlayer() {
|
|
|
171
174
|
let canceled = false;
|
|
172
175
|
if (!apiLoaded && videoId !== null) {
|
|
173
176
|
debug('Load API');
|
|
174
|
-
loadDailymotion(
|
|
177
|
+
loadDailymotion({
|
|
178
|
+
url: 'https://geo.dailymotion.com/libs/player.js',
|
|
179
|
+
callback: null
|
|
180
|
+
}).then(api => {
|
|
175
181
|
if (!canceled) {
|
|
176
182
|
apiRef.current = api;
|
|
177
183
|
setApiLoaded(true);
|
|
@@ -187,7 +193,7 @@ function useDailymotionPlayer() {
|
|
|
187
193
|
// Create or update player
|
|
188
194
|
useEffect(() => {
|
|
189
195
|
const {
|
|
190
|
-
current:
|
|
196
|
+
current: dailymotion = null
|
|
191
197
|
} = apiRef;
|
|
192
198
|
const {
|
|
193
199
|
current: currentPlayer = null
|
|
@@ -216,7 +222,7 @@ function useDailymotionPlayer() {
|
|
|
216
222
|
});
|
|
217
223
|
debug('Load video [ID: %s]', videoId);
|
|
218
224
|
} else {
|
|
219
|
-
player =
|
|
225
|
+
player = dailymotion.createPlayer(element, {
|
|
220
226
|
video: videoId,
|
|
221
227
|
width,
|
|
222
228
|
height,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "React hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c1626b0db8d1a530bb7f79ac37fa6efdd13e49b3",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@folklore/events": "^0.0.5",
|
|
55
|
-
"@folklore/services": "^0.1.
|
|
55
|
+
"@folklore/services": "^0.1.39",
|
|
56
56
|
"cancelable-promise": "^4.3.1",
|
|
57
57
|
"debug": "^4.3.4",
|
|
58
58
|
"lodash": "^4.17.21",
|