@@ -50,6 +50,9 @@ function LocalMedia(opts) {
5050 this . _log = this . logger . log . bind ( this . logger , 'LocalMedia:' )
5151 this . _logerror = this . logger . error . bind ( this . logger , 'LocalMedia:' )
5252
53+ this . _audioEnabled = true
54+ this . _videoEnabled = true
55+
5356 this . localStreams = [ ]
5457 this . _audioMonitorStreams = [ ]
5558 this . localScreens = [ ]
@@ -156,6 +159,11 @@ LocalMedia.prototype.start = function(mediaConstraints, cb, context) {
156159 self . _audioMonitorStreams . push ( audioMonitorStream )
157160
158161 stream . getTracks ( ) . forEach ( function ( track ) {
162+ if ( ( track . kind === 'audio' && ! self . _audioEnabled )
163+ || ( track . kind === 'video' && ! self . _videoEnabled ) ) {
164+ track . enabled = false
165+ }
166+
159167 track . addEventListener ( 'ended' , function ( ) {
160168 if ( isAllTracksEnded ( stream ) ) {
161169 self . _removeStream ( stream )
@@ -290,6 +298,10 @@ LocalMedia.prototype._handleAudioInputIdChanged = function(mediaDevicesManager,
290298 this . _setupAudioMonitor ( audioMonitorStream , this . config . harkOptions )
291299 }
292300
301+ if ( ! this . _audioEnabled ) {
302+ clonedTrack . enabled = false
303+ }
304+
293305 clonedTrack . addEventListener ( 'ended' , ( ) => {
294306 if ( isAllTracksEnded ( stream ) ) {
295307 this . _removeStream ( stream )
@@ -406,6 +418,10 @@ LocalMedia.prototype._handleVideoInputIdChanged = function(mediaDevicesManager,
406418
407419 stream . addTrack ( clonedTrack )
408420
421+ if ( ! this . _videoEnabled ) {
422+ clonedTrack . enabled = false
423+ }
424+
409425 clonedTrack . addEventListener ( 'ended' , ( ) => {
410426 if ( isAllTracksEnded ( stream ) ) {
411427 this . _removeStream ( stream )
@@ -530,11 +546,11 @@ LocalMedia.prototype.unmute = function() {
530546
531547// Video controls
532548LocalMedia . prototype . pauseVideo = function ( ) {
533- this . _videoEnabled ( false )
549+ this . _setVideoEnabled ( false )
534550 this . emit ( 'videoOff' )
535551}
536552LocalMedia . prototype . resumeVideo = function ( ) {
537- this . _videoEnabled ( true )
553+ this . _setVideoEnabled ( true )
538554 this . emit ( 'videoOn' )
539555}
540556
@@ -558,7 +574,9 @@ LocalMedia.prototype._setAudioEnabled = function(bool) {
558574 } )
559575 } )
560576}
561- LocalMedia . prototype . _videoEnabled = function ( bool ) {
577+ LocalMedia . prototype . _setVideoEnabled = function ( bool ) {
578+ this . _videoEnabled = bool
579+
562580 this . localStreams . forEach ( function ( stream ) {
563581 stream . getVideoTracks ( ) . forEach ( function ( track ) {
564582 track . enabled = ! ! bool
0 commit comments