Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/utils/webrtc/simplewebrtc/localmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function LocalMedia(opts) {
this._log = this.logger.log.bind(this.logger, 'LocalMedia:')
this._logerror = this.logger.error.bind(this.logger, 'LocalMedia:')

this._audioEnabled = true
this._videoEnabled = true

this.localStreams = []
this._audioMonitorStreams = []
this.localScreens = []
Expand Down Expand Up @@ -156,6 +159,11 @@ LocalMedia.prototype.start = function(mediaConstraints, cb, context) {
self._audioMonitorStreams.push(audioMonitorStream)

stream.getTracks().forEach(function(track) {
if ((track.kind === 'audio' && !self._audioEnabled)
|| (track.kind === 'video' && !self._videoEnabled)) {
track.enabled = false
}

track.addEventListener('ended', function() {
if (isAllTracksEnded(stream)) {
self._removeStream(stream)
Expand Down Expand Up @@ -290,6 +298,10 @@ LocalMedia.prototype._handleAudioInputIdChanged = function(mediaDevicesManager,
this._setupAudioMonitor(audioMonitorStream, this.config.harkOptions)
}

if (!this._audioEnabled) {
clonedTrack.enabled = false
}

clonedTrack.addEventListener('ended', () => {
if (isAllTracksEnded(stream)) {
this._removeStream(stream)
Expand Down Expand Up @@ -406,6 +418,10 @@ LocalMedia.prototype._handleVideoInputIdChanged = function(mediaDevicesManager,

stream.addTrack(clonedTrack)

if (!this._videoEnabled) {
clonedTrack.enabled = false
}

clonedTrack.addEventListener('ended', () => {
if (isAllTracksEnded(stream)) {
this._removeStream(stream)
Expand Down Expand Up @@ -530,11 +546,11 @@ LocalMedia.prototype.unmute = function() {

// Video controls
LocalMedia.prototype.pauseVideo = function() {
this._videoEnabled(false)
this._setVideoEnabled(false)
this.emit('videoOff')
}
LocalMedia.prototype.resumeVideo = function() {
this._videoEnabled(true)
this._setVideoEnabled(true)
this.emit('videoOn')
}

Expand All @@ -558,7 +574,9 @@ LocalMedia.prototype._setAudioEnabled = function(bool) {
})
})
}
LocalMedia.prototype._videoEnabled = function(bool) {
LocalMedia.prototype._setVideoEnabled = function(bool) {
this._videoEnabled = bool

this.localStreams.forEach(function(stream) {
stream.getVideoTracks().forEach(function(track) {
track.enabled = !!bool
Expand Down
6 changes: 4 additions & 2 deletions src/utils/webrtc/simplewebrtc/simplewebrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ function SimpleWebRTC(opts) {
} else if (message.type === 'control') {
if (message.payload.action === 'forceMute') {
if (message.payload.peerId === self.connection.getSessionId()) {
self.mute()
self.emit('forcedMute')
if (self.webrtc.isAudioEnabled()) {
self.mute()
self.emit('forcedMute')
}
} else {
self.emit('mute', { id: message.payload.peerId })
}
Expand Down