2021-09-18 01:17:31 +08:00
|
|
|
import BaseAudioBridge from './base';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import logger from '/imports/startup/client/logger';
|
2022-04-20 22:13:37 +08:00
|
|
|
import AudioBroker from '/imports/ui/services/bbb-webrtc-sfu/audio-broker';
|
2021-09-18 01:17:31 +08:00
|
|
|
import loadAndPlayMediaStream from '/imports/ui/services/bbb-webrtc-sfu/load-play';
|
|
|
|
import {
|
|
|
|
fetchWebRTCMappedStunTurnServers,
|
2021-09-25 02:11:53 +08:00
|
|
|
getMappedFallbackStun,
|
2021-09-18 01:17:31 +08:00
|
|
|
} from '/imports/utils/fetchStunTurnServers';
|
|
|
|
import getFromMeetingSettings from '/imports/ui/services/meeting-settings';
|
2023-08-08 02:28:17 +08:00
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2022-02-02 03:29:21 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2022-02-01 03:37:40 +08:00
|
|
|
import {
|
|
|
|
getAudioSessionNumber,
|
|
|
|
getAudioConstraints,
|
2022-02-02 03:29:21 +08:00
|
|
|
filterSupportedConstraints,
|
2022-09-16 01:48:26 +08:00
|
|
|
doGUM,
|
2022-02-01 03:37:40 +08:00
|
|
|
} from '/imports/api/audio/client/bridge/service';
|
2022-03-11 01:31:42 +08:00
|
|
|
import { shouldForceRelay } from '/imports/ui/services/bbb-webrtc-sfu/utils';
|
2022-02-02 03:29:21 +08:00
|
|
|
|
2021-09-25 02:11:53 +08:00
|
|
|
const SENDRECV_ROLE = 'sendrecv';
|
2021-09-18 01:17:31 +08:00
|
|
|
const RECV_ROLE = 'recv';
|
2024-06-05 19:26:27 +08:00
|
|
|
const PASSIVE_SENDRECV_ROLE = 'passive-sendrecv';
|
2021-09-25 02:11:53 +08:00
|
|
|
const BRIDGE_NAME = 'fullaudio';
|
2022-02-02 03:29:21 +08:00
|
|
|
const IS_CHROME = browserInfo.isChrome;
|
2021-09-18 01:17:31 +08:00
|
|
|
|
|
|
|
// SFU's base broker has distinct error codes so that it can be reused by different
|
|
|
|
// modules. Errors that have a valid, localized counterpart in audio manager are
|
|
|
|
// mapped so that the user gets a localized error message.
|
|
|
|
// The ones that haven't (ie SFU's servers-side errors), aren't mapped.
|
|
|
|
const errorCodeMap = {
|
|
|
|
1301: 1001,
|
|
|
|
1302: 1002,
|
|
|
|
1305: 1005,
|
|
|
|
1307: 1007,
|
2021-09-25 02:11:53 +08:00
|
|
|
};
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
// Error codes that are prone to a retry according to RETRY_THROUGH_RELAY
|
|
|
|
const RETRYABLE_ERRORS = [1007, 1010];
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
const mapErrorCode = (error) => {
|
|
|
|
const { errorCode } = error;
|
|
|
|
const mappedErrorCode = errorCodeMap[errorCode];
|
|
|
|
if (errorCode == null || mappedErrorCode == null) return error;
|
2021-09-25 02:11:53 +08:00
|
|
|
// eslint-disable-next-line no-param-reassign
|
2021-09-18 01:17:31 +08:00
|
|
|
error.errorCode = mappedErrorCode;
|
|
|
|
return error;
|
2021-09-25 02:11:53 +08:00
|
|
|
};
|
2021-09-18 01:17:31 +08:00
|
|
|
|
2022-04-20 03:16:22 +08:00
|
|
|
const getMediaServerAdapter = (listenOnly = false) => {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const DEFAULT_LISTENONLY_MEDIA_SERVER = SETTINGS.public.kurento.listenOnlyMediaServer;
|
|
|
|
const DEFAULT_FULLAUDIO_MEDIA_SERVER = MEDIA.audio.fullAudioMediaServer;
|
|
|
|
|
2022-04-20 03:16:22 +08:00
|
|
|
if (listenOnly) {
|
|
|
|
return getFromMeetingSettings(
|
|
|
|
'media-server-listenonly',
|
|
|
|
DEFAULT_LISTENONLY_MEDIA_SERVER,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return getFromMeetingSettings(
|
|
|
|
'media-server-fullaudio',
|
|
|
|
DEFAULT_FULLAUDIO_MEDIA_SERVER,
|
|
|
|
);
|
|
|
|
};
|
2021-09-25 02:11:53 +08:00
|
|
|
|
2024-07-03 01:58:58 +08:00
|
|
|
const isTransparentListenOnlyEnabled = () => {
|
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const TRANSPARENT_LISTEN_ONLY = MEDIA.transparentListenOnly;
|
|
|
|
return getFromUserSettings(
|
|
|
|
'bbb_transparent_listen_only',
|
|
|
|
TRANSPARENT_LISTEN_ONLY,
|
|
|
|
);
|
|
|
|
};
|
2023-08-08 02:28:17 +08:00
|
|
|
|
2022-04-21 04:38:52 +08:00
|
|
|
export default class SFUAudioBridge extends BaseAudioBridge {
|
2023-08-08 02:28:17 +08:00
|
|
|
static getOfferingRole(isListenOnly) {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const LISTEN_ONLY_OFFERING = MEDIA.listenOnlyOffering;
|
|
|
|
const FULLAUDIO_OFFERING = MEDIA.fullAudioOffering;
|
2024-06-05 19:26:27 +08:00
|
|
|
return isListenOnly && !isTransparentListenOnlyEnabled()
|
2023-08-08 02:28:17 +08:00
|
|
|
? LISTEN_ONLY_OFFERING
|
|
|
|
: (!isTransparentListenOnlyEnabled() && FULLAUDIO_OFFERING);
|
|
|
|
}
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
constructor(userData) {
|
|
|
|
super();
|
|
|
|
this.userId = userData.userId;
|
|
|
|
this.name = userData.username;
|
|
|
|
this.sessionToken = userData.sessionToken;
|
2021-09-25 02:11:53 +08:00
|
|
|
this.broker = null;
|
2021-09-18 01:17:31 +08:00
|
|
|
this.reconnecting = false;
|
2021-09-25 02:11:53 +08:00
|
|
|
this.iceServers = [];
|
2022-01-26 04:51:02 +08:00
|
|
|
this.bridgeName = BRIDGE_NAME;
|
2024-06-05 19:26:27 +08:00
|
|
|
this.isListenOnly = false;
|
|
|
|
this.bypassGUM = false;
|
|
|
|
this.supportsTransparentListenOnly = isTransparentListenOnlyEnabled;
|
2023-07-28 02:08:29 +08:00
|
|
|
|
|
|
|
this.handleTermination = this.handleTermination.bind(this);
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
|
2022-02-01 03:37:40 +08:00
|
|
|
get inputStream() {
|
2024-06-05 19:26:27 +08:00
|
|
|
// Only return the stream if the broker is active and the role isn't recvonly
|
|
|
|
// Input stream == actual input-capturing stream, not the one that's being played
|
|
|
|
if (this.broker && this.role !== RECV_ROLE) {
|
2022-02-01 03:37:40 +08:00
|
|
|
return this.broker.getLocalStream();
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
|
2022-02-01 03:37:40 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-04-20 22:13:37 +08:00
|
|
|
get role() {
|
|
|
|
return this.broker?.role;
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:26:27 +08:00
|
|
|
getBrokerRole({ hasInputStream }) {
|
|
|
|
if (this.isListenOnly) {
|
|
|
|
return isTransparentListenOnlyEnabled()
|
|
|
|
? PASSIVE_SENDRECV_ROLE
|
|
|
|
: RECV_ROLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.bypassGUM && !hasInputStream) return PASSIVE_SENDRECV_ROLE;
|
|
|
|
|
|
|
|
return SENDRECV_ROLE;
|
|
|
|
}
|
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
setInputStream(stream) {
|
|
|
|
if (this.broker == null) return null;
|
2022-02-01 03:37:40 +08:00
|
|
|
|
2022-08-20 01:22:42 +08:00
|
|
|
return this.broker.setLocalStream(stream);
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getPeerConnection() {
|
|
|
|
if (!this.broker) return null;
|
|
|
|
|
2021-09-25 02:11:53 +08:00
|
|
|
const { webRtcPeer } = this.broker;
|
2021-09-18 01:17:31 +08:00
|
|
|
if (webRtcPeer) return webRtcPeer.peerConnection;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-09-16 04:42:43 +08:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
mediaStreamFactory(constraints) {
|
|
|
|
return doGUM(constraints, true);
|
|
|
|
}
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
setConnectionTimeout() {
|
|
|
|
if (this.connectionTimeout) this.clearConnectionTimeout();
|
|
|
|
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const CONNECTION_TIMEOUT_MS = MEDIA.listenOnlyCallTimeout || 15000;
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
this.connectionTimeout = setTimeout(() => {
|
|
|
|
const error = new Error(`ICE negotiation timeout after ${CONNECTION_TIMEOUT_MS / 1000}s`);
|
|
|
|
error.errorCode = 1010;
|
|
|
|
// Duplicating key-vals because I can'decide settle on an error pattern - prlanzarin again
|
|
|
|
error.errorCause = error.message;
|
|
|
|
error.errorMessage = error.message;
|
|
|
|
this.handleBrokerFailure(error);
|
|
|
|
}, CONNECTION_TIMEOUT_MS);
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
clearConnectionTimeout() {
|
|
|
|
if (this.connectionTimeout) {
|
|
|
|
clearTimeout(this.connectionTimeout);
|
|
|
|
this.connectionTimeout = null;
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
dispatchAutoplayHandlingEvent(mediaElement) {
|
|
|
|
const tagFailedEvent = new CustomEvent('audioPlayFailed', {
|
|
|
|
detail: { mediaElement },
|
|
|
|
});
|
|
|
|
window.dispatchEvent(tagFailedEvent);
|
|
|
|
this.callback({ status: this.baseCallStates.autoplayBlocked, bridge: this.bridgeName });
|
|
|
|
}
|
|
|
|
|
2023-07-27 21:59:49 +08:00
|
|
|
reconnect(options = {}) {
|
|
|
|
// If broker has already started, fire the reconnecting callback so the user
|
|
|
|
// knows what's going on
|
|
|
|
if (this.broker.started) {
|
|
|
|
this.callback({ status: this.baseCallStates.reconnecting, bridge: this.bridgeName });
|
|
|
|
} else {
|
|
|
|
// Otherwise: override termination handler so the ended callback doesn't get
|
|
|
|
// triggered - this is a retry attempt and the user shouldn't be notified
|
|
|
|
// yet.
|
|
|
|
this.broker.onended = () => {};
|
|
|
|
}
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
this.broker.stop();
|
|
|
|
this.reconnecting = true;
|
2023-07-28 02:08:29 +08:00
|
|
|
this._startBroker({ isListenOnly: this.isListenOnly, ...options })
|
|
|
|
.catch((error) => {
|
|
|
|
// Error handling is a no-op because it will be "handled" in handleBrokerFailure
|
|
|
|
logger.debug({
|
|
|
|
logCode: 'sfuaudio_reconnect_failed',
|
|
|
|
extraInfo: {
|
|
|
|
errorMessage: error.errorMessage,
|
|
|
|
reconnecting: this.reconnecting,
|
|
|
|
bridge: this.bridgeName,
|
|
|
|
role: this.role,
|
|
|
|
},
|
|
|
|
}, 'SFU audio reconnect failed');
|
2021-09-18 01:17:31 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBrokerFailure(error) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-07-28 02:08:29 +08:00
|
|
|
this.clearConnectionTimeout();
|
2021-09-18 01:17:31 +08:00
|
|
|
mapErrorCode(error);
|
|
|
|
const { errorMessage, errorCause, errorCode } = error;
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const RETRY_THROUGH_RELAY = MEDIA.audio.retryThroughRelay || false;
|
2021-09-18 01:17:31 +08:00
|
|
|
|
2023-07-27 21:59:49 +08:00
|
|
|
if (!this.reconnecting) {
|
|
|
|
if (this.broker.started) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'sfuaudio_error_try_to_reconnect',
|
|
|
|
extraInfo: {
|
|
|
|
errorMessage,
|
|
|
|
errorCode,
|
|
|
|
errorCause,
|
|
|
|
bridge: this.bridgeName,
|
|
|
|
role: this.role,
|
|
|
|
},
|
|
|
|
}, 'SFU audio failed, try to reconnect');
|
|
|
|
this.reconnect();
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
if (RETRYABLE_ERRORS.includes(errorCode) && RETRY_THROUGH_RELAY) {
|
2023-07-27 21:59:49 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'sfuaudio_error_retry_through_relay',
|
|
|
|
extraInfo: {
|
|
|
|
errorMessage,
|
|
|
|
errorCode,
|
|
|
|
errorCause,
|
|
|
|
bridge: this.bridgeName,
|
|
|
|
role: this.role,
|
|
|
|
},
|
|
|
|
}, 'SFU audio failed to connect, retry through relay');
|
|
|
|
this.reconnect({ forceRelay: true });
|
|
|
|
return resolve();
|
|
|
|
}
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
2023-07-28 02:08:29 +08:00
|
|
|
|
2024-03-18 21:58:53 +08:00
|
|
|
// Already tried reconnecting once OR the user handn't successfully
|
2023-07-28 02:08:29 +08:00
|
|
|
// connected firsthand and retrying isn't an option. Finish the session
|
|
|
|
// and reject with the error
|
2021-09-25 02:11:53 +08:00
|
|
|
logger.error({
|
2022-04-20 22:13:37 +08:00
|
|
|
logCode: 'sfuaudio_error',
|
2021-09-25 02:11:53 +08:00
|
|
|
extraInfo: {
|
|
|
|
errorMessage,
|
|
|
|
errorCode,
|
|
|
|
errorCause,
|
|
|
|
reconnecting: this.reconnecting,
|
2022-01-26 04:51:02 +08:00
|
|
|
bridge: this.bridgeName,
|
2022-04-20 22:13:37 +08:00
|
|
|
role: this.role,
|
2021-09-25 02:11:53 +08:00
|
|
|
},
|
2022-04-20 22:13:37 +08:00
|
|
|
}, 'SFU audio failed');
|
2023-07-28 02:08:29 +08:00
|
|
|
this.clearConnectionTimeout();
|
2021-09-25 02:11:53 +08:00
|
|
|
this.broker.stop();
|
|
|
|
this.callback({
|
|
|
|
status: this.baseCallStates.failed,
|
|
|
|
error: errorCode,
|
|
|
|
bridgeError: errorMessage,
|
2022-01-26 04:51:02 +08:00
|
|
|
bridge: this.bridgeName,
|
2021-09-25 02:11:53 +08:00
|
|
|
});
|
|
|
|
return reject(error);
|
2021-09-18 01:17:31 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
handleTermination() {
|
|
|
|
this.clearConnectionTimeout();
|
|
|
|
return this.callback({ status: this.baseCallStates.ended, bridge: this.bridgeName });
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleStart() {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const MEDIA_TAG = MEDIA.mediaTag.replace(/#/g, '');
|
2021-09-18 01:17:31 +08:00
|
|
|
const stream = this.broker.webRtcPeer.getRemoteStream();
|
|
|
|
const mediaElement = document.getElementById(MEDIA_TAG);
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
return loadAndPlayMediaStream(stream, mediaElement, false).then(() => {
|
|
|
|
this.callback({
|
2021-09-25 02:11:53 +08:00
|
|
|
status: this.baseCallStates.started,
|
2022-01-26 04:51:02 +08:00
|
|
|
bridge: this.bridgeName,
|
2023-07-28 02:08:29 +08:00
|
|
|
});
|
|
|
|
this.clearConnectionTimeout();
|
|
|
|
this.reconnecting = false;
|
|
|
|
}).catch((error) => {
|
2021-09-18 01:17:31 +08:00
|
|
|
// NotAllowedError equals autoplay issues, fire autoplay handling event.
|
|
|
|
// This will be handled in audio-manager.
|
|
|
|
if (error.name === 'NotAllowedError') {
|
|
|
|
logger.error({
|
2022-04-20 22:13:37 +08:00
|
|
|
logCode: 'sfuaudio_error_autoplay',
|
|
|
|
extraInfo: {
|
|
|
|
errorName: error.name,
|
|
|
|
bridge: this.bridgeName,
|
|
|
|
role: this.role,
|
|
|
|
},
|
|
|
|
}, 'SFU audio media play failed due to autoplay error');
|
2021-09-18 01:17:31 +08:00
|
|
|
this.dispatchAutoplayHandlingEvent(mediaElement);
|
2023-08-09 22:09:27 +08:00
|
|
|
// For connection purposes, this worked - the autoplay thing is a client
|
|
|
|
// side soft issue to be handled at the UI/UX level, not WebRTC/negotiation
|
|
|
|
// So: clear the connection timer
|
|
|
|
this.clearConnectionTimeout();
|
|
|
|
this.reconnecting = false;
|
2021-09-18 01:17:31 +08:00
|
|
|
} else {
|
|
|
|
const normalizedError = {
|
|
|
|
errorCode: 1004,
|
|
|
|
errorMessage: error.message || 'AUDIO_PLAY_FAILED',
|
|
|
|
};
|
|
|
|
this.callback({
|
|
|
|
status: this.baseCallStates.failed,
|
|
|
|
error: normalizedError.errorCode,
|
|
|
|
bridgeError: normalizedError.errorMessage,
|
2022-01-26 04:51:02 +08:00
|
|
|
bridge: this.bridgeName,
|
2021-09-25 02:11:53 +08:00
|
|
|
});
|
2021-09-18 01:17:31 +08:00
|
|
|
throw normalizedError;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-21 01:40:06 +08:00
|
|
|
async _startBroker(options) {
|
2023-07-28 02:08:29 +08:00
|
|
|
try {
|
|
|
|
this.iceServers = await fetchWebRTCMappedStunTurnServers(this.sessionToken);
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({ logCode: 'sfuaudio_stun-turn_fetch_failed' },
|
|
|
|
'SFU audio bridge failed to fetch STUN/TURN info, using default servers');
|
|
|
|
this.iceServers = getMappedFallbackStun();
|
|
|
|
}
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
return new Promise((resolve, reject) => {
|
2023-07-27 21:59:49 +08:00
|
|
|
const {
|
|
|
|
isListenOnly,
|
|
|
|
extension,
|
|
|
|
inputStream,
|
|
|
|
forceRelay: _forceRelay = false,
|
2024-06-05 19:26:27 +08:00
|
|
|
bypassGUM = false,
|
2023-07-27 21:59:49 +08:00
|
|
|
} = options;
|
|
|
|
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const SIGNAL_CANDIDATES = SETTINGS.public.kurento.signalCandidates;
|
|
|
|
const SFU_URL = SETTINGS.public.kurento.wsUrl;
|
|
|
|
const TRACE_LOGS = SETTINGS.public.kurento.traceLogs;
|
|
|
|
const GATHERING_TIMEOUT = SETTINGS.public.kurento.gatheringTimeout;
|
|
|
|
const RETRY_THROUGH_RELAY = MEDIA.audio.retryThroughRelay || false;
|
|
|
|
const { audio: NETWORK_PRIORITY } = MEDIA.networkPriorities || {};
|
|
|
|
|
2023-07-27 21:59:49 +08:00
|
|
|
const handleInitError = (_error) => {
|
|
|
|
mapErrorCode(_error);
|
2023-07-28 02:08:29 +08:00
|
|
|
if (RETRYABLE_ERRORS.includes(_error?.errorCode)
|
|
|
|
|| !RETRY_THROUGH_RELAY
|
|
|
|
|| this.reconnecting) {
|
2023-07-27 21:59:49 +08:00
|
|
|
reject(_error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
try {
|
2022-04-21 01:40:06 +08:00
|
|
|
this.inEchoTest = !!extension;
|
|
|
|
this.isListenOnly = isListenOnly;
|
2024-06-05 19:26:27 +08:00
|
|
|
this.bypassGUM = bypassGUM;
|
|
|
|
const role = this.getBrokerRole({
|
|
|
|
hasInputStream: !!inputStream,
|
|
|
|
});
|
2022-04-21 01:40:06 +08:00
|
|
|
|
|
|
|
const brokerOptions = {
|
2022-06-29 03:22:37 +08:00
|
|
|
clientSessionNumber: getAudioSessionNumber(),
|
2022-04-21 01:40:06 +08:00
|
|
|
extension,
|
|
|
|
iceServers: this.iceServers,
|
|
|
|
mediaServer: getMediaServerAdapter(isListenOnly),
|
|
|
|
constraints: getAudioConstraints({ deviceId: this.inputDeviceId }),
|
2023-07-27 21:59:49 +08:00
|
|
|
forceRelay: _forceRelay || shouldForceRelay(),
|
2022-04-21 01:40:06 +08:00
|
|
|
stream: (inputStream && inputStream.active) ? inputStream : undefined,
|
2023-08-08 02:28:17 +08:00
|
|
|
offering: SFUAudioBridge.getOfferingRole(this.isListenOnly),
|
2022-05-02 21:47:22 +08:00
|
|
|
signalCandidates: SIGNAL_CANDIDATES,
|
2022-07-12 22:19:57 +08:00
|
|
|
traceLogs: TRACE_LOGS,
|
2022-08-16 05:24:05 +08:00
|
|
|
networkPriority: NETWORK_PRIORITY,
|
2022-09-16 04:42:43 +08:00
|
|
|
mediaStreamFactory: this.mediaStreamFactory,
|
2023-04-06 00:22:38 +08:00
|
|
|
gatheringTimeout: GATHERING_TIMEOUT,
|
2023-08-08 02:28:17 +08:00
|
|
|
transparentListenOnly: isTransparentListenOnlyEnabled(),
|
2024-06-05 19:26:27 +08:00
|
|
|
bypassGUM,
|
2022-04-21 01:40:06 +08:00
|
|
|
};
|
2021-09-18 01:17:31 +08:00
|
|
|
|
2022-04-21 01:40:06 +08:00
|
|
|
this.broker = new AudioBroker(
|
|
|
|
Auth.authenticateURL(SFU_URL),
|
2024-06-05 19:26:27 +08:00
|
|
|
role,
|
2022-04-21 01:40:06 +08:00
|
|
|
brokerOptions,
|
|
|
|
);
|
2021-09-25 02:11:53 +08:00
|
|
|
|
2022-04-21 01:40:06 +08:00
|
|
|
this.broker.onended = this.handleTermination.bind(this);
|
2021-09-18 01:17:31 +08:00
|
|
|
this.broker.onerror = (error) => {
|
|
|
|
this.handleBrokerFailure(error).catch(reject);
|
2021-09-25 02:11:53 +08:00
|
|
|
};
|
2021-09-18 01:17:31 +08:00
|
|
|
this.broker.onstart = () => {
|
|
|
|
this.handleStart().then(resolve).catch(reject);
|
|
|
|
};
|
2022-04-21 01:40:06 +08:00
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
// Set up a connectionTimeout in case the server or network are botching
|
|
|
|
// negotiation or conn checks.
|
|
|
|
this.setConnectionTimeout();
|
2023-07-27 21:59:49 +08:00
|
|
|
this.broker.joinAudio().catch(handleInitError);
|
2021-09-25 02:11:53 +08:00
|
|
|
} catch (error) {
|
2023-07-27 21:59:49 +08:00
|
|
|
handleInitError(error);
|
2021-09-18 01:17:31 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-25 02:11:53 +08:00
|
|
|
async joinAudio(options, callback) {
|
2022-04-20 22:13:37 +08:00
|
|
|
this.callback = callback;
|
2023-07-28 02:08:29 +08:00
|
|
|
this.reconnecting = false;
|
2022-04-20 22:13:37 +08:00
|
|
|
|
|
|
|
return this._startBroker(options);
|
2021-09-25 02:11:53 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 04:51:02 +08:00
|
|
|
sendDtmf(tones) {
|
|
|
|
if (this.broker) {
|
|
|
|
this.broker.dtmf(tones);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
transferCall(onTransferSuccess) {
|
|
|
|
this.inEchoTest = false;
|
|
|
|
return this.trackTransferState(onTransferSuccess);
|
|
|
|
}
|
|
|
|
|
2022-02-02 03:29:21 +08:00
|
|
|
async updateAudioConstraints(constraints) {
|
|
|
|
try {
|
|
|
|
if (typeof constraints !== 'object') return;
|
|
|
|
|
|
|
|
const matchConstraints = filterSupportedConstraints(constraints);
|
|
|
|
|
|
|
|
if (IS_CHROME) {
|
|
|
|
matchConstraints.deviceId = this.inputDeviceId;
|
2022-09-16 01:48:26 +08:00
|
|
|
const stream = await doGUM({ audio: matchConstraints });
|
2022-08-20 01:22:42 +08:00
|
|
|
await this.setInputStream(stream);
|
2022-02-02 03:29:21 +08:00
|
|
|
} else {
|
2022-04-20 03:18:04 +08:00
|
|
|
this.inputStream.getAudioTracks()
|
|
|
|
.forEach((track) => track.applyConstraints(matchConstraints));
|
2022-02-02 03:29:21 +08:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({
|
2022-04-20 22:13:37 +08:00
|
|
|
logCode: 'sfuaudio_audio_constraint_error',
|
2022-02-02 03:29:21 +08:00
|
|
|
extraInfo: {
|
|
|
|
errorCode: error.code,
|
|
|
|
errorMessage: error.message,
|
|
|
|
bridgeName: this.bridgeName,
|
2022-04-20 22:13:37 +08:00
|
|
|
role: this.role,
|
2022-02-02 03:29:21 +08:00
|
|
|
},
|
|
|
|
}, 'Failed to update audio constraint');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 00:34:39 +08:00
|
|
|
trickleIce() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
fetchWebRTCMappedStunTurnServers(this.sessionToken)
|
|
|
|
.then((iceServers) => {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const SFU_URL = SETTINGS.public.kurento.wsUrl;
|
|
|
|
const TRACE_LOGS = SETTINGS.public.kurento.traceLogs;
|
|
|
|
const GATHERING_TIMEOUT = SETTINGS.public.kurento.gatheringTimeout;
|
|
|
|
const LISTEN_ONLY_OFFERING = MEDIA.listenOnlyOffering;
|
|
|
|
|
2022-04-26 00:34:39 +08:00
|
|
|
const options = {
|
2022-06-29 03:22:37 +08:00
|
|
|
clientSessionNumber: getAudioSessionNumber(),
|
2022-04-26 00:34:39 +08:00
|
|
|
iceServers,
|
|
|
|
offering: LISTEN_ONLY_OFFERING,
|
2022-07-12 22:19:57 +08:00
|
|
|
traceLogs: TRACE_LOGS,
|
2023-04-06 00:22:38 +08:00
|
|
|
gatheringTimeout: GATHERING_TIMEOUT,
|
2022-04-26 00:34:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.broker = new AudioBroker(
|
|
|
|
Auth.authenticateURL(SFU_URL),
|
|
|
|
RECV_ROLE,
|
|
|
|
options,
|
|
|
|
);
|
|
|
|
|
|
|
|
this.broker.onstart = () => {
|
|
|
|
const { peerConnection } = this.broker.webRtcPeer;
|
|
|
|
|
|
|
|
if (!peerConnection) return resolve(null);
|
|
|
|
|
|
|
|
const selectedCandidatePair = peerConnection.getReceivers()[0]
|
|
|
|
.transport.iceTransport.getSelectedCandidatePair();
|
|
|
|
|
|
|
|
const validIceCandidate = [selectedCandidatePair.local];
|
|
|
|
|
|
|
|
this.broker.stop();
|
|
|
|
return resolve(validIceCandidate);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.broker.joinAudio().catch(reject);
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// Rollback
|
|
|
|
this.exitAudio();
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-18 01:17:31 +08:00
|
|
|
exitAudio() {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const MEDIA = SETTINGS.public.media;
|
|
|
|
const MEDIA_TAG = MEDIA.mediaTag.replace(/#/g, '');
|
2021-09-18 01:17:31 +08:00
|
|
|
const mediaElement = document.getElementById(MEDIA_TAG);
|
|
|
|
|
2023-07-28 02:08:29 +08:00
|
|
|
this.clearConnectionTimeout();
|
|
|
|
this.reconnecting = false;
|
2022-06-30 01:44:47 +08:00
|
|
|
|
|
|
|
if (this.broker) {
|
|
|
|
this.broker.stop();
|
|
|
|
this.broker = null;
|
|
|
|
}
|
2021-09-18 01:17:31 +08:00
|
|
|
|
|
|
|
if (mediaElement && typeof mediaElement.pause === 'function') {
|
|
|
|
mediaElement.pause();
|
|
|
|
mediaElement.srcObject = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
}
|