2017-09-20 01:47:57 +08:00
|
|
|
import { Tracker } from 'meteor/tracker';
|
2020-12-02 02:24:24 +08:00
|
|
|
|
2017-11-17 19:52:48 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2017-11-18 03:01:52 +08:00
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2017-10-13 03:22:10 +08:00
|
|
|
import SIPBridge from '/imports/api/audio/client/bridge/sip';
|
2022-04-21 04:38:52 +08:00
|
|
|
import SFUAudioBridge from '/imports/api/audio/client/bridge/sfu-audio-bridge';
|
2018-07-12 06:03:56 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2017-10-24 21:19:58 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2019-09-30 22:54:34 +08:00
|
|
|
import playAndRetry from '/imports/utils/mediaElementPlayRetry';
|
2019-11-15 03:07:35 +08:00
|
|
|
import iosWebviewAudioPolyfills from '/imports/utils/ios-webview-audio-polyfills';
|
2019-11-30 05:48:04 +08:00
|
|
|
import { monitorAudioConnection } from '/imports/utils/stats';
|
2019-09-30 22:54:34 +08:00
|
|
|
import AudioErrors from './error-codes';
|
2021-12-10 04:37:05 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2021-07-02 23:51:00 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2021-10-12 04:35:53 +08:00
|
|
|
import getFromMeetingSettings from '/imports/ui/services/meeting-settings';
|
2023-05-10 01:14:31 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2022-04-08 03:45:17 +08:00
|
|
|
import {
|
|
|
|
DEFAULT_INPUT_DEVICE_ID,
|
2022-08-20 01:22:42 +08:00
|
|
|
reloadAudioElement,
|
|
|
|
getCurrentAudioSinkId,
|
|
|
|
getStoredAudioInputDeviceId,
|
|
|
|
storeAudioInputDeviceId,
|
|
|
|
getStoredAudioOutputDeviceId,
|
|
|
|
storeAudioOutputDeviceId,
|
2022-04-08 03:45:17 +08:00
|
|
|
} from '/imports/api/audio/client/bridge/service';
|
2022-08-24 22:36:40 +08:00
|
|
|
import MediaStreamUtils from '/imports/utils/media-stream-utils';
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2020-01-28 21:07:21 +08:00
|
|
|
const STATS = Meteor.settings.public.stats;
|
2017-10-18 03:16:42 +08:00
|
|
|
const MEDIA = Meteor.settings.public.media;
|
2022-08-20 01:22:42 +08:00
|
|
|
const MEDIA_TAG = MEDIA.mediaTag;
|
2017-10-18 03:16:42 +08:00
|
|
|
const ECHO_TEST_NUMBER = MEDIA.echoTestNumber;
|
2018-09-12 01:09:29 +08:00
|
|
|
const MAX_LISTEN_ONLY_RETRIES = 1;
|
2020-09-26 07:11:44 +08:00
|
|
|
const LISTEN_ONLY_CALL_TIMEOUT_MS = MEDIA.listenOnlyCallTimeout || 25000;
|
2021-12-10 04:37:05 +08:00
|
|
|
const EXPERIMENTAL_USE_KMS_TRICKLE_ICE_FOR_MICROPHONE =
|
|
|
|
Meteor.settings.public.app.experimentalUseKmsTrickleIceForMicrophone;
|
2017-10-10 04:48:10 +08:00
|
|
|
|
2021-09-01 02:50:53 +08:00
|
|
|
const DEFAULT_AUDIO_BRIDGES_PATH = '/imports/api/audio/client/';
|
2017-10-10 04:48:10 +08:00
|
|
|
const CALL_STATES = {
|
2017-10-05 04:49:11 +08:00
|
|
|
STARTED: 'started',
|
|
|
|
ENDED: 'ended',
|
|
|
|
FAILED: 'failed',
|
2019-06-13 05:01:20 +08:00
|
|
|
RECONNECTING: 'reconnecting',
|
2019-08-03 05:32:42 +08:00
|
|
|
AUTOPLAY_BLOCKED: 'autoplayBlocked',
|
2017-10-05 04:49:11 +08:00
|
|
|
};
|
2017-09-20 01:47:57 +08:00
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
const BREAKOUT_AUDIO_TRANSFER_STATES = {
|
|
|
|
CONNECTED: 'connected',
|
|
|
|
DISCONNECTED: 'disconnected',
|
|
|
|
RETURNING: 'returning',
|
|
|
|
};
|
|
|
|
|
2021-08-13 03:39:04 +08:00
|
|
|
/**
|
|
|
|
* Audio status to be filtered in getStats()
|
|
|
|
*/
|
|
|
|
const FILTER_AUDIO_STATS = [
|
|
|
|
'outbound-rtp',
|
|
|
|
'inbound-rtp',
|
2021-08-26 03:27:46 +08:00
|
|
|
'candidate-pair',
|
|
|
|
'local-candidate',
|
|
|
|
'transport',
|
2021-08-13 03:39:04 +08:00
|
|
|
];
|
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
class AudioManager {
|
|
|
|
constructor() {
|
2017-09-30 04:42:34 +08:00
|
|
|
this._inputDevice = {
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
value: DEFAULT_INPUT_DEVICE_ID,
|
2017-10-11 02:03:29 +08:00
|
|
|
tracker: new Tracker.Dependency(),
|
2017-09-30 04:42:34 +08:00
|
|
|
};
|
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
this._breakoutAudioTransferStatus = {
|
|
|
|
status: BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
|
|
|
breakoutMeetingId: null,
|
|
|
|
};
|
2021-02-26 02:36:11 +08:00
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
this.defineProperties({
|
|
|
|
isMuted: false,
|
|
|
|
isConnected: false,
|
|
|
|
isConnecting: false,
|
2017-10-27 01:14:56 +08:00
|
|
|
isHangingUp: false,
|
2017-09-29 21:38:10 +08:00
|
|
|
isListenOnly: false,
|
|
|
|
isEchoTest: false,
|
2018-06-20 23:36:26 +08:00
|
|
|
isTalking: false,
|
2017-11-09 02:41:15 +08:00
|
|
|
isWaitingPermissions: false,
|
2017-09-20 01:47:57 +08:00
|
|
|
error: null,
|
2018-01-16 23:56:31 +08:00
|
|
|
muteHandle: null,
|
2019-08-03 05:32:42 +08:00
|
|
|
autoplayBlocked: false,
|
2021-02-27 02:05:17 +08:00
|
|
|
isReconnecting: false,
|
2017-09-20 01:47:57 +08:00
|
|
|
});
|
2018-09-12 01:09:29 +08:00
|
|
|
|
2019-08-03 05:32:42 +08:00
|
|
|
this.failedMediaElements = [];
|
|
|
|
this.handlePlayElementFailed = this.handlePlayElementFailed.bind(this);
|
2019-11-30 05:48:04 +08:00
|
|
|
this.monitor = this.monitor.bind(this);
|
2021-03-07 09:09:43 +08:00
|
|
|
|
2021-04-16 21:45:40 +08:00
|
|
|
this._inputStream = null;
|
|
|
|
this._inputStreamTracker = new Tracker.Dependency();
|
2022-08-20 01:22:42 +08:00
|
|
|
this._inputDeviceId = {
|
|
|
|
value: getStoredAudioInputDeviceId() || DEFAULT_INPUT_DEVICE_ID,
|
|
|
|
tracker: new Tracker.Dependency(),
|
|
|
|
};
|
|
|
|
this._outputDeviceId = {
|
2022-08-24 22:36:40 +08:00
|
|
|
value: getCurrentAudioSinkId(),
|
2022-08-20 01:22:42 +08:00
|
|
|
tracker: new Tracker.Dependency(),
|
|
|
|
};
|
2021-04-16 21:45:40 +08:00
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
this.BREAKOUT_AUDIO_TRANSFER_STATES = BREAKOUT_AUDIO_TRANSFER_STATES;
|
2022-08-20 01:22:42 +08:00
|
|
|
this._applyCachedOutputDeviceId();
|
|
|
|
}
|
|
|
|
|
|
|
|
_applyCachedOutputDeviceId() {
|
|
|
|
const cachedId = getStoredAudioOutputDeviceId();
|
|
|
|
|
|
|
|
if (typeof cachedId === 'string') {
|
|
|
|
this.changeOutputDevice(cachedId, false).then(() => {
|
|
|
|
this.outputDeviceId = cachedId;
|
|
|
|
}).catch((error) => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'audiomanager_output_device_storage_failed',
|
|
|
|
extraInfo: {
|
|
|
|
deviceId: cachedId,
|
|
|
|
errorMessage: error.message,
|
|
|
|
},
|
|
|
|
}, `Failed to apply output audio device from storage: ${error.message}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set inputDeviceId(value) {
|
|
|
|
if (this._inputDeviceId.value !== value) {
|
|
|
|
this._inputDeviceId.value = value;
|
|
|
|
this._inputDeviceId.tracker.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.fullAudioBridge) {
|
|
|
|
this.fullAudioBridge.inputDeviceId = this._inputDeviceId.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get inputDeviceId() {
|
|
|
|
this._inputDeviceId.tracker.depend();
|
|
|
|
return this._inputDeviceId.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set outputDeviceId(value) {
|
|
|
|
if (this._outputDeviceId.value !== value) {
|
|
|
|
this._outputDeviceId.value = value;
|
|
|
|
this._outputDeviceId.tracker.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.fullAudioBridge) {
|
|
|
|
this.fullAudioBridge.outputDeviceId = this._outputDeviceId.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.listenOnlyBridge) {
|
|
|
|
this.listenOnlyBridge.outputDeviceId = this._outputDeviceId.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get outputDeviceId() {
|
|
|
|
this._outputDeviceId.tracker.depend();
|
|
|
|
return this._outputDeviceId.value;
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2021-11-10 02:04:10 +08:00
|
|
|
async init(userData, audioEventHandler) {
|
2021-09-01 02:50:53 +08:00
|
|
|
this.loadBridges(userData);
|
2017-10-18 03:16:42 +08:00
|
|
|
this.userData = userData;
|
2017-11-18 03:01:52 +08:00
|
|
|
this.initialized = true;
|
2021-02-12 10:55:34 +08:00
|
|
|
this.audioEventHandler = audioEventHandler;
|
2021-11-10 02:04:10 +08:00
|
|
|
await this.loadBridges(userData);
|
2017-10-18 03:16:42 +08:00
|
|
|
}
|
2018-12-22 01:14:05 +08:00
|
|
|
|
2021-09-01 02:50:53 +08:00
|
|
|
/**
|
|
|
|
* Load audio bridges modules to be used the manager.
|
|
|
|
*
|
|
|
|
* Bridges can be configured in settings.yml file.
|
|
|
|
* @param {Object} userData The Object representing user data to be passed to
|
|
|
|
* the bridge.
|
|
|
|
*/
|
2021-09-09 03:24:15 +08:00
|
|
|
async loadBridges(userData) {
|
2021-09-01 02:50:53 +08:00
|
|
|
let FullAudioBridge = SIPBridge;
|
2022-04-21 04:38:52 +08:00
|
|
|
let ListenOnlyBridge = SFUAudioBridge;
|
2021-09-01 02:50:53 +08:00
|
|
|
|
|
|
|
if (MEDIA.audio) {
|
2022-04-21 04:38:52 +08:00
|
|
|
const { bridges, defaultFullAudioBridge, defaultListenOnlyBridge } = MEDIA.audio;
|
2021-09-01 02:50:53 +08:00
|
|
|
|
2023-05-10 01:14:31 +08:00
|
|
|
const _fullAudioBridge = getFromUserSettings(
|
|
|
|
'bbb_fullaudio_bridge',
|
|
|
|
getFromMeetingSettings('fullaudio-bridge', defaultFullAudioBridge),
|
2021-10-12 04:35:53 +08:00
|
|
|
);
|
|
|
|
|
2021-09-01 02:50:53 +08:00
|
|
|
this.bridges = {};
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
await Promise.all(
|
|
|
|
Object.values(bridges).map(async (bridge) => {
|
|
|
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
|
|
this.bridges[bridge.name] = (
|
|
|
|
(await import(DEFAULT_AUDIO_BRIDGES_PATH + bridge.path)) || {}
|
|
|
|
).default;
|
|
|
|
})
|
|
|
|
);
|
2021-09-01 02:50:53 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
if (_fullAudioBridge && this.bridges[_fullAudioBridge]) {
|
2021-10-12 04:35:53 +08:00
|
|
|
FullAudioBridge = this.bridges[_fullAudioBridge];
|
2021-09-01 02:50:53 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
if (defaultListenOnlyBridge && this.bridges[defaultListenOnlyBridge]) {
|
2021-09-01 02:50:53 +08:00
|
|
|
ListenOnlyBridge = this.bridges[defaultListenOnlyBridge];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
this.fullAudioBridge = new FullAudioBridge(userData);
|
|
|
|
this.listenOnlyBridge = new ListenOnlyBridge(userData);
|
2022-08-20 01:22:42 +08:00
|
|
|
// Initialize device IDs in configured bridges
|
|
|
|
this.fullAudioBridge.inputDeviceId = this.inputDeviceId;
|
|
|
|
this.fullAudioBridge.outputDeviceId = this.outputDeviceId;
|
|
|
|
this.listenOnlyBridge.outputDeviceId = this.outputDeviceId;
|
2021-09-01 02:50:53 +08:00
|
|
|
}
|
|
|
|
|
2019-02-21 05:58:37 +08:00
|
|
|
setAudioMessages(messages, intl) {
|
2018-04-20 03:57:54 +08:00
|
|
|
this.messages = messages;
|
2019-02-21 05:58:37 +08:00
|
|
|
this.intl = intl;
|
2018-04-20 03:57:54 +08:00
|
|
|
}
|
2017-10-18 03:16:42 +08:00
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
defineProperties(obj) {
|
2017-09-29 21:38:10 +08:00
|
|
|
Object.keys(obj).forEach((key) => {
|
|
|
|
const privateKey = `_${key}`;
|
|
|
|
this[privateKey] = {
|
2017-09-20 01:47:57 +08:00
|
|
|
value: obj[key],
|
2017-10-11 02:03:29 +08:00
|
|
|
tracker: new Tracker.Dependency(),
|
2017-09-29 21:38:10 +08:00
|
|
|
};
|
2017-09-20 01:47:57 +08:00
|
|
|
|
|
|
|
Object.defineProperty(this, key, {
|
|
|
|
set: (value) => {
|
2017-09-29 21:38:10 +08:00
|
|
|
this[privateKey].value = value;
|
|
|
|
this[privateKey].tracker.changed();
|
2017-09-20 01:47:57 +08:00
|
|
|
},
|
|
|
|
get: () => {
|
2017-09-29 21:38:10 +08:00
|
|
|
this[privateKey].tracker.depend();
|
|
|
|
return this[privateKey].value;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2021-06-30 01:47:59 +08:00
|
|
|
async trickleIce() {
|
2021-07-02 23:51:00 +08:00
|
|
|
const { isFirefox, isIe, isSafari } = browserInfo;
|
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
if (!this.listenOnlyBridge
|
|
|
|
|| typeof this.listenOnlyBridge.trickleIce !== 'function'
|
|
|
|
|| isFirefox
|
|
|
|
|| isIe
|
|
|
|
|| isSafari) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-06-30 01:47:59 +08:00
|
|
|
|
|
|
|
if (this.validIceCandidates && this.validIceCandidates.length) {
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{ logCode: 'audiomanager_trickle_ice_reuse_candidate' },
|
2022-04-26 00:34:39 +08:00
|
|
|
'Reusing trickle ICE information before activating microphone',
|
2021-12-10 04:37:05 +08:00
|
|
|
);
|
2021-06-30 01:47:59 +08:00
|
|
|
return this.validIceCandidates;
|
|
|
|
}
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{ logCode: 'audiomanager_trickle_ice_get_local_candidate' },
|
2022-04-26 00:34:39 +08:00
|
|
|
'Performing trickle ICE before activating microphone',
|
2021-12-10 04:37:05 +08:00
|
|
|
);
|
2022-04-26 00:34:39 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
this.validIceCandidates = await this.listenOnlyBridge.trickleIce();
|
|
|
|
return this.validIceCandidates;
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'audiomanager_trickle_ice_failed',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
},
|
|
|
|
}, `Trickle ICE before activating microphone failed: ${error.message}`);
|
|
|
|
return [];
|
|
|
|
}
|
2021-06-30 01:47:59 +08:00
|
|
|
}
|
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
joinMicrophone() {
|
2021-06-30 01:47:59 +08:00
|
|
|
this.audioJoinStartTime = new Date();
|
|
|
|
this.logAudioJoinTime = false;
|
2018-03-16 02:57:25 +08:00
|
|
|
this.isListenOnly = false;
|
|
|
|
this.isEchoTest = false;
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
return this.onAudioJoining
|
|
|
|
.bind(this)()
|
2019-06-13 05:01:20 +08:00
|
|
|
.then(() => {
|
|
|
|
const callOptions = {
|
|
|
|
isListenOnly: false,
|
|
|
|
extension: null,
|
|
|
|
inputStream: this.inputStream,
|
|
|
|
};
|
2020-09-26 07:11:44 +08:00
|
|
|
return this.joinAudio(callOptions, this.callStateCallback.bind(this));
|
2019-06-13 05:01:20 +08:00
|
|
|
});
|
2018-03-16 02:57:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
joinEchoTest() {
|
2021-06-30 01:47:59 +08:00
|
|
|
this.audioJoinStartTime = new Date();
|
|
|
|
this.logAudioJoinTime = false;
|
2018-03-16 02:57:25 +08:00
|
|
|
this.isListenOnly = false;
|
|
|
|
this.isEchoTest = true;
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
return this.onAudioJoining
|
|
|
|
.bind(this)()
|
2021-06-30 01:47:59 +08:00
|
|
|
.then(async () => {
|
2021-07-02 23:51:00 +08:00
|
|
|
let validIceCandidates = [];
|
|
|
|
if (EXPERIMENTAL_USE_KMS_TRICKLE_ICE_FOR_MICROPHONE) {
|
|
|
|
validIceCandidates = await this.trickleIce();
|
|
|
|
}
|
|
|
|
|
2019-06-13 05:01:20 +08:00
|
|
|
const callOptions = {
|
|
|
|
isListenOnly: false,
|
|
|
|
extension: ECHO_TEST_NUMBER,
|
|
|
|
inputStream: this.inputStream,
|
2021-06-30 01:47:59 +08:00
|
|
|
validIceCandidates,
|
2019-06-13 05:01:20 +08:00
|
|
|
};
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_join_echotest',
|
|
|
|
extraInfo: { logType: 'user_action' },
|
|
|
|
},
|
|
|
|
'User requested to join audio conference with mic'
|
|
|
|
);
|
2020-09-26 07:11:44 +08:00
|
|
|
return this.joinAudio(callOptions, this.callStateCallback.bind(this));
|
2019-06-13 05:01:20 +08:00
|
|
|
});
|
2018-03-16 02:57:25 +08:00
|
|
|
}
|
|
|
|
|
2020-09-26 07:11:44 +08:00
|
|
|
joinAudio(callOptions, callStateCallback) {
|
2021-12-10 04:37:05 +08:00
|
|
|
return this.bridge
|
|
|
|
.joinAudio(callOptions, callStateCallback.bind(this))
|
|
|
|
.catch((error) => {
|
|
|
|
const { name } = error;
|
2020-09-26 07:11:44 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
if (!name) {
|
|
|
|
throw error;
|
|
|
|
}
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
switch (name) {
|
|
|
|
case 'NotAllowedError':
|
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_error_getting_device',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
`Error getting microphone - {${error.name}: ${error.message}}`
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'NotFoundError':
|
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_error_device_not_found',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
`Error getting microphone - {${error.name}: ${error.message}}`
|
|
|
|
);
|
|
|
|
break;
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
this.isConnecting = false;
|
|
|
|
this.isWaitingPermissions = false;
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
throw {
|
|
|
|
type: 'MEDIA_ERROR',
|
|
|
|
};
|
|
|
|
});
|
2020-09-26 07:11:44 +08:00
|
|
|
}
|
|
|
|
|
2019-07-26 02:41:24 +08:00
|
|
|
async joinListenOnly(r = 0) {
|
2021-06-30 01:47:59 +08:00
|
|
|
this.audioJoinStartTime = new Date();
|
|
|
|
this.logAudioJoinTime = false;
|
2019-07-26 02:41:24 +08:00
|
|
|
let retries = r;
|
2018-03-16 02:57:25 +08:00
|
|
|
this.isListenOnly = true;
|
|
|
|
this.isEchoTest = false;
|
2019-06-13 05:01:20 +08:00
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
const callOptions = {
|
|
|
|
isListenOnly: true,
|
|
|
|
extension: null,
|
|
|
|
};
|
|
|
|
|
2018-12-22 01:14:05 +08:00
|
|
|
// Call polyfills for webrtc client if navigator is "iOS Webview"
|
|
|
|
const userAgent = window.navigator.userAgent.toLocaleLowerCase();
|
2021-12-10 04:37:05 +08:00
|
|
|
if (
|
|
|
|
(userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipad') > -1) &&
|
|
|
|
userAgent.indexOf('safari') === -1
|
|
|
|
) {
|
2018-12-22 01:14:05 +08:00
|
|
|
iosWebviewAudioPolyfills();
|
|
|
|
}
|
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
// We need this until we upgrade to SIP 9x. See #4690
|
2022-04-21 04:38:52 +08:00
|
|
|
const listenOnlyCallTimeoutErr = 'SIP_CALL_TIMEOUT';
|
2019-12-03 06:15:46 +08:00
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
const iceGatheringTimeout = new Promise((resolve, reject) => {
|
2019-12-03 06:15:46 +08:00
|
|
|
setTimeout(reject, LISTEN_ONLY_CALL_TIMEOUT_MS, listenOnlyCallTimeoutErr);
|
2018-03-16 02:57:25 +08:00
|
|
|
});
|
|
|
|
|
2019-12-03 06:15:46 +08:00
|
|
|
const handleListenOnlyError = (err) => {
|
2018-09-12 01:09:29 +08:00
|
|
|
if (iceGatheringTimeout) {
|
|
|
|
clearTimeout(iceGatheringTimeout);
|
|
|
|
}
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
const errorReason =
|
|
|
|
(typeof err === 'string' ? err : undefined) ||
|
|
|
|
err.errorReason ||
|
|
|
|
err.errorMessage;
|
2019-12-03 06:15:46 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_listenonly_error',
|
|
|
|
extraInfo: {
|
|
|
|
errorReason,
|
2022-04-21 04:38:52 +08:00
|
|
|
audioBridge: this.bridge?.bridgeName,
|
2021-12-10 04:37:05 +08:00
|
|
|
retries,
|
|
|
|
},
|
2019-06-29 05:45:50 +08:00
|
|
|
},
|
2022-04-21 04:38:52 +08:00
|
|
|
`Listen only error - ${errorReason} - bridge: ${this.bridge?.bridgeName}`
|
2021-12-10 04:37:05 +08:00
|
|
|
);
|
2018-11-14 01:14:30 +08:00
|
|
|
};
|
2018-09-12 01:09:29 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_join_listenonly',
|
|
|
|
extraInfo: { logType: 'user_action' },
|
|
|
|
},
|
|
|
|
'user requested to connect to audio conference as listen only'
|
|
|
|
);
|
2019-07-26 02:41:24 +08:00
|
|
|
|
2019-08-03 05:32:42 +08:00
|
|
|
window.addEventListener('audioPlayFailed', this.handlePlayElementFailed);
|
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
return this.onAudioJoining()
|
2021-12-10 04:37:05 +08:00
|
|
|
.then(() =>
|
|
|
|
Promise.race([
|
2022-04-21 04:38:52 +08:00
|
|
|
this.bridge.joinAudio(callOptions, this.callStateCallback.bind(this)),
|
2021-12-10 04:37:05 +08:00
|
|
|
iceGatheringTimeout,
|
|
|
|
])
|
|
|
|
)
|
2018-09-12 01:09:29 +08:00
|
|
|
.catch(async (err) => {
|
2019-12-03 06:15:46 +08:00
|
|
|
handleListenOnlyError(err);
|
|
|
|
|
2018-10-04 02:39:55 +08:00
|
|
|
if (retries < MAX_LISTEN_ONLY_RETRIES) {
|
2019-12-03 06:15:46 +08:00
|
|
|
retries += 1;
|
|
|
|
this.joinListenOnly(retries);
|
2018-03-16 02:57:25 +08:00
|
|
|
}
|
2019-07-26 02:41:24 +08:00
|
|
|
|
|
|
|
return null;
|
2017-11-02 20:10:01 +08:00
|
|
|
});
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2018-03-16 02:57:25 +08:00
|
|
|
onAudioJoining() {
|
|
|
|
this.isConnecting = true;
|
|
|
|
this.isMuted = false;
|
|
|
|
this.error = false;
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
exitAudio() {
|
2017-11-02 20:10:01 +08:00
|
|
|
if (!this.isConnected) return Promise.resolve();
|
|
|
|
|
2017-10-27 01:14:56 +08:00
|
|
|
this.isHangingUp = true;
|
2018-06-28 01:44:11 +08:00
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
return this.bridge.exitAudio();
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2021-12-03 19:45:07 +08:00
|
|
|
forceExitAudio() {
|
|
|
|
this.isConnected = false;
|
|
|
|
this.isConnecting = false;
|
|
|
|
this.isHangingUp = false;
|
|
|
|
|
|
|
|
if (this.inputStream) {
|
|
|
|
this.inputStream.getTracks().forEach((track) => track.stop());
|
|
|
|
this.inputStream = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.removeEventListener('audioPlayFailed', this.handlePlayElementFailed);
|
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
return this.bridge.exitAudio();
|
2021-12-03 19:45:07 +08:00
|
|
|
}
|
|
|
|
|
2017-10-12 20:50:23 +08:00
|
|
|
transferCall() {
|
2017-10-18 03:16:42 +08:00
|
|
|
this.onTransferStart();
|
|
|
|
return this.bridge.transferCall(this.onAudioJoin.bind(this));
|
2017-10-12 20:50:23 +08:00
|
|
|
}
|
|
|
|
|
2020-08-27 05:23:01 +08:00
|
|
|
onVoiceUserChanges(fields) {
|
|
|
|
if (fields.muted !== undefined && fields.muted !== this.isMuted) {
|
2020-09-10 01:03:27 +08:00
|
|
|
let muteState;
|
2020-08-27 05:23:01 +08:00
|
|
|
this.isMuted = fields.muted;
|
2020-09-10 01:03:27 +08:00
|
|
|
|
|
|
|
if (this.isMuted) {
|
|
|
|
muteState = 'selfMuted';
|
|
|
|
this.mute();
|
|
|
|
} else {
|
|
|
|
muteState = 'selfUnmuted';
|
|
|
|
this.unmute();
|
|
|
|
}
|
2020-08-27 05:23:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fields.talking !== undefined && fields.talking !== this.isTalking) {
|
|
|
|
this.isTalking = fields.talking;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isMuted) {
|
|
|
|
this.isTalking = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
onAudioJoin() {
|
|
|
|
this.isConnecting = false;
|
2017-10-19 03:40:01 +08:00
|
|
|
this.isConnected = true;
|
2017-10-20 18:11:51 +08:00
|
|
|
|
2018-01-16 05:01:57 +08:00
|
|
|
// listen to the VoiceUsers changes and update the flag
|
2018-03-16 02:57:25 +08:00
|
|
|
if (!this.muteHandle) {
|
2021-12-10 04:37:05 +08:00
|
|
|
const query = VoiceUsers.find(
|
|
|
|
{ intId: Auth.userID },
|
|
|
|
{ fields: { muted: 1, talking: 1 } }
|
|
|
|
);
|
2018-01-16 05:13:18 +08:00
|
|
|
this.muteHandle = query.observeChanges({
|
2020-08-27 05:23:01 +08:00
|
|
|
added: (id, fields) => this.onVoiceUserChanges(fields),
|
|
|
|
changed: (id, fields) => this.onVoiceUserChanges(fields),
|
2018-01-16 05:01:57 +08:00
|
|
|
});
|
|
|
|
}
|
2021-12-10 04:37:05 +08:00
|
|
|
const secondsToActivateAudio =
|
|
|
|
(new Date() - this.audioJoinStartTime) / 1000;
|
2021-06-30 01:47:59 +08:00
|
|
|
|
|
|
|
if (!this.logAudioJoinTime) {
|
|
|
|
this.logAudioJoinTime = true;
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'audio_mic_join_time',
|
|
|
|
extraInfo: {
|
|
|
|
secondsToActivateAudio,
|
|
|
|
},
|
2021-07-10 00:43:43 +08:00
|
|
|
},
|
2021-12-10 04:37:05 +08:00
|
|
|
`Time needed to connect audio (seconds): ${secondsToActivateAudio}`
|
|
|
|
);
|
2021-06-30 01:47:59 +08:00
|
|
|
}
|
2018-01-16 05:01:57 +08:00
|
|
|
|
2017-10-20 18:11:51 +08:00
|
|
|
if (!this.isEchoTest) {
|
2019-02-21 05:58:37 +08:00
|
|
|
this.notify(this.intl.formatMessage(this.messages.info.JOINED_AUDIO));
|
|
|
|
logger.info({ logCode: 'audio_joined' }, 'Audio Joined');
|
2021-12-10 04:37:05 +08:00
|
|
|
this.inputStream = this.bridge ? this.bridge.inputStream : null;
|
2020-01-28 21:07:21 +08:00
|
|
|
if (STATS.enabled) this.monitor();
|
2021-02-27 02:52:11 +08:00
|
|
|
this.audioEventHandler({
|
|
|
|
name: 'started',
|
|
|
|
isListenOnly: this.isListenOnly,
|
|
|
|
});
|
2017-10-20 18:11:51 +08:00
|
|
|
}
|
2021-04-13 02:59:43 +08:00
|
|
|
Session.set('audioModalIsOpen', false);
|
2022-08-20 01:22:42 +08:00
|
|
|
|
|
|
|
// Enforce correct output device on audio join
|
|
|
|
this.changeOutputDevice(this.outputDeviceId, true);
|
2022-08-24 22:36:40 +08:00
|
|
|
storeAudioOutputDeviceId(this.outputDeviceId);
|
|
|
|
|
|
|
|
// Extract the deviceId again from the stream to guarantee consistency
|
|
|
|
// between stream DID vs chosen DID. That's necessary in scenarios where,
|
|
|
|
// eg, there's no default/pre-set deviceId ('') and the browser's
|
|
|
|
// default device has been altered by the user (browser default != system's
|
|
|
|
// default).
|
|
|
|
if (this.inputStream) {
|
|
|
|
const extractedDeviceId = MediaStreamUtils.extractDeviceIdFromStream(this.inputStream, 'audio');
|
|
|
|
if (extractedDeviceId && extractedDeviceId !== this.inputDeviceId) {
|
|
|
|
this.changeInputDevice(extractedDeviceId);
|
|
|
|
}
|
|
|
|
}
|
2022-08-20 01:22:42 +08:00
|
|
|
// Audio joined successfully - add device IDs to session storage so they
|
|
|
|
// can be re-used on refreshes/other sessions
|
|
|
|
storeAudioInputDeviceId(this.inputDeviceId);
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2017-10-12 20:50:23 +08:00
|
|
|
onTransferStart() {
|
|
|
|
this.isEchoTest = false;
|
|
|
|
this.isConnecting = true;
|
|
|
|
}
|
|
|
|
|
2017-09-20 01:47:57 +08:00
|
|
|
onAudioExit() {
|
|
|
|
this.isConnected = false;
|
2017-10-05 04:49:11 +08:00
|
|
|
this.isConnecting = false;
|
2017-10-27 01:14:56 +08:00
|
|
|
this.isHangingUp = false;
|
2019-08-03 05:32:42 +08:00
|
|
|
this.autoplayBlocked = false;
|
|
|
|
this.failedMediaElements = [];
|
2017-09-29 21:38:10 +08:00
|
|
|
|
2018-04-18 01:09:05 +08:00
|
|
|
if (this.inputStream) {
|
2021-04-16 21:45:40 +08:00
|
|
|
this.inputStream.getTracks().forEach((track) => track.stop());
|
|
|
|
this.inputStream = null;
|
2018-04-18 01:09:05 +08:00
|
|
|
}
|
2018-04-13 20:39:26 +08:00
|
|
|
|
2017-10-20 18:11:51 +08:00
|
|
|
if (!this.error && !this.isEchoTest) {
|
2021-10-19 04:26:01 +08:00
|
|
|
this.notify(
|
|
|
|
this.intl.formatMessage(this.messages.info.LEFT_AUDIO),
|
|
|
|
false,
|
|
|
|
'no_audio'
|
|
|
|
);
|
2017-09-29 21:38:10 +08:00
|
|
|
}
|
2019-06-13 05:01:20 +08:00
|
|
|
if (!this.isEchoTest) {
|
|
|
|
this.playHangUpSound();
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:32:42 +08:00
|
|
|
window.removeEventListener('audioPlayFailed', this.handlePlayElementFailed);
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
2017-10-05 04:49:11 +08:00
|
|
|
callStateCallback(response) {
|
2017-09-29 21:38:10 +08:00
|
|
|
return new Promise((resolve) => {
|
2021-12-10 04:37:05 +08:00
|
|
|
const { STARTED, ENDED, FAILED, RECONNECTING, AUTOPLAY_BLOCKED } =
|
|
|
|
CALL_STATES;
|
|
|
|
|
|
|
|
const { status, error, bridgeError, silenceNotifications, bridge } =
|
|
|
|
response;
|
2017-10-05 04:49:11 +08:00
|
|
|
|
|
|
|
if (status === STARTED) {
|
2021-02-27 02:05:17 +08:00
|
|
|
this.isReconnecting = false;
|
2017-09-29 21:38:10 +08:00
|
|
|
this.onAudioJoin();
|
2017-10-05 04:49:11 +08:00
|
|
|
resolve(STARTED);
|
|
|
|
} else if (status === ENDED) {
|
2021-02-27 02:05:17 +08:00
|
|
|
this.isReconnecting = false;
|
2021-03-09 01:51:03 +08:00
|
|
|
this.setBreakoutAudioTransferStatus({
|
|
|
|
breakoutMeetingId: '',
|
|
|
|
status: BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
|
|
|
});
|
2019-06-05 02:16:43 +08:00
|
|
|
logger.info({ logCode: 'audio_ended' }, 'Audio ended without issue');
|
2017-09-29 21:38:10 +08:00
|
|
|
this.onAudioExit();
|
2017-10-05 04:49:11 +08:00
|
|
|
} else if (status === FAILED) {
|
2021-02-27 02:05:17 +08:00
|
|
|
this.isReconnecting = false;
|
2021-03-09 01:51:03 +08:00
|
|
|
this.setBreakoutAudioTransferStatus({
|
|
|
|
breakoutMeetingId: '',
|
|
|
|
status: BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
2021-12-10 04:37:05 +08:00
|
|
|
});
|
|
|
|
const errorKey =
|
|
|
|
this.messages.error[error] || this.messages.error.GENERIC_ERROR;
|
2019-02-21 05:58:37 +08:00
|
|
|
const errorMsg = this.intl.formatMessage(errorKey, { 0: bridgeError });
|
|
|
|
this.error = !!error;
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'audio_failure',
|
|
|
|
extraInfo: {
|
|
|
|
errorCode: error,
|
|
|
|
cause: bridgeError,
|
|
|
|
bridge,
|
|
|
|
},
|
2019-06-29 05:45:50 +08:00
|
|
|
},
|
2021-12-10 04:37:05 +08:00
|
|
|
`Audio error - errorCode=${error}, cause=${bridgeError}`
|
|
|
|
);
|
2019-06-13 05:01:20 +08:00
|
|
|
if (silenceNotifications !== true) {
|
|
|
|
this.notify(errorMsg, true);
|
|
|
|
this.exitAudio();
|
|
|
|
this.onAudioExit();
|
|
|
|
}
|
|
|
|
} else if (status === RECONNECTING) {
|
2021-02-27 02:05:17 +08:00
|
|
|
this.isReconnecting = true;
|
2021-03-09 01:51:03 +08:00
|
|
|
this.setBreakoutAudioTransferStatus({
|
|
|
|
breakoutMeetingId: '',
|
|
|
|
status: BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
2021-12-10 04:37:05 +08:00
|
|
|
});
|
|
|
|
logger.info(
|
|
|
|
{ logCode: 'audio_reconnecting' },
|
|
|
|
'Attempting to reconnect audio'
|
|
|
|
);
|
|
|
|
this.notify(
|
|
|
|
this.intl.formatMessage(this.messages.info.RECONNECTING_AUDIO),
|
|
|
|
true
|
|
|
|
);
|
2019-06-13 05:01:20 +08:00
|
|
|
this.playHangUpSound();
|
2019-08-03 05:32:42 +08:00
|
|
|
} else if (status === AUTOPLAY_BLOCKED) {
|
2021-03-09 01:51:03 +08:00
|
|
|
this.setBreakoutAudioTransferStatus({
|
|
|
|
breakoutMeetingId: '',
|
|
|
|
status: BREAKOUT_AUDIO_TRANSFER_STATES.DISCONNECTED,
|
2021-12-10 04:37:05 +08:00
|
|
|
});
|
2021-02-27 02:05:17 +08:00
|
|
|
this.isReconnecting = false;
|
2019-08-03 05:32:42 +08:00
|
|
|
this.autoplayBlocked = true;
|
|
|
|
this.onAudioJoin();
|
|
|
|
resolve(AUTOPLAY_BLOCKED);
|
2017-09-29 21:38:10 +08:00
|
|
|
}
|
2017-10-11 20:05:57 +08:00
|
|
|
});
|
2017-09-29 21:38:10 +08:00
|
|
|
}
|
|
|
|
|
2018-06-20 23:36:26 +08:00
|
|
|
isUsingAudio() {
|
2021-12-10 04:37:05 +08:00
|
|
|
return (
|
|
|
|
this.isConnected ||
|
|
|
|
this.isConnecting ||
|
|
|
|
this.isHangingUp ||
|
|
|
|
this.isEchoTest
|
|
|
|
);
|
2018-06-20 23:36:26 +08:00
|
|
|
}
|
|
|
|
|
2017-11-02 20:10:01 +08:00
|
|
|
changeInputDevice(deviceId) {
|
2022-08-20 01:22:42 +08:00
|
|
|
if (typeof deviceId !== 'string') throw new TypeError('Invalid inputDeviceId');
|
2019-09-27 21:52:29 +08:00
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
if (deviceId === this.inputDeviceId) return this.inputDeviceId;
|
2019-09-27 21:52:29 +08:00
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
const currentDeviceId = this.inputDeviceId ?? 'none';
|
|
|
|
this.inputDeviceId = deviceId;
|
|
|
|
logger.debug({
|
|
|
|
logCode: 'audiomanager_input_device_change',
|
|
|
|
extraInfo: {
|
|
|
|
deviceId: currentDeviceId,
|
|
|
|
newDeviceId: deviceId,
|
|
|
|
},
|
|
|
|
}, `Microphone input device changed: from ${currentDeviceId} to ${deviceId}`);
|
2017-11-02 20:10:01 +08:00
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
return this.inputDeviceId;
|
2017-10-18 03:16:42 +08:00
|
|
|
}
|
2017-09-30 04:42:34 +08:00
|
|
|
|
2020-07-28 03:49:26 +08:00
|
|
|
liveChangeInputDevice(deviceId) {
|
2022-08-20 01:22:42 +08:00
|
|
|
const currentDeviceId = this.inputDeviceId ?? 'none';
|
2021-04-16 21:45:40 +08:00
|
|
|
// we force stream to be null, so MutedAlert will deallocate it and
|
|
|
|
// a new one will be created for the new stream
|
|
|
|
this.inputStream = null;
|
2022-08-20 01:22:42 +08:00
|
|
|
return this.bridge.liveChangeInputDevice(deviceId).then((stream) => {
|
2022-09-16 01:48:26 +08:00
|
|
|
this.inputStream = stream;
|
|
|
|
const extractedDeviceId = MediaStreamUtils.extractDeviceIdFromStream(this.inputStream, 'audio');
|
|
|
|
if (extractedDeviceId && extractedDeviceId !== this.inputDeviceId) {
|
|
|
|
this.changeInputDevice(extractedDeviceId);
|
|
|
|
}
|
2022-08-20 01:22:42 +08:00
|
|
|
// Live input device change - add device ID to session storage so it
|
|
|
|
// can be re-used on refreshes/other sessions
|
2022-09-16 01:48:26 +08:00
|
|
|
storeAudioInputDeviceId(extractedDeviceId);
|
|
|
|
this.setSenderTrackEnabled(!this.isMuted);
|
2022-08-19 04:41:18 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
logger.error({
|
2022-08-20 01:22:42 +08:00
|
|
|
logCode: 'audiomanager_input_live_device_change_failure',
|
2022-08-19 04:41:18 +08:00
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
deviceId: currentDeviceId,
|
2022-08-20 01:22:42 +08:00
|
|
|
newDeviceId: deviceId,
|
2022-08-19 04:41:18 +08:00
|
|
|
},
|
2022-08-20 01:22:42 +08:00
|
|
|
}, `Input device live change failed - {${error.name}: ${error.message}}`);
|
2022-08-19 04:41:18 +08:00
|
|
|
|
|
|
|
throw error;
|
|
|
|
});
|
2017-09-30 04:42:34 +08:00
|
|
|
}
|
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
async changeOutputDevice(deviceId, isLive) {
|
|
|
|
const targetDeviceId = deviceId;
|
|
|
|
const currentDeviceId = this.outputDeviceId ?? getCurrentAudioSinkId();
|
|
|
|
const audioElement = document.querySelector(MEDIA_TAG);
|
|
|
|
const sinkIdSupported = audioElement && typeof audioElement.setSinkId === 'function';
|
|
|
|
|
|
|
|
if (typeof deviceId === 'string' && sinkIdSupported && currentDeviceId !== targetDeviceId) {
|
|
|
|
try {
|
|
|
|
if (!isLive) audioElement.srcObject = null;
|
|
|
|
|
|
|
|
await audioElement.setSinkId(deviceId);
|
|
|
|
reloadAudioElement(audioElement);
|
|
|
|
logger.debug({
|
|
|
|
logCode: 'audiomanager_output_device_change',
|
|
|
|
extraInfo: {
|
|
|
|
deviceId: currentDeviceId,
|
|
|
|
newDeviceId: deviceId,
|
|
|
|
},
|
|
|
|
}, `Audio output device changed: from ${currentDeviceId || 'default'} to ${deviceId || 'default'}`);
|
|
|
|
this.outputDeviceId = deviceId;
|
|
|
|
|
|
|
|
// Live output device change - add device ID to session storage so it
|
|
|
|
// can be re-used on refreshes/other sessions
|
|
|
|
if (isLive) storeAudioOutputDeviceId(deviceId);
|
|
|
|
|
|
|
|
return this.outputDeviceId;
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'audiomanager_output_device_change_failure',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
errorMessage: error.message,
|
|
|
|
deviceId: currentDeviceId,
|
|
|
|
newDeviceId: targetDeviceId,
|
|
|
|
},
|
|
|
|
}, `Error changing output device - {${error.name}: ${error.message}}`);
|
|
|
|
|
|
|
|
// Rollback/enforce current sinkId (if possible)
|
|
|
|
if (sinkIdSupported) {
|
|
|
|
this.outputDeviceId = getCurrentAudioSinkId();
|
|
|
|
} else {
|
|
|
|
this.outputDeviceId = currentDeviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.outputDeviceId;
|
2017-10-10 04:48:10 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 02:03:29 +08:00
|
|
|
get inputStream() {
|
2021-04-16 21:45:40 +08:00
|
|
|
this._inputStreamTracker.depend();
|
|
|
|
return this._inputStream;
|
|
|
|
}
|
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
get bridge() {
|
|
|
|
return this.isListenOnly ? this.listenOnlyBridge : this.fullAudioBridge;
|
|
|
|
}
|
|
|
|
|
2021-04-16 21:45:40 +08:00
|
|
|
set inputStream(stream) {
|
|
|
|
// We store reactive information about input stream
|
|
|
|
// because mutedalert component needs to track when it changes
|
|
|
|
// and then update hark with the new value for inputStream
|
|
|
|
if (this._inputStream !== stream) {
|
|
|
|
this._inputStreamTracker.changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._inputStream = stream;
|
2017-09-30 04:42:34 +08:00
|
|
|
}
|
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
/**
|
|
|
|
* Sets the current status for breakout audio transfer
|
2021-03-08 02:01:12 +08:00
|
|
|
* @param {Object} newStatus The status Object to be set for
|
2021-03-07 09:09:43 +08:00
|
|
|
* audio transfer.
|
2021-03-08 02:01:12 +08:00
|
|
|
* @param {string} newStatus.breakoutMeetingId The meeting id of the current
|
|
|
|
* breakout audio transfer.
|
|
|
|
* @param {string} newStatus.status The status of the current audio
|
|
|
|
* transfer. Valid values are
|
|
|
|
* 'connected', 'disconnected' and
|
|
|
|
* 'returning'.
|
2021-03-07 09:09:43 +08:00
|
|
|
*/
|
2021-03-08 02:01:12 +08:00
|
|
|
setBreakoutAudioTransferStatus(newStatus) {
|
|
|
|
const currentStatus = this._breakoutAudioTransferStatus;
|
|
|
|
const { breakoutMeetingId, status } = newStatus;
|
2021-03-07 09:09:43 +08:00
|
|
|
|
|
|
|
if (typeof breakoutMeetingId === 'string') {
|
2021-03-08 02:01:12 +08:00
|
|
|
currentStatus.breakoutMeetingId = breakoutMeetingId;
|
2023-07-13 23:40:46 +08:00
|
|
|
} else {
|
|
|
|
currentStatus.breakoutMeetingId = null;
|
2021-03-07 09:09:43 +08:00
|
|
|
}
|
2021-03-17 22:30:07 +08:00
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
if (typeof status === 'string') {
|
2021-03-08 02:01:12 +08:00
|
|
|
currentStatus.status = status;
|
2021-09-21 22:22:05 +08:00
|
|
|
|
|
|
|
if (this.bridge && !this.isListenOnly) {
|
|
|
|
if (status !== BREAKOUT_AUDIO_TRANSFER_STATES.CONNECTED) {
|
|
|
|
this.bridge.ignoreCallState = false;
|
|
|
|
} else {
|
|
|
|
this.bridge.ignoreCallState = true;
|
|
|
|
}
|
|
|
|
}
|
2021-03-07 09:09:43 +08:00
|
|
|
}
|
2021-02-26 02:36:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-07 09:09:43 +08:00
|
|
|
getBreakoutAudioTransferStatus() {
|
|
|
|
return this._breakoutAudioTransferStatus;
|
2021-02-26 02:36:11 +08:00
|
|
|
}
|
|
|
|
|
2017-10-18 03:16:42 +08:00
|
|
|
set userData(value) {
|
|
|
|
this._userData = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
get userData() {
|
|
|
|
return this._userData;
|
|
|
|
}
|
2017-10-23 20:41:09 +08:00
|
|
|
|
2019-06-13 05:01:20 +08:00
|
|
|
playHangUpSound() {
|
2021-12-10 04:37:05 +08:00
|
|
|
this.playAlertSound(
|
|
|
|
`${
|
|
|
|
Meteor.settings.public.app.cdn +
|
|
|
|
Meteor.settings.public.app.basename +
|
|
|
|
Meteor.settings.public.app.instanceId
|
|
|
|
}` + '/resources/sounds/LeftCall.mp3'
|
|
|
|
);
|
2019-06-13 05:01:20 +08:00
|
|
|
}
|
|
|
|
|
2019-04-12 21:55:14 +08:00
|
|
|
notify(message, error = false, icon = 'unmute') {
|
|
|
|
const audioIcon = this.isListenOnly ? 'listen' : icon;
|
2019-04-12 06:53:57 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
notify(message, error ? 'error' : 'info', audioIcon);
|
2017-10-23 20:41:09 +08:00
|
|
|
}
|
2019-08-03 05:32:42 +08:00
|
|
|
|
2019-11-30 05:48:04 +08:00
|
|
|
monitor() {
|
2022-04-21 04:38:52 +08:00
|
|
|
const peer = this.bridge.getPeerConnection();
|
2019-11-30 05:48:04 +08:00
|
|
|
monitorAudioConnection(peer);
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:32:42 +08:00
|
|
|
handleAllowAutoplay() {
|
|
|
|
window.removeEventListener('audioPlayFailed', this.handlePlayElementFailed);
|
2019-09-07 02:58:22 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_autoplay_allowed',
|
|
|
|
},
|
|
|
|
'Listen only autoplay allowed by the user'
|
|
|
|
);
|
2019-09-07 02:58:22 +08:00
|
|
|
|
2019-08-03 05:32:42 +08:00
|
|
|
while (this.failedMediaElements.length) {
|
|
|
|
const mediaElement = this.failedMediaElements.shift();
|
|
|
|
if (mediaElement) {
|
2019-09-07 02:58:22 +08:00
|
|
|
playAndRetry(mediaElement).then((played) => {
|
|
|
|
if (!played) {
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.error(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_autoplay_handling_failed',
|
|
|
|
},
|
|
|
|
'Listen only autoplay handling failed to play media'
|
|
|
|
);
|
2019-09-07 02:58:22 +08:00
|
|
|
} else {
|
|
|
|
// logCode is listenonly_* to make it consistent with the other tag play log
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'listenonly_media_play_success',
|
|
|
|
},
|
|
|
|
'Listen only media played successfully'
|
|
|
|
);
|
2019-09-07 02:58:22 +08:00
|
|
|
}
|
2019-08-03 05:32:42 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.autoplayBlocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayElementFailed(e) {
|
|
|
|
const { mediaElement } = e.detail;
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
this.failedMediaElements.push(mediaElement);
|
|
|
|
if (!this.autoplayBlocked) {
|
2021-12-10 04:37:05 +08:00
|
|
|
logger.info(
|
|
|
|
{
|
|
|
|
logCode: 'audiomanager_autoplay_prompt',
|
|
|
|
},
|
|
|
|
'Prompting user for action to play listen only media'
|
|
|
|
);
|
2019-08-03 05:32:42 +08:00
|
|
|
this.autoplayBlocked = true;
|
|
|
|
}
|
|
|
|
}
|
2020-09-10 01:03:27 +08:00
|
|
|
|
2020-09-17 22:37:28 +08:00
|
|
|
setSenderTrackEnabled(shouldEnable) {
|
2020-09-12 07:06:56 +08:00
|
|
|
// If the bridge is set to listen only mode, nothing to do here. This method
|
|
|
|
// is solely for muting outbound tracks.
|
|
|
|
if (this.isListenOnly) return;
|
|
|
|
|
2020-09-10 22:50:50 +08:00
|
|
|
// Bridge -> SIP.js bridge, the only full audio capable one right now
|
|
|
|
const peer = this.bridge.getPeerConnection();
|
2020-09-26 07:11:44 +08:00
|
|
|
|
|
|
|
if (!peer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
peer.getSenders().forEach((sender) => {
|
2020-09-10 01:03:27 +08:00
|
|
|
const { track } = sender;
|
|
|
|
if (track && track.kind === 'audio') {
|
2020-09-10 22:50:50 +08:00
|
|
|
track.enabled = shouldEnable;
|
2020-09-10 01:03:27 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-17 22:37:28 +08:00
|
|
|
mute() {
|
2020-09-10 22:50:50 +08:00
|
|
|
this.setSenderTrackEnabled(false);
|
|
|
|
}
|
|
|
|
|
2020-09-17 22:37:28 +08:00
|
|
|
unmute() {
|
2020-09-10 22:50:50 +08:00
|
|
|
this.setSenderTrackEnabled(true);
|
2020-09-10 01:03:27 +08:00
|
|
|
}
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
|
2021-04-02 02:53:43 +08:00
|
|
|
playAlertSound(url) {
|
2021-04-13 00:57:02 +08:00
|
|
|
if (!url || !this.bridge) {
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
const audioAlert = new Audio(url);
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
audioAlert.addEventListener('ended', () => {
|
|
|
|
audioAlert.src = null;
|
|
|
|
});
|
2021-04-02 02:53:43 +08:00
|
|
|
|
|
|
|
const { outputDeviceId } = this.bridge;
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
if (outputDeviceId && typeof audioAlert.setSinkId === 'function') {
|
|
|
|
return audioAlert.setSinkId(outputDeviceId).then(() => audioAlert.play());
|
Correctly set audio input/output devices
When refusing ("thumbs down" button) echo test, user is able to select a different input device. This should work fine for chrome, firefox and safari (once user grants permission when asked by html5client).
For output devices, we depend on setSinkId function, which is enabled by default on current chrome release (2020) but not in Firefox (user needs to enable "setSinkId in about:config page). This implementation is listed as (?) in MDN.
In other words, output device selection should work out of the box for chrome, only.
When selecting an outputDevice, all alert sounds (hangup, screenshare , polling, etc) also goes to the same output device.
This solves #10592
2020-10-07 07:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return audioAlert.play();
|
|
|
|
}
|
2021-01-23 03:30:42 +08:00
|
|
|
|
|
|
|
async updateAudioConstraints(constraints) {
|
|
|
|
await this.bridge.updateAudioConstraints(constraints);
|
|
|
|
}
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2021-08-13 20:46:19 +08:00
|
|
|
/**
|
2021-08-26 03:27:46 +08:00
|
|
|
* Get the info about candidate-pair that is being used by the current peer.
|
|
|
|
* For firefox, or any other browser that doesn't support iceTransport
|
|
|
|
* property of RTCDtlsTransport, we retrieve the selected local candidate
|
|
|
|
* by looking into stats returned from getStats() api. For other browsers,
|
|
|
|
* we should use getSelectedCandidatePairFromPeer instead, because it has
|
|
|
|
* relatedAddress and relatedPort information about local candidate.
|
2021-08-13 20:46:19 +08:00
|
|
|
*
|
2021-08-26 03:27:46 +08:00
|
|
|
* @param {Object} stats object returned by getStats() api
|
|
|
|
* @returns An Object of type RTCIceCandidatePairStats containing information
|
|
|
|
* about the candidate-pair being used by the peer.
|
2021-08-13 20:46:19 +08:00
|
|
|
*
|
2021-08-26 03:27:46 +08:00
|
|
|
* For firefox, we can use the 'selected' flag to find the candidate pair
|
|
|
|
* being used, while in chrome we can retrieved the selected pair
|
|
|
|
* by looking for the corresponding transport of the active peer.
|
2021-08-13 20:46:19 +08:00
|
|
|
* For more information see:
|
2021-08-26 03:27:46 +08:00
|
|
|
* https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats
|
2021-08-13 20:46:19 +08:00
|
|
|
* and
|
2021-08-26 03:27:46 +08:00
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePairStats/selected#value
|
|
|
|
*/
|
|
|
|
static getSelectedCandidatePairFromStats(stats) {
|
|
|
|
if (!stats || typeof stats !== 'object') return null;
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
const transport =
|
|
|
|
Object.values(stats).find((stat) => stat.type === 'transport') || {};
|
2021-08-26 03:27:46 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
return Object.values(stats).find(
|
|
|
|
(stat) =>
|
|
|
|
stat.type === 'candidate-pair' &&
|
|
|
|
stat.nominated &&
|
|
|
|
(stat.selected || stat.id === transport.selectedCandidatePairId)
|
|
|
|
);
|
2021-08-26 03:27:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the info about candidate-pair that is being used by the current peer.
|
|
|
|
* This function's return value (RTCIceCandidatePair object ) is different
|
|
|
|
* from getSelectedCandidatePairFromStats (RTCIceCandidatePairStats object).
|
|
|
|
* The information returned here contains the relatedAddress and relatedPort
|
|
|
|
* fields (only for candidates that are derived from another candidate, for
|
|
|
|
* host candidates, these fields are null). These field can be helpful for
|
|
|
|
* debugging network issues. For all the browsers that support iceTransport
|
|
|
|
* field of RTCDtlsTransport, we use this function as default to retrieve
|
|
|
|
* information about current selected-pair. For other browsers we retrieve it
|
|
|
|
* from getSelectedCandidatePairFromStats
|
|
|
|
*
|
|
|
|
* @returns {Object} An RTCIceCandidatePair represented the selected
|
|
|
|
* candidate-pair of the active peer.
|
|
|
|
*
|
|
|
|
* For more info see:
|
|
|
|
* https://www.w3.org/TR/webrtc/#dom-rtcicecandidatepair
|
|
|
|
* and
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePair
|
|
|
|
* and
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCDtlsTransport
|
2021-08-13 20:46:19 +08:00
|
|
|
*/
|
2021-08-26 03:27:46 +08:00
|
|
|
getSelectedCandidatePairFromPeer() {
|
2022-04-21 04:38:52 +08:00
|
|
|
if (!this.bridge) return null;
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
const peer = this.bridge.getPeerConnection();
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2021-08-26 03:27:46 +08:00
|
|
|
if (!peer) return null;
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2021-08-26 03:27:46 +08:00
|
|
|
let selectedPair = null;
|
2021-08-13 03:39:04 +08:00
|
|
|
|
|
|
|
const receivers = peer.getReceivers();
|
2021-12-10 04:37:05 +08:00
|
|
|
if (
|
|
|
|
receivers &&
|
|
|
|
receivers[0] &&
|
|
|
|
receivers[0].transport &&
|
|
|
|
receivers[0].transport.iceTransport &&
|
|
|
|
receivers[0].transport.iceTransport
|
|
|
|
) {
|
|
|
|
selectedPair =
|
|
|
|
receivers[0].transport.iceTransport.getSelectedCandidatePair();
|
2021-08-26 03:27:46 +08:00
|
|
|
}
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2021-08-26 03:27:46 +08:00
|
|
|
return selectedPair;
|
|
|
|
}
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2021-08-26 03:27:46 +08:00
|
|
|
/**
|
|
|
|
* Gets the selected local-candidate information. For browsers that support
|
|
|
|
* iceTransport property (see getSelectedCandidatePairFromPeer) we get this
|
|
|
|
* info from peer, otherwise we retrieve this information from getStats() api
|
|
|
|
*
|
|
|
|
* @param {Object} [stats] The status object returned from getStats() api
|
|
|
|
* @returns {Object} An Object containing the information about the
|
|
|
|
* local-candidate. For browsers that support iceTransport
|
|
|
|
* property, the object's type is RCIceCandidate. A
|
|
|
|
* RTCIceCandidateStats is returned, otherwise.
|
|
|
|
*
|
|
|
|
* For more info see:
|
|
|
|
* https://www.w3.org/TR/webrtc/#dom-rtcicecandidate
|
|
|
|
* and
|
|
|
|
* https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatestats
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
getSelectedLocalCandidate(stats) {
|
|
|
|
let selectedPair = this.getSelectedCandidatePairFromPeer();
|
|
|
|
|
|
|
|
if (selectedPair) return selectedPair.local;
|
|
|
|
|
|
|
|
if (!stats) return null;
|
|
|
|
|
|
|
|
selectedPair = AudioManager.getSelectedCandidatePairFromStats(stats);
|
|
|
|
|
|
|
|
if (selectedPair) return stats[selectedPair.localCandidateId];
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the information about private/public ip address from peer
|
|
|
|
* stats. The information retrieved from selected pair from the current
|
|
|
|
* RTCIceTransport and returned in a new Object with format:
|
|
|
|
* {
|
|
|
|
* address: String,
|
|
|
|
* relatedAddress: String,
|
|
|
|
* port: Number,
|
|
|
|
* relatedPort: Number,
|
|
|
|
* candidateType: String,
|
|
|
|
* selectedLocalCandidate: Object,
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* If users isn't behind NAT, relatedAddress and relatedPort may be null.
|
|
|
|
*
|
|
|
|
* @returns An Object containing the information about private/public IP
|
|
|
|
* addresses and ports.
|
|
|
|
*
|
|
|
|
* For more information see:
|
|
|
|
* https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats
|
|
|
|
* and
|
|
|
|
* https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatestats
|
|
|
|
* and
|
|
|
|
* https://www.w3.org/TR/webrtc/#rtcicecandidatetype-enum
|
|
|
|
*/
|
|
|
|
async getInternalExternalIpAddresses(stats) {
|
|
|
|
let transports = {};
|
|
|
|
|
|
|
|
if (stats) {
|
|
|
|
const selectedLocalCandidate = this.getSelectedLocalCandidate(stats);
|
|
|
|
|
|
|
|
if (!selectedLocalCandidate) return transports;
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
const candidateType =
|
|
|
|
selectedLocalCandidate.candidateType || selectedLocalCandidate.type;
|
2021-08-13 03:39:04 +08:00
|
|
|
|
|
|
|
transports = {
|
2021-12-10 04:37:05 +08:00
|
|
|
isUsingTurn: candidateType === 'relay',
|
2021-08-26 03:27:46 +08:00
|
|
|
address: selectedLocalCandidate.address,
|
|
|
|
relatedAddress: selectedLocalCandidate.relatedAddress,
|
|
|
|
port: selectedLocalCandidate.port,
|
|
|
|
relatedPort: selectedLocalCandidate.relatedPort,
|
|
|
|
candidateType,
|
|
|
|
selectedLocalCandidate,
|
2021-08-13 03:39:04 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return transports;
|
|
|
|
}
|
|
|
|
|
2021-08-13 20:46:19 +08:00
|
|
|
/**
|
|
|
|
* Get stats about active audio peer.
|
2021-08-23 22:07:12 +08:00
|
|
|
* We filter the status based on FILTER_AUDIO_STATS constant.
|
2021-08-13 20:46:19 +08:00
|
|
|
* We also append to the returned object the information about peer's
|
|
|
|
* transport. This transport information is retrieved by
|
|
|
|
* getInternalExternalIpAddressesFromPeer().
|
|
|
|
*
|
|
|
|
* @returns An Object containing the status about the active audio peer.
|
|
|
|
*
|
|
|
|
* For more information see:
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats
|
2021-08-23 23:36:01 +08:00
|
|
|
* and
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
|
2021-08-13 20:46:19 +08:00
|
|
|
*/
|
2021-08-13 03:39:04 +08:00
|
|
|
async getStats() {
|
2022-04-21 04:38:52 +08:00
|
|
|
if (!this.bridge) return null;
|
2021-08-13 03:39:04 +08:00
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
const peer = this.bridge.getPeerConnection();
|
2021-08-13 03:39:04 +08:00
|
|
|
|
|
|
|
if (!peer) return null;
|
|
|
|
|
|
|
|
const peerStats = await peer.getStats();
|
|
|
|
|
|
|
|
const audioStats = {};
|
|
|
|
|
|
|
|
peerStats.forEach((stat) => {
|
|
|
|
if (FILTER_AUDIO_STATS.includes(stat.type)) {
|
2021-08-26 03:27:46 +08:00
|
|
|
audioStats[stat.id] = stat;
|
2021-08-13 03:39:04 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
const transportStats = await this.getInternalExternalIpAddresses(
|
|
|
|
audioStats
|
|
|
|
);
|
2021-08-13 03:39:04 +08:00
|
|
|
|
|
|
|
return { transportStats, ...audioStats };
|
|
|
|
}
|
2017-09-20 01:47:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const audioManager = new AudioManager();
|
|
|
|
export default audioManager;
|