This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Maintain aspect ratio on Desktop Playback #635
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1504f2d
Maintains aspect ratio on playback. Opportunistically moves ProgressB…
857be49
Adds an indicator that's displayed while the player is loading, and l…
f463705
alternative implementation which uses id
1d8a553
Merge branch 'master' into isaiah/maintain-aspect-ratio
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
84 changes: 84 additions & 0 deletions
84
packages/teleport/src/Player/ProgressBar/ProgressBarDesktop.tsx
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,84 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import { throttle } from 'lodash'; | ||
import { dateToUtc } from 'shared/services/loc'; | ||
import { format } from 'date-fns'; | ||
|
||
import { PlayerClient, PlayerClientEvent } from 'teleport/lib/tdp'; | ||
|
||
import ProgressBar from './ProgressBar'; | ||
|
||
export const ProgressBarDesktop = (props: { | ||
playerClient: PlayerClient; | ||
durationMs: number; | ||
style?: React.CSSProperties; | ||
id?: string; | ||
}) => { | ||
const { playerClient, durationMs } = props; | ||
|
||
const toHuman = (currentMs: number) => { | ||
return format(dateToUtc(new Date(currentMs)), 'mm:ss'); | ||
}; | ||
|
||
const [state, setState] = useState({ | ||
max: durationMs, | ||
min: 0, | ||
current: 0, // the recording always starts at 0 ms | ||
time: toHuman(0), | ||
isPlaying: true, // determines whether play or pause symbol is shown | ||
}); | ||
|
||
useEffect(() => { | ||
playerClient.addListener(PlayerClientEvent.TOGGLE_PLAY_PAUSE, () => { | ||
// setState({...state, isPlaying: !state.isPlaying}) doesn't work because | ||
// the listener is added when state == initialState, and that initialState | ||
// value is effectively hardcoded into its logic. | ||
setState(prevState => { | ||
return { ...prevState, isPlaying: !prevState.isPlaying }; | ||
}); | ||
}); | ||
|
||
const throttledUpdateCurrentTime = throttle( | ||
currentTimeMs => { | ||
setState(prevState => { | ||
return { | ||
...prevState, | ||
current: currentTimeMs, | ||
time: toHuman(currentTimeMs), | ||
}; | ||
}); | ||
}, | ||
// Magic number to throttle progress bar updates so that the playback is smoother. | ||
50 | ||
); | ||
|
||
playerClient.addListener( | ||
PlayerClientEvent.UPDATE_CURRENT_TIME, | ||
currentTimeMs => throttledUpdateCurrentTime(currentTimeMs) | ||
); | ||
|
||
playerClient.addListener(PlayerClientEvent.SESSION_END, () => { | ||
throttledUpdateCurrentTime.cancel(); | ||
// TODO(isaiah): Make this smoother | ||
// https://github.com/gravitational/webapps/issues/579 | ||
setState(prevState => { | ||
return { ...prevState, current: durationMs }; | ||
}); | ||
}); | ||
|
||
return () => { | ||
throttledUpdateCurrentTime.cancel(); | ||
playerClient.nuke(); | ||
}; | ||
}, [playerClient]); | ||
|
||
return ( | ||
<ProgressBar | ||
{...state} | ||
toggle={() => playerClient.togglePlayPause()} | ||
move={() => {}} | ||
style={props.style} | ||
id={props.id} | ||
/> | ||
); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to run this logic on every PNG frame? Or can we instead run it once when we initialize the player and (optionally) run it in a window resize handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only being run when we receive the
client screen spec
tdp message, so since we currently don't support a dynamic resize, it just happens once at the beginning. Once we do implement resize, this will also account for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Github's UI confuses me, I looked up and it looked like this was inside
tdpCliOnPngFrame
, but it's not. My eyes always glance over the light blue bars. Sorry!