Skip to content

Commit

Permalink
Merge pull request #846 from howardchung/quality
Browse files Browse the repository at this point in the history
ui changes for quality/bitrate
  • Loading branch information
howardchung authored Mar 18, 2024
2 parents 6bd383b + 1bc2fee commit 3affa88
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
46 changes: 46 additions & 0 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ interface AppState {
isErrorAuth: boolean;
settings: Settings;
vBrowserResolution: string;
vBrowserQuality: string;
isVBrowserLarge: boolean;
nonPlayableMedia: boolean;
currentTab: string;
Expand Down Expand Up @@ -189,6 +190,7 @@ export default class App extends React.Component<AppProps, AppState> {
isErrorAuth: false,
settings: {},
vBrowserResolution: '1280x720@30',
vBrowserQuality: '1',
isVBrowserLarge: false,
nonPlayableMedia: false,
currentTab:
Expand Down Expand Up @@ -431,6 +433,7 @@ export default class App extends React.Component<AppProps, AppState> {
nonPlayableMedia: false,
isVBrowserLarge: data.isVBrowserLarge,
vBrowserResolution: '1280x720@30',
vBrowserQuality: '1',
controller: data.controller,
isLiveHls: false,
},
Expand Down Expand Up @@ -2276,6 +2279,45 @@ export default class App extends React.Component<AppProps, AppState> {
]}
></Dropdown>
)}
{this.playingVBrowser() && (
<Dropdown
icon="chart area"
labeled
className="icon"
style={{ height: '36px' }}
button
disabled={!this.haveLock()}
value={this.state.vBrowserQuality}
onChange={(_e, data) => {
this.setState({
vBrowserQuality: data.value as string,
});
}}
selection
options={[
{
text: 'Eco',
value: '0.25',
},
{
text: 'Low',
value: '0.5',
},
{
text: 'Standard',
value: '1',
},
{
text: 'High',
value: '1.5',
},
{
text: 'Ultra',
value: '2',
},
]}
></Dropdown>
)}
{this.playingVBrowser() && (
<Button
fluid
Expand Down Expand Up @@ -2401,10 +2443,14 @@ export default class App extends React.Component<AppProps, AppState> {
hostname={this.getVBrowserHost()}
controlling={this.state.controller === this.socket.id}
resolution={this.state.vBrowserResolution}
quality={this.state.vBrowserQuality}
doPlay={this.localPlay}
setResolution={(data: string) =>
this.setState({ vBrowserResolution: data })
}
setQuality={(data: string) => {
this.setState({ vBrowserQuality: data });
}}
/>
) : (
<video
Expand Down
19 changes: 15 additions & 4 deletions src/components/VBrowser/VBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class VBrowser extends React.Component<{
controlling: boolean;
resolution: string;
setResolution: (resolution: string) => void;
quality: string;
setQuality: (quality: string) => void;
doPlay: () => Promise<void>;
}> {
// private observer = new ResizeObserver(this.onResize);
Expand Down Expand Up @@ -58,6 +60,7 @@ export default class VBrowser extends React.Component<{
this.rate = data.rate;
// Update our state with the resolution sent from server
this.props.setResolution(`${this.width}x${this.height}@${this.rate}`);
this.props.setQuality(String(data.quality));
});
this.$client.on(EVENT.TRACK, async (track: MediaStreamTrack, stream) => {
// console.log(track, streams);
Expand Down Expand Up @@ -124,8 +127,11 @@ export default class VBrowser extends React.Component<{
if (this.props.controlling && !prevProps.controlling) {
this.takeControl();
}
if (this.props.resolution !== prevProps.resolution) {
this.changeResolution(this.props.resolution);
if (
this.props.resolution !== prevProps.resolution ||
(this.props.quality && this.props.quality !== prevProps.quality)
) {
this.changeResolution(this.props.resolution, this.props.quality);
}
}

Expand All @@ -145,12 +151,17 @@ export default class VBrowser extends React.Component<{
}
};

changeResolution = (resString: string) => {
changeResolution = (resString: string, quality: string) => {
const split = resString.split(/x|@/);
const width = Number(split[0]);
const height = Number(split[1]);
const rate = Number(split[2]);
this.$client.sendMessage(EVENT.SCREEN.SET, { width, height, rate });
this.$client.sendMessage(EVENT.SCREEN.SET, {
width,
height,
rate,
quality: Number(quality),
});
};

onClipboardChanged(clipboard: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/VBrowser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export class NekoClient extends BaseClient implements EventEmitter<any> {
width,
height,
rate,
quality,
}: ScreenResolutionPayload) {
this.emit(EVENT.SCREEN.RESOLUTION, { width, height, rate });
this.emit(EVENT.SCREEN.RESOLUTION, { width, height, rate, quality });
}
}

Expand Down
1 change: 1 addition & 0 deletions src/components/VBrowser/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface ScreenResolution {
width: number;
height: number;
rate: number;
quality: number;
}

0 comments on commit 3affa88

Please sign in to comment.