-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(live): adding live ui preset and functionality (#34)
- Loading branch information
Dvir Hazout
committed
Aug 31, 2017
1 parent
7abb9b0
commit 81d9919
Showing
17 changed files
with
296 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.live-tag { | ||
color: $live-color; | ||
font-size: 14px; | ||
font-weight: bold; | ||
letter-spacing: 1px; | ||
line-height: 19px; | ||
border: 2px solid $live-color; | ||
border-radius: 4px; | ||
text-transform: uppercase; | ||
text-align: center; | ||
display: inline-block; | ||
padding: 0 3px 0 5px; | ||
margin: 5px 23px; | ||
cursor: default; | ||
|
||
&.non-live-playhead { | ||
background-color: rgba(255,255,255,0.2); | ||
border: none; | ||
color: #fff; | ||
line-height: 23px; | ||
padding: 0 5px 0 7px; | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 480px) { | ||
.live-tag { | ||
margin-left: 0; | ||
} | ||
} |
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 @@ | ||
export default from './live-tag'; |
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,80 @@ | ||
//@flow | ||
import { h } from 'preact'; | ||
import { connect } from 'preact-redux'; | ||
import BaseComponent from '../base'; | ||
|
||
/** | ||
* mapping state to props | ||
* @param {*} state - redux store state | ||
* @returns {Object} - mapped state to this component | ||
*/ | ||
const mapStateToProps = state => ({ | ||
isLive: state.engine.isLive, | ||
isDvr: state.engine.isDvr, | ||
currentTime: state.engine.currentTime, | ||
duration: state.engine.duration | ||
}); | ||
|
||
@connect(mapStateToProps) | ||
/** | ||
* LiveTag component | ||
* | ||
* @class LiveTag | ||
* @example <LiveTag player={this.player} /> | ||
* @extends {BaseComponent} | ||
*/ | ||
class LiveTag extends BaseComponent { | ||
|
||
/** | ||
* Creates an instance of LiveTag. | ||
* @param {Object} obj obj | ||
* @memberof LiveTag | ||
*/ | ||
constructor(obj: Object) { | ||
super({name: 'LiveTag', player: obj.player}); | ||
} | ||
|
||
/** | ||
* returns a boolean to detect if player is on live edge with buffer of 1 second | ||
* | ||
* @returns {boolean} - is player on live edge | ||
* @memberof LiveTag | ||
*/ | ||
isOnLiveEdge(): boolean { | ||
return (this.props.currentTime >= this.props.duration - 1); | ||
} | ||
|
||
/** | ||
* click handler to live tag | ||
* if not on live edge, seeking to live edge and if paused, call play method | ||
* | ||
* @returns {void} | ||
* @memberof LiveTag | ||
*/ | ||
onClick(): void { | ||
if (!this.isOnLiveEdge()) { | ||
this.player.seekToLiveEdge(); | ||
if (this.player.paused) { | ||
this.player.play(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* render live tag component | ||
* | ||
* @param {*} props - component props | ||
* @returns {React$Element} component element | ||
* @memberof LiveTag | ||
*/ | ||
render(props: any): React$Element<any> { | ||
var tagStyleClass = 'live-tag'; | ||
if (props.isDvr && !this.isOnLiveEdge()) tagStyleClass += ' non-live-playhead'; | ||
|
||
return ( | ||
<div className={tagStyleClass} onClick={() => this.onClick()}>Live</div> | ||
) | ||
} | ||
} | ||
|
||
export default LiveTag; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './seekbar-live-playback-container'; |
85 changes: 85 additions & 0 deletions
85
src/components/seekbar-live-playback-container/seekbar-live-playback-container.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,85 @@ | ||
//@flow | ||
import { h } from 'preact'; | ||
import { connect } from 'preact-redux'; | ||
import { bindActions } from '../../utils/bind-actions'; | ||
import { actions } from '../../reducers/seekbar'; | ||
import BaseComponent from '../base'; | ||
import SeekBarControl from '../seekbar'; | ||
|
||
/** | ||
* mapping state to props | ||
* @param {*} state - redux store state | ||
* @returns {Object} - mapped state to this component | ||
*/ | ||
const mapStateToProps = state => ({ | ||
currentTime: state.seekbar.currentTime, | ||
duration: state.engine.duration, | ||
isDraggingActive: state.seekbar.draggingActive, | ||
isMobile: state.shell.isMobile, | ||
poster: state.engine.poster, | ||
isDvr: state.engine.isDvr | ||
}); | ||
|
||
@connect(mapStateToProps, bindActions(actions)) | ||
/** | ||
* SeekBarLivePlaybackContainer component | ||
* | ||
* @class SeekBarLivePlaybackContainer | ||
* @example <SeekBarLivePlaybackContainer player={this.player} /> | ||
* @extends {BaseComponent} | ||
*/ | ||
class SeekBarLivePlaybackContainer extends BaseComponent { | ||
|
||
/** | ||
* Creates an instance of SeekBarLivePlaybackContainer. | ||
* @param {Object} obj obj | ||
* @memberof SeekBarLivePlaybackContainer | ||
*/ | ||
constructor(obj: Object) { | ||
super({name: 'SeekBarLivePlaybackContainer', player: obj.player}); | ||
} | ||
|
||
/** | ||
* after component mounted, listen to time update event and if dragging not active, | ||
* update the current time in the store | ||
* | ||
* @returns {void} | ||
* @memberof SeekBarLivePlaybackContainer | ||
*/ | ||
componentDidMount() { | ||
this.player.addEventListener(this.player.Event.TIME_UPDATE, () => { | ||
if (!this.props.isDraggingActive) { | ||
this.props.updateCurrentTime(this.player.currentTime); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* render component | ||
* | ||
* @param {*} props - component props | ||
* @returns {React$Element} - component element | ||
* @memberof SeekBarLivePlaybackContainer | ||
*/ | ||
render(props: any) { | ||
if (!props.isDvr) return undefined; | ||
return ( | ||
<SeekBarControl | ||
playerElement={this.player.getView().parentElement} | ||
showTimeBubble={this.props.showTimeBubble} | ||
changeCurrentTime={time => this.player.currentTime = time} | ||
playerPoster={this.props.poster} | ||
updateSeekbarDraggingStatus={data => this.props.updateSeekbarDraggingStatus(data)} | ||
updateCurrentTime={data => this.props.updateCurrentTime(data)} | ||
|
||
isDvr={this.props.isDvr} | ||
currentTime={this.props.currentTime} | ||
duration={this.props.duration} | ||
isDraggingActive={this.props.isDraggingActive} | ||
isMobile={this.props.isMobile} | ||
/> | ||
) | ||
} | ||
|
||
} | ||
export default SeekBarLivePlaybackContainer; |
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
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
Oops, something went wrong.