1
0
Fork 0
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:
Fedor Katurov 2020-04-18 22:33:59 +07:00
parent 8ff9fdd9bd
commit 2b757a07a2
4 changed files with 87 additions and 26 deletions

View file

@ -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);
}