You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2026-01-03 23:22:30 +03:00
Add the same for video
This commit is contained in:
@@ -259,6 +259,33 @@ MatrixCall.prototype.hangup = function(reason, suppressEvent) {
|
||||
sendEvent(this, 'm.call.hangup', content);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the local video preview should be muted or not.
|
||||
* @param {boolean} muted True to mute the local video.
|
||||
*/
|
||||
MatrixCall.prototype.setLocalVideoMuted = function(muted) {
|
||||
if (!this.localAVStream) {
|
||||
return;
|
||||
}
|
||||
setTracksEnabled(this.localAVStream.getVideoTracks(), !muted);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if local video is muted.
|
||||
*
|
||||
* If there are multiple video tracks, <i>all</i> of the tracks need to be muted
|
||||
* for this to return true. This means if there are no video tracks, this will
|
||||
* return true.
|
||||
* @return {Boolean} True if the local preview video is muted, else false
|
||||
* (including if the call is not set up yet).
|
||||
*/
|
||||
MatrixCall.prototype.isLocalVideoMuted = function(muted) {
|
||||
if (!this.localAVStream) {
|
||||
return false;
|
||||
}
|
||||
return !isTracksEnabled(this.localAVStream.getVideoTracks());
|
||||
};
|
||||
|
||||
/**
|
||||
* Set whether the microphone should be muted or not.
|
||||
* @param {boolean} muted True to mute the mic.
|
||||
@@ -267,7 +294,7 @@ MatrixCall.prototype.setMicrophoneMuted = function(muted) {
|
||||
if (!this.localAVStream) {
|
||||
return;
|
||||
}
|
||||
setAudioTracksEnabled(this.localAVStream, !muted);
|
||||
setTracksEnabled(this.localAVStream.getAudioTracks(), !muted);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -283,13 +310,7 @@ MatrixCall.prototype.isMicrophoneMuted = function(muted) {
|
||||
if (!this.localAVStream) {
|
||||
return false;
|
||||
}
|
||||
var audioTracks = this.localAVStream.getAudioTracks();
|
||||
for (var i = 0; i < audioTracks.length; i++) {
|
||||
if (audioTracks[i].enabled) {
|
||||
return false; // track is enabled; so mic is not muted
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return !isTracksEnabled(this.localAVStream.getAudioTracks());
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -321,7 +342,7 @@ MatrixCall.prototype._gotUserMediaForInvite = function(stream) {
|
||||
}
|
||||
|
||||
this.localAVStream = stream;
|
||||
setAudioTracksEnabled(stream, true);
|
||||
setTracksEnabled(stream.getAudioTracks(), true);
|
||||
this.peerConn = _createPeerConnection(this);
|
||||
this.peerConn.addStream(stream);
|
||||
this.peerConn.createOffer(
|
||||
@@ -356,7 +377,7 @@ MatrixCall.prototype._gotUserMediaForAnswer = function(stream) {
|
||||
}
|
||||
|
||||
self.localAVStream = stream;
|
||||
setAudioTracksEnabled(stream, true);
|
||||
setTracksEnabled(stream.getAudioTracks(), true);
|
||||
self.peerConn.addStream(stream);
|
||||
|
||||
var constraints = {
|
||||
@@ -658,13 +679,21 @@ 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 setTracksEnabled = function(tracks, enabled) {
|
||||
for (var i = 0; i < tracks.length; i++) {
|
||||
tracks[i].enabled = enabled;
|
||||
}
|
||||
};
|
||||
|
||||
var isTracksEnabled = function(tracks) {
|
||||
for (var i = 0; i < tracks.length; i++) {
|
||||
if (tracks[i].enabled) {
|
||||
return true; // at least one track is enabled
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var setState = function(self, state) {
|
||||
var oldState = self.state;
|
||||
self.state = state;
|
||||
|
||||
Reference in New Issue
Block a user