mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-01 09:45:10 +00:00
media.positions[outpoint] |> content.positions[claimId][outpoint]
This commit is contained in:
parent
503bc76ef1
commit
f1a799374a
10 changed files with 50 additions and 51 deletions
|
@ -2,9 +2,8 @@ import { connect } from 'react-redux';
|
||||||
import * as settings from 'constants/settings';
|
import * as settings from 'constants/settings';
|
||||||
import { doChangeVolume } from 'redux/actions/app';
|
import { doChangeVolume } from 'redux/actions/app';
|
||||||
import { selectVolume } from 'redux/selectors/app';
|
import { selectVolume } from 'redux/selectors/app';
|
||||||
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content';
|
import { doPlayUri, doSetPlayingUri, savePosition } from 'redux/actions/content';
|
||||||
import { doPlay, doPause, savePosition } from 'redux/actions/media';
|
import { doPlay, doPause } from 'redux/actions/media';
|
||||||
import { doClaimEligiblePurchaseRewards } from 'redux/actions/rewards';
|
|
||||||
import {
|
import {
|
||||||
makeSelectMetadataForUri,
|
makeSelectMetadataForUri,
|
||||||
makeSelectContentTypeForUri,
|
makeSelectContentTypeForUri,
|
||||||
|
@ -16,8 +15,8 @@ import {
|
||||||
selectSearchBarFocused,
|
selectSearchBarFocused,
|
||||||
} from 'lbry-redux';
|
} from 'lbry-redux';
|
||||||
import { makeSelectClientSetting, selectShowNsfw } from 'redux/selectors/settings';
|
import { makeSelectClientSetting, selectShowNsfw } from 'redux/selectors/settings';
|
||||||
import { selectMediaPaused, makeSelectMediaPositionForUri } from 'redux/selectors/media';
|
import { selectMediaPaused } from 'redux/selectors/media';
|
||||||
import { selectPlayingUri } from 'redux/selectors/content';
|
import { selectPlayingUri, makeSelectContentPositionForUri } from 'redux/selectors/content';
|
||||||
import { selectFileInfoErrors } from 'redux/selectors/file_info';
|
import { selectFileInfoErrors } from 'redux/selectors/file_info';
|
||||||
import FileViewer from './view';
|
import FileViewer from './view';
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ const select = (state, props) => ({
|
||||||
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
contentType: makeSelectContentTypeForUri(props.uri)(state),
|
||||||
volume: selectVolume(state),
|
volume: selectVolume(state),
|
||||||
mediaPaused: selectMediaPaused(state),
|
mediaPaused: selectMediaPaused(state),
|
||||||
mediaPosition: makeSelectMediaPositionForUri(props.uri)(state),
|
playbackPosition: makeSelectContentPositionForUri(props.uri)(state),
|
||||||
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
|
autoplay: makeSelectClientSetting(settings.AUTOPLAY)(state),
|
||||||
searchBarFocused: selectSearchBarFocused(state),
|
searchBarFocused: selectSearchBarFocused(state),
|
||||||
fileInfoErrors: selectFileInfoErrors(state),
|
fileInfoErrors: selectFileInfoErrors(state),
|
||||||
|
@ -45,8 +44,8 @@ const perform = dispatch => ({
|
||||||
changeVolume: volume => dispatch(doChangeVolume(volume)),
|
changeVolume: volume => dispatch(doChangeVolume(volume)),
|
||||||
doPlay: () => dispatch(doPlay()),
|
doPlay: () => dispatch(doPlay()),
|
||||||
doPause: () => dispatch(doPause()),
|
doPause: () => dispatch(doPause()),
|
||||||
savePosition: (claimId, position) => dispatch(savePosition(claimId, position)),
|
savePosition: (claimId, outpoint, position) =>
|
||||||
claimRewards: () => dispatch(doClaimEligiblePurchaseRewards()),
|
dispatch(savePosition(claimId, outpoint, position)),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
@ -90,7 +90,11 @@ class MediaPlayer extends React.PureComponent {
|
||||||
mediaElement.addEventListener('play', () => this.props.doPlay());
|
mediaElement.addEventListener('play', () => this.props.doPlay());
|
||||||
mediaElement.addEventListener('pause', () => this.props.doPause());
|
mediaElement.addEventListener('pause', () => this.props.doPause());
|
||||||
mediaElement.addEventListener('timeupdate', () =>
|
mediaElement.addEventListener('timeupdate', () =>
|
||||||
this.props.savePosition(claim.claim_id, mediaElement.currentTime)
|
this.props.savePosition(
|
||||||
|
claim.claim_id,
|
||||||
|
`${claim.txid}:${claim.nout}`,
|
||||||
|
mediaElement.currentTime
|
||||||
|
)
|
||||||
);
|
);
|
||||||
mediaElement.addEventListener('click', this.togglePlayListener);
|
mediaElement.addEventListener('click', this.togglePlayListener);
|
||||||
mediaElement.addEventListener('loadedmetadata', loadedMetadata.bind(this), {
|
mediaElement.addEventListener('loadedmetadata', loadedMetadata.bind(this), {
|
||||||
|
|
|
@ -36,9 +36,9 @@ type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
doPlay: () => void,
|
doPlay: () => void,
|
||||||
doPause: () => void,
|
doPause: () => void,
|
||||||
savePosition: (string, number) => void,
|
savePosition: (string, string, number) => void,
|
||||||
mediaPaused: boolean,
|
mediaPaused: boolean,
|
||||||
mediaPosition: ?number,
|
playbackPosition: ?number,
|
||||||
className: ?string,
|
className: ?string,
|
||||||
obscureNsfw: boolean,
|
obscureNsfw: boolean,
|
||||||
play: string => void,
|
play: string => void,
|
||||||
|
@ -206,7 +206,7 @@ class FileViewer extends React.PureComponent<Props> {
|
||||||
doPause,
|
doPause,
|
||||||
savePosition,
|
savePosition,
|
||||||
mediaPaused,
|
mediaPaused,
|
||||||
mediaPosition,
|
playbackPosition,
|
||||||
className,
|
className,
|
||||||
obscureNsfw,
|
obscureNsfw,
|
||||||
mediaType,
|
mediaType,
|
||||||
|
@ -257,8 +257,7 @@ class FileViewer extends React.PureComponent<Props> {
|
||||||
claim={claim}
|
claim={claim}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
paused={mediaPaused}
|
paused={mediaPaused}
|
||||||
position={mediaPosition}
|
position={playbackPosition}
|
||||||
startedPlayingCb={this.startedPlayingCb}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -74,6 +74,7 @@ export const PUBLISH_STARTED = 'PUBLISH_STARTED';
|
||||||
export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED';
|
export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED';
|
||||||
export const PUBLISH_FAILED = 'PUBLISH_FAILED';
|
export const PUBLISH_FAILED = 'PUBLISH_FAILED';
|
||||||
export const SET_PLAYING_URI = 'PLAY_URI';
|
export const SET_PLAYING_URI = 'PLAY_URI';
|
||||||
|
export const SET_CONTENT_POSITION = 'SET_CONTENT_POSITION';
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
export const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
export const FILE_LIST_STARTED = 'FILE_LIST_STARTED';
|
||||||
|
@ -187,7 +188,6 @@ export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE';
|
||||||
// Media controls
|
// Media controls
|
||||||
export const MEDIA_PLAY = 'MEDIA_PLAY';
|
export const MEDIA_PLAY = 'MEDIA_PLAY';
|
||||||
export const MEDIA_PAUSE = 'MEDIA_PAUSE';
|
export const MEDIA_PAUSE = 'MEDIA_PAUSE';
|
||||||
export const MEDIA_POSITION = 'MEDIA_POSITION';
|
|
||||||
|
|
||||||
// Publishing
|
// Publishing
|
||||||
export const CLEAR_PUBLISH = 'CLEAR_PUBLISH';
|
export const CLEAR_PUBLISH = 'CLEAR_PUBLISH';
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import * as NOTIFICATION_TYPES from 'constants/notification_types';
|
import * as NOTIFICATION_TYPES from 'constants/notification_types';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import Lbryio from 'lbryio';
|
import Lbryio from 'lbryio';
|
||||||
|
@ -494,3 +495,12 @@ export function doPublish(params) {
|
||||||
Lbry.publishDeprecated(params, null, success, failure);
|
Lbry.publishDeprecated(params, null, success, failure);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function savePosition(claimId: string, outpoint: string, position: number) {
|
||||||
|
return dispatch => {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.SET_CONTENT_POSITION,
|
||||||
|
data: { claimId, outpoint, position },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -11,18 +11,3 @@ export const doPause = () => (dispatch: Dispatch) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: actions.MEDIA_PAUSE,
|
type: actions.MEDIA_PAUSE,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function savePosition(claimId: String, position: Number) {
|
|
||||||
return function(dispatch: Dispatch, getState: Function) {
|
|
||||||
const state = getState();
|
|
||||||
const claim = state.claims.byId[claimId];
|
|
||||||
const outpoint = `${claim.txid}:${claim.nout}`;
|
|
||||||
dispatch({
|
|
||||||
type: actions.MEDIA_POSITION,
|
|
||||||
data: {
|
|
||||||
outpoint,
|
|
||||||
position,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ const defaultState = {
|
||||||
playingUri: null,
|
playingUri: null,
|
||||||
rewardedContentClaimIds: [],
|
rewardedContentClaimIds: [],
|
||||||
channelClaimCounts: {},
|
channelClaimCounts: {},
|
||||||
|
positions: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state =>
|
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state =>
|
||||||
|
@ -79,6 +80,20 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = (state, action) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
reducers[ACTIONS.SET_CONTENT_POSITION] = (state, action) => {
|
||||||
|
const { claimId, outpoint, position } = action.data;
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
positions: {
|
||||||
|
...state.positions,
|
||||||
|
[claimId]: {
|
||||||
|
...state.positions[claimId],
|
||||||
|
[outpoint]: position,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action) {
|
export default function reducer(state = defaultState, action) {
|
||||||
const handler = reducers[action.type];
|
const handler = reducers[action.type];
|
||||||
if (handler) return handler(state, action);
|
if (handler) return handler(state, action);
|
||||||
|
|
|
@ -4,9 +4,6 @@ import { handleActions } from 'util/redux-utils';
|
||||||
|
|
||||||
export type MediaState = {
|
export type MediaState = {
|
||||||
paused: Boolean,
|
paused: Boolean,
|
||||||
positions: {
|
|
||||||
[string]: number,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Action = any;
|
export type Action = any;
|
||||||
|
@ -25,17 +22,6 @@ export default handleActions(
|
||||||
...state,
|
...state,
|
||||||
paused: true,
|
paused: true,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[actions.MEDIA_POSITION]: (state: MediaState, action: Action) => {
|
|
||||||
const { outpoint, position } = action.data;
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
positions: {
|
|
||||||
...state.positions,
|
|
||||||
[outpoint]: position,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
defaultState
|
defaultState
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { makeSelectClaimForUri } from 'lbry-redux';
|
||||||
|
|
||||||
export const selectState = state => state.content || {};
|
export const selectState = state => state.content || {};
|
||||||
|
|
||||||
|
@ -29,3 +30,10 @@ export const selectRewardContentClaimIds = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.rewardedContentClaimIds
|
state => state.rewardedContentClaimIds
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const makeSelectContentPositionForUri = uri =>
|
||||||
|
createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => {
|
||||||
|
const outpoint = `${claim.txid}:${claim.nout}`;
|
||||||
|
const id = claim.claim_id;
|
||||||
|
return state.positions[id] ? state.positions[id][outpoint] : null;
|
||||||
|
});
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { makeSelectClaimForUri } from 'lbry-redux';
|
|
||||||
|
|
||||||
const selectState = state => state.media || {};
|
const selectState = state => state.media || {};
|
||||||
|
|
||||||
export const selectMediaPaused = createSelector(selectState, state => state.paused);
|
export const selectMediaPaused = createSelector(selectState, state => state.paused);
|
||||||
|
|
||||||
export const makeSelectMediaPositionForUri = uri =>
|
|
||||||
createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => {
|
|
||||||
const outpoint = `${claim.txid}:${claim.nout}`;
|
|
||||||
return state.positions[outpoint] || null;
|
|
||||||
});
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue