diff --git a/src/matrix.js b/src/matrix.js index f856174ee..92ba72f34 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -81,6 +81,13 @@ module.exports.IndexedDBCryptoStore = module.exports.createNewMatrixCall = require("./webrtc/call").createNewMatrixCall; +/** + * Set an audio output device to use for MatrixCalls + * @function + * @param {string=} deviceId the identifier for the device + * undefined treated as unset + */ +module.exports.setMatrixCallAudioOutput = require('./webrtc/call').setAudioOutput; /** * Set an audio input device to use for MatrixCalls * @function diff --git a/src/webrtc/call.js b/src/webrtc/call.js index 413631d42..3611c49c1 100644 --- a/src/webrtc/call.js +++ b/src/webrtc/call.js @@ -1121,9 +1121,13 @@ const _tryPlayRemoteStream = function(self) { } }; -const _tryPlayRemoteAudioStream = function(self) { +const _tryPlayRemoteAudioStream = async function(self) { if (self.getRemoteAudioElement() && self.remoteAStream) { const player = self.getRemoteAudioElement(); + + // if audioOutput is non-default: + if (audioOutput) await player.setSinkId(audioOutput); + player.autoplay = true; self.assignElement(player, self.remoteAStream, "remoteAudio"); setTimeout(function() { @@ -1317,8 +1321,16 @@ const forAllTracksOnStream = function(s, f) { /** The MatrixCall class. */ module.exports.MatrixCall = MatrixCall; +let audioOutput; let audioInput; let videoInput; +/** + * Set an audio output device to use for MatrixCalls + * @function + * @param {string=} deviceId the identifier for the device + * undefined treated as unset + */ +module.exports.setAudioOutput = function(deviceId) { audioOutput = deviceId; }; /** * Set an audio input device to use for MatrixCalls * @function