Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Content progression (#2500)
* playhead tracking * pulling play history working. * adjust on end.
- Loading branch information
Showing
8 changed files
with
174 additions
and
23 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
packages/apollos-ui-connected/src/ApollosPlayerConnected/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { useCallback } from 'react'; | ||
import { useQuery, useMutation } from '@apollo/client'; | ||
import PropTypes from 'prop-types'; | ||
import { ApollosPlayerContainer } from '@apollosproject/ui-media-player'; | ||
import { named } from '@apollosproject/ui-kit/src/theme'; | ||
import { useTrack } from '@apollosproject/ui-analytics'; | ||
import { GET_MEDIA } from '../NodeSingleConnected'; | ||
import INTERACT_WITH_NODE from './interactWithNode'; | ||
|
||
const Noop = () => null; | ||
|
||
const ApollosPlayerConnected = ({ | ||
nodeId, | ||
Component, | ||
audioOnly, | ||
mediaSource, | ||
...props | ||
}) => { | ||
const [interactWithVideo] = useMutation(INTERACT_WITH_NODE); | ||
|
||
const track = useTrack(); | ||
|
||
const { data } = useQuery(GET_MEDIA, { | ||
variables: { nodeId }, | ||
fetchPolicy: 'cache-and-network', | ||
}); | ||
|
||
const handleOnPlay = useCallback( | ||
({ id, elapsedTime, title }) => { | ||
interactWithVideo({ | ||
variables: { | ||
nodeId: id, | ||
action: 'VIEW', | ||
data: { field: 'progress', value: elapsedTime }, | ||
}, | ||
}); | ||
track({ | ||
eventName: 'Video Play', | ||
properties: { | ||
videoId: id, | ||
videoTitle: title, | ||
}, | ||
}); | ||
}, | ||
[interactWithVideo, track] | ||
); | ||
const handleOnPause = useCallback( | ||
({ id, elapsedTime, title }) => { | ||
interactWithVideo({ | ||
variables: { | ||
nodeId: id, | ||
action: 'VIEW', | ||
data: { field: 'progress', value: elapsedTime }, | ||
}, | ||
}); | ||
track({ | ||
eventName: 'Video Pause', | ||
properties: { | ||
videoId: id, | ||
videoTitle: title, | ||
}, | ||
}); | ||
}, | ||
[interactWithVideo, track] | ||
); | ||
const handleOnEnd = useCallback( | ||
({ id, elapsedTime, title }) => { | ||
interactWithVideo({ | ||
variables: { | ||
nodeId: id, | ||
action: 'VIEW', | ||
data: { field: 'progress', value: elapsedTime }, | ||
}, | ||
}); | ||
track({ | ||
eventName: 'Video End', | ||
properties: { | ||
videoId: id, | ||
videoTitle: title, | ||
}, | ||
}); | ||
}, | ||
[interactWithVideo, track] | ||
); | ||
|
||
return ( | ||
<ApollosPlayerContainer | ||
source={mediaSource} | ||
coverImage={data.node?.coverImage?.sources} | ||
presentationProps={{ | ||
title: data?.node?.title, | ||
}} | ||
audioOnly={audioOnly} | ||
videos={data?.node?.videos} | ||
onPlay={handleOnPlay} | ||
onPause={handleOnPause} | ||
onEnd={handleOnEnd} | ||
playheadStart={data?.node?.videos[0]?.userProgress?.playhead} | ||
{...props} | ||
> | ||
<Component nodeId={nodeId} ImageWrapperComponent={Noop} {...props} /> | ||
</ApollosPlayerContainer> | ||
); | ||
}; | ||
|
||
ApollosPlayerConnected.propTypes = { | ||
nodeId: PropTypes.string, | ||
Component: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), | ||
audioOnly: PropTypes.bool, | ||
// eslint-disable-next-line react/forbid-prop-types | ||
mediaSource: PropTypes.object, | ||
}; | ||
|
||
export default named('ui-connected.ApollosPlayerConnected')( | ||
ApollosPlayerConnected | ||
); |
13 changes: 13 additions & 0 deletions
13
packages/apollos-ui-connected/src/ApollosPlayerConnected/interactWithNode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export default gql` | ||
mutation interactWithNode( | ||
$nodeId: ID! | ||
$action: InteractionAction! | ||
$data: [InteractionDataField] | ||
) { | ||
interactWithNode(nodeId: $nodeId, action: $action, data: $data) { | ||
success | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters