mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
Collecting youtube ids for fetching
This commit is contained in:
parent
8ff9fdd9bd
commit
2b757a07a2
4 changed files with 87 additions and 26 deletions
|
@ -36,3 +36,8 @@ export const playerSeek = (seek: number) => ({
|
|||
type: PLAYER_ACTIONS.SEEK,
|
||||
seek,
|
||||
});
|
||||
|
||||
export const playerGetYoutubeInfo = (url: string) => ({
|
||||
type: PLAYER_ACTIONS.GET_YOUTUBE_INFO,
|
||||
url,
|
||||
});
|
||||
|
|
|
@ -10,6 +10,8 @@ export const PLAYER_ACTIONS = {
|
|||
SEEK: `${prefix}SEEK`,
|
||||
STOP: `${prefix}STOP`,
|
||||
STOPPED: `${prefix}STOPPED`,
|
||||
|
||||
GET_YOUTUBE_INFO: `${prefix}GET_YOUTUBE_INFO`,
|
||||
};
|
||||
|
||||
export const PLAYER_STATES = {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { takeLatest, put } from 'redux-saga/effects';
|
||||
import { takeLatest, put, fork, race, take, delay } from 'redux-saga/effects';
|
||||
import { PLAYER_ACTIONS, PLAYER_STATES } from './constants';
|
||||
import { playerSetFile, playerSeek, playerSetStatus } from './actions';
|
||||
import { playerSetFile, playerSeek, playerSetStatus, playerGetYoutubeInfo } from './actions';
|
||||
import { Player } from '~/utils/player';
|
||||
import { getURL } from '~/utils/dom';
|
||||
|
||||
|
@ -31,6 +31,29 @@ function* stoppedSaga() {
|
|||
yield put(playerSetFile(null));
|
||||
}
|
||||
|
||||
function* getYoutubeInfo() {
|
||||
let ids = [];
|
||||
|
||||
while (true) {
|
||||
const {
|
||||
action,
|
||||
ticker,
|
||||
}: { action: ReturnType<typeof playerGetYoutubeInfo>; ticker: any } = yield race({
|
||||
action: take(PLAYER_ACTIONS.GET_YOUTUBE_INFO),
|
||||
...(ids.length > 0 ? { ticker: delay(1000) } : {}),
|
||||
});
|
||||
|
||||
if (action) {
|
||||
ids.push(action.url);
|
||||
}
|
||||
|
||||
if (ticker || ids.length > 25) {
|
||||
// console.log('FETCHING!', ids);
|
||||
ids = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default function* playerSaga() {
|
||||
yield takeLatest(PLAYER_ACTIONS.SET_FILE_AND_PLAY, setFileAndPlaySaga);
|
||||
yield takeLatest(PLAYER_ACTIONS.PAUSE, pauseSaga);
|
||||
|
@ -38,4 +61,7 @@ export default function* playerSaga() {
|
|||
yield takeLatest(PLAYER_ACTIONS.SEEK, seekSaga);
|
||||
yield takeLatest(PLAYER_ACTIONS.STOP, stopSaga);
|
||||
yield takeLatest(PLAYER_ACTIONS.STOPPED, stoppedSaga);
|
||||
|
||||
yield fork(getYoutubeInfo);
|
||||
// yield takeEvery(PLAYER_ACTIONS.GET_YOUTUBE_INFO, getYoutubeInfo);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue