add bitrate switcher. (#15)

This commit is contained in:
Miroslav Šedivý
2022-11-07 19:40:36 +01:00
committed by GitHub
parent ba931ea52e
commit b27b8e028d
6 changed files with 25 additions and 8 deletions

View File

@ -164,12 +164,16 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
this._reconnector.webrtc.config = this._state.webrtc.config
}
public setVideo(video: string) {
if (!this._state.webrtc.videos.includes(video)) {
public setVideo(video: string, bitrate: number = 0) {
if (video != '' && !this._state.webrtc.videos.includes(video)) {
throw new Error('video id not found')
}
this.websocket.send(EVENT.SIGNAL_VIDEO, { video })
if (video == '' && bitrate == 0) {
throw new Error('video id and bitrate cannot be empty')
}
this.websocket.send(EVENT.SIGNAL_VIDEO, { video, bitrate })
}
public getLogger(scope?: string): Logger {

View File

@ -194,9 +194,10 @@ export class NekoMessages extends EventEmitter<NekoEvents> {
this.emit('connection.webrtc.sdp.candidate', 'remote', candidate)
}
protected [EVENT.SIGNAL_VIDEO]({ video }: message.SignalVideo) {
this._localLog.debug(`EVENT.SIGNAL_VIDEO`, { video })
protected [EVENT.SIGNAL_VIDEO]({ video, bitrate }: message.SignalVideo) {
this._localLog.debug(`EVENT.SIGNAL_VIDEO`, { video, bitrate })
Vue.set(this._state.connection.webrtc, 'video', video)
Vue.set(this._state.connection.webrtc, 'bitrate', bitrate)
}
protected [EVENT.SIGNAL_CLOSE]() {

View File

@ -154,6 +154,7 @@
},
stats: null,
video: null,
bitrate: null,
videos: [],
},
screencast: true, // TODO: Should get by API call.
@ -417,8 +418,8 @@
this.connection.websocket.send(EVENT.SCREEN_SET, { width, height, rate })
}
public setWebRTCVideo(video: string) {
this.connection.setVideo(video)
public setWebRTCVideo(video: string, bitrate: number = 0) {
this.connection.setVideo(video, bitrate)
}
public addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender {

View File

@ -56,6 +56,7 @@ export interface SignalDescription {
export interface SignalVideo {
video: string
bitrate: number
}
/////////////////////////////

View File

@ -38,6 +38,7 @@ export interface WebRTC {
config: ReconnectorConfig
stats: WebRTCStats | null
video: string | null
bitrate: number | null
videos: string[]
}