Add getters to check if media is allowed or disallowed

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2022-03-30 22:28:02 +02:00
Родитель c91ebaae58
Коммит a7a9e8368a
3 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -68,6 +68,14 @@ export default class MediaDevicesSource extends TrackSource {
this._active = false
}
isAudioAllowed() {
return this._audioAllowed
}
isVideoAllowed() {
return this._videoAllowed
}
setAudioAllowed(audioAllowed) {
if (this._audioAllowed === audioAllowed) {
return

Просмотреть файл

@ -161,6 +161,27 @@ describe('MediaDevicesSource', () => {
jest.restoreAllMocks()
})
describe('get allowed state', () => {
test('audio and video are allowed by default', () => {
expect(mediaDevicesSource.isAudioAllowed()).toBe(true)
expect(mediaDevicesSource.isVideoAllowed()).toBe(true)
})
test('after modifying the audio state', () => {
mediaDevicesSource.setAudioAllowed(false)
expect(mediaDevicesSource.isAudioAllowed()).toBe(false)
expect(mediaDevicesSource.isVideoAllowed()).toBe(true)
})
test('after modifying the video state', () => {
mediaDevicesSource.setVideoAllowed(false)
expect(mediaDevicesSource.isAudioAllowed()).toBe(true)
expect(mediaDevicesSource.isVideoAllowed()).toBe(false)
})
})
describe('start', () => {
/**

Просмотреть файл

@ -288,6 +288,10 @@ LocalMedia.prototype.stopScreenShare = function() {
}
// Audio controls
LocalMedia.prototype.isAudioAllowed = function() {
return this._mediaDevicesSource.isAudioAllowed()
}
LocalMedia.prototype.disallowAudio = function() {
this._mediaDevicesSource.setAudioAllowed(false)
this.emit('audioDisallowed')
@ -309,6 +313,10 @@ LocalMedia.prototype.unmute = function() {
}
// Video controls
LocalMedia.prototype.isVideoAllowed = function() {
return this._mediaDevicesSource.isVideoAllowed()
}
LocalMedia.prototype.disallowVideo = function() {
this._mediaDevicesSource.setVideoAllowed(false)
this.emit('videoDisallowed')