You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Remove handling of audio from MatrixCall
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@@ -55,7 +55,6 @@ export * from "./content-repo";
|
|||||||
export * as ContentHelpers from "./content-helpers";
|
export * as ContentHelpers from "./content-helpers";
|
||||||
export {
|
export {
|
||||||
createNewMatrixCall,
|
createNewMatrixCall,
|
||||||
setAudioOutput as setMatrixCallAudioOutput,
|
|
||||||
setAudioInput as setMatrixCallAudioInput,
|
setAudioInput as setMatrixCallAudioInput,
|
||||||
setVideoInput as setMatrixCallVideoInput,
|
setVideoInput as setMatrixCallVideoInput,
|
||||||
} from "./webrtc/call";
|
} from "./webrtc/call";
|
||||||
|
|||||||
@@ -252,7 +252,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
private sentEndOfCandidates: boolean;
|
private sentEndOfCandidates: boolean;
|
||||||
private peerConn: RTCPeerConnection;
|
private peerConn: RTCPeerConnection;
|
||||||
private feeds: Array<CallFeed>;
|
private feeds: Array<CallFeed>;
|
||||||
private remoteAudioElement: HTMLAudioElement;
|
|
||||||
private screenSharingStream: MediaStream;
|
private screenSharingStream: MediaStream;
|
||||||
private remoteStream: MediaStream;
|
private remoteStream: MediaStream;
|
||||||
private localAVStream: MediaStream;
|
private localAVStream: MediaStream;
|
||||||
@@ -435,29 +434,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
this.emit(CallEvent.FeedsChanged, this.feeds);
|
this.emit(CallEvent.FeedsChanged, this.feeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the remote <code><audio></code> DOM element
|
|
||||||
* used for playing back audio only streams.
|
|
||||||
* @return {Element} The dom element
|
|
||||||
*/
|
|
||||||
public getRemoteAudioElement(): HTMLAudioElement {
|
|
||||||
return this.remoteAudioElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the remote <code><audio></code> DOM element. If this call is active,
|
|
||||||
* the first received audio-only stream will be rendered to it immediately.
|
|
||||||
* The audio will *not* be rendered from the remoteVideoElement.
|
|
||||||
* @param {Element} element The <code><video></code> DOM element.
|
|
||||||
*/
|
|
||||||
public async setRemoteAudioElement(element: HTMLAudioElement) {
|
|
||||||
if (element === this.remoteAudioElement) return;
|
|
||||||
|
|
||||||
this.remoteAudioElement = element;
|
|
||||||
|
|
||||||
if (this.remoteStream) this.playRemoteAudio();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The typescript definitions have this type as 'any' :(
|
// The typescript definitions have this type as 'any' :(
|
||||||
public async getCurrentCallStats(): Promise<any[]> {
|
public async getCurrentCallStats(): Promise<any[]> {
|
||||||
if (this.callHasEnded()) {
|
if (this.callHasEnded()) {
|
||||||
@@ -603,7 +579,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
newCall.gotUserMediaForAnswer(this.localAVStream);
|
newCall.gotUserMediaForAnswer(this.localAVStream);
|
||||||
delete(this.localAVStream);
|
delete(this.localAVStream);
|
||||||
}
|
}
|
||||||
newCall.remoteAudioElement = this.remoteAudioElement;
|
|
||||||
this.successor = newCall;
|
this.successor = newCall;
|
||||||
this.emit(CallEvent.Replaced, newCall);
|
this.emit(CallEvent.Replaced, newCall);
|
||||||
this.hangup(CallErrorCode.Replaced, true);
|
this.hangup(CallErrorCode.Replaced, true);
|
||||||
@@ -713,10 +688,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
}
|
}
|
||||||
this.updateMuteStatus();
|
this.updateMuteStatus();
|
||||||
|
|
||||||
if (!onHold) {
|
|
||||||
this.playRemoteAudio();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.emit(CallEvent.RemoteHoldUnhold, this.remoteOnHold);
|
this.emit(CallEvent.RemoteHoldUnhold, this.remoteOnHold);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,14 +741,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
|
|
||||||
const vidShouldBeMuted = this.vidMuted || this.remoteOnHold;
|
const vidShouldBeMuted = this.vidMuted || this.remoteOnHold;
|
||||||
setTracksEnabled(this.localAVStream.getVideoTracks(), !vidShouldBeMuted);
|
setTracksEnabled(this.localAVStream.getVideoTracks(), !vidShouldBeMuted);
|
||||||
|
|
||||||
if (this.remoteOnHold) {
|
|
||||||
if (this.remoteAudioElement && this.remoteAudioElement.srcObject === this.remoteStream) {
|
|
||||||
this.remoteAudioElement.muted = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.playRemoteAudio();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1297,7 +1260,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
logger.debug(`Track id ${ev.track.id} of kind ${ev.track.kind} added`);
|
logger.debug(`Track id ${ev.track.id} of kind ${ev.track.kind} added`);
|
||||||
|
|
||||||
this.pushNewFeed(this.remoteStream, this.getOpponentMember().userId, CallFeedType.Webcam)
|
this.pushNewFeed(this.remoteStream, this.getOpponentMember().userId, CallFeedType.Webcam)
|
||||||
if (this.remoteAudioElement) this.playRemoteAudio();
|
|
||||||
|
|
||||||
logger.info("playing remote. stream active? " + this.remoteStream.active);
|
logger.info("playing remote. stream active? " + this.remoteStream.active);
|
||||||
};
|
};
|
||||||
@@ -1322,31 +1284,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async playRemoteAudio() {
|
|
||||||
this.remoteAudioElement.muted = false;
|
|
||||||
this.remoteAudioElement.srcObject = this.remoteStream;
|
|
||||||
|
|
||||||
// if audioOutput is non-default:
|
|
||||||
try {
|
|
||||||
if (audioOutput) {
|
|
||||||
// This seems quite unreliable in Chrome, although I haven't yet managed to make a jsfiddle where
|
|
||||||
// it fails.
|
|
||||||
// It seems reliable if you set the sink ID after setting the srcObject and then set the sink ID
|
|
||||||
// back to the default after the call is over
|
|
||||||
logger.info("Setting audio sink to " + audioOutput + ", was " + this.remoteAudioElement.sinkId);
|
|
||||||
await this.remoteAudioElement.setSinkId(audioOutput);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
logger.warn("Couldn't set requested audio output device: using default", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.remoteAudioElement.play();
|
|
||||||
} catch (e) {
|
|
||||||
logger.error("Failed to play remote audio element", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onHangupReceived = (msg) => {
|
onHangupReceived = (msg) => {
|
||||||
logger.debug("Hangup received for call ID " + this.callId);
|
logger.debug("Hangup received for call ID " + this.callId);
|
||||||
|
|
||||||
@@ -1463,18 +1400,6 @@ export class MatrixCall extends EventEmitter {
|
|||||||
this.inviteTimeout = null;
|
this.inviteTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const remoteAud = this.getRemoteAudioElement();
|
|
||||||
if (remoteAud) {
|
|
||||||
remoteAud.pause();
|
|
||||||
remoteAud.srcObject = null;
|
|
||||||
try {
|
|
||||||
// As per comment in playRemoteAudio, setting the sink ID back to the default
|
|
||||||
// once the call is over makes setSinkId work reliably.
|
|
||||||
await this.remoteAudioElement.setSinkId('')
|
|
||||||
} catch (e) {
|
|
||||||
logger.warn("Failed to set sink ID back to default");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.deleteAllFeeds();
|
this.deleteAllFeeds();
|
||||||
|
|
||||||
this.hangupParty = hangupParty;
|
this.hangupParty = hangupParty;
|
||||||
@@ -1730,16 +1655,8 @@ async function getScreenshareContraints(selectDesktopCapturerSource?: () => Prom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let audioOutput: string;
|
|
||||||
let audioInput: string;
|
let audioInput: string;
|
||||||
let videoInput: string;
|
let videoInput: string;
|
||||||
/**
|
|
||||||
* Set an audio output device to use for MatrixCalls
|
|
||||||
* @function
|
|
||||||
* @param {string=} deviceId the identifier for the device
|
|
||||||
* undefined treated as unset
|
|
||||||
*/
|
|
||||||
export function setAudioOutput(deviceId: string) { audioOutput = deviceId; }
|
|
||||||
/**
|
/**
|
||||||
* Set an audio input device to use for MatrixCalls
|
* Set an audio input device to use for MatrixCalls
|
||||||
* @function
|
* @function
|
||||||
|
|||||||
Reference in New Issue
Block a user