From d8c43d02ba2c6985169524bd93dc21ea3a72cdd1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 19 Oct 2015 16:21:13 +0100 Subject: [PATCH] Add MatrixCall.setMicrophoneMuted --- lib/webrtc/call.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/webrtc/call.js b/lib/webrtc/call.js index 84edace08..94b602222 100644 --- a/lib/webrtc/call.js +++ b/lib/webrtc/call.js @@ -259,6 +259,17 @@ MatrixCall.prototype.hangup = function(reason, suppressEvent) { sendEvent(this, 'm.call.hangup', content); }; +/** + * Set whether the microphone should be muted or not. + * @param {boolean} muted True to mute the mic. + */ +MatrixCall.prototype.setMicrophoneMuted = function(muted) { + if (!this.localAVStream) { + return; + } + setAudioTracksEnabled(this.localAVStream, !muted); +}; + /** * Internal * @private @@ -288,10 +299,7 @@ MatrixCall.prototype._gotUserMediaForInvite = function(stream) { } this.localAVStream = stream; - var audioTracks = stream.getAudioTracks(); - for (var i = 0; i < audioTracks.length; i++) { - audioTracks[i].enabled = true; - } + setAudioTracksEnabled(stream, true); this.peerConn = _createPeerConnection(this); this.peerConn.addStream(stream); this.peerConn.createOffer( @@ -326,10 +334,7 @@ MatrixCall.prototype._gotUserMediaForAnswer = function(stream) { } self.localAVStream = stream; - var audioTracks = stream.getAudioTracks(); - for (var i = 0; i < audioTracks.length; i++) { - audioTracks[i].enabled = true; - } + setAudioTracksEnabled(stream, true); self.peerConn.addStream(stream); var constraints = { @@ -631,6 +636,13 @@ MatrixCall.prototype._onAnsweredElsewhere = function(msg) { terminate(this, "remote", "answered_elsewhere", true); }; +var setAudioTracksEnabled = function(stream, enabled) { + var audioTracks = stream.getAudioTracks(); + for (var i = 0; i < audioTracks.length; i++) { + audioTracks[i].enabled = enabled; + } +}; + var setState = function(self, state) { var oldState = self.state; self.state = state;