2017-09-09 01:00:00 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2018-07-27 02:26:56 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2020-12-10 06:00:54 +08:00
|
|
|
import BridgeService from './service';
|
|
|
|
import ScreenshareBroker from '/imports/ui/services/bbb-webrtc-sfu/screenshare-broker';
|
2023-05-31 22:06:49 +08:00
|
|
|
import { setIsSharing, screenShareEndAlert, setOutputDeviceId } from '/imports/ui/components/screenshare/service';
|
2021-01-12 23:24:01 +08:00
|
|
|
import { SCREENSHARING_ERRORS } from './errors';
|
2021-12-01 04:31:09 +08:00
|
|
|
import { shouldForceRelay } from '/imports/ui/services/bbb-webrtc-sfu/utils';
|
2022-05-08 00:50:34 +08:00
|
|
|
import MediaStreamUtils from '/imports/utils/media-stream-utils';
|
2023-02-16 22:37:00 +08:00
|
|
|
import { notifyStreamStateChange } from '/imports/ui/services/bbb-webrtc-sfu/stream-state-service';
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
const BRIDGE_NAME = 'kurento'
|
2018-07-10 05:29:27 +08:00
|
|
|
const SCREENSHARE_VIDEO_TAG = 'screenshareVideo';
|
2020-12-10 06:00:54 +08:00
|
|
|
const SEND_ROLE = 'send';
|
|
|
|
const RECV_ROLE = 'recv';
|
2021-12-09 00:24:26 +08:00
|
|
|
const DEFAULT_VOLUME = 1;
|
2017-11-18 02:55:59 +08:00
|
|
|
|
2021-01-12 23:24:01 +08:00
|
|
|
// the error-code mapping is bridge specific; that's why it's not in the errors util
|
|
|
|
const ERROR_MAP = {
|
|
|
|
1301: SCREENSHARING_ERRORS.SIGNALLING_TRANSPORT_DISCONNECTED,
|
|
|
|
1302: SCREENSHARING_ERRORS.SIGNALLING_TRANSPORT_CONNECTION_FAILED,
|
|
|
|
1305: SCREENSHARING_ERRORS.PEER_NEGOTIATION_FAILED,
|
|
|
|
1307: SCREENSHARING_ERRORS.ICE_STATE_FAILED,
|
2022-05-08 00:25:31 +08:00
|
|
|
1310: SCREENSHARING_ERRORS.ENDED_WHILE_STARTING,
|
|
|
|
};
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
const mapErrorCode = (error) => {
|
|
|
|
const { errorCode } = error;
|
2021-01-12 23:24:01 +08:00
|
|
|
const mappedError = ERROR_MAP[errorCode];
|
|
|
|
|
|
|
|
if (errorCode == null || mappedError == null) return error;
|
|
|
|
error.errorCode = mappedError.errorCode;
|
|
|
|
error.errorMessage = mappedError.errorMessage;
|
|
|
|
error.message = mappedError.errorMessage;
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
return error;
|
|
|
|
}
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
export default class KurentoScreenshareBridge {
|
|
|
|
constructor() {
|
|
|
|
this.role;
|
|
|
|
this.broker;
|
|
|
|
this._gdmStream;
|
2020-12-16 01:45:20 +08:00
|
|
|
this.hasAudio = false;
|
2020-12-10 06:00:54 +08:00
|
|
|
this.connectionAttempts = 0;
|
|
|
|
this.reconnecting = false;
|
|
|
|
this.reconnectionTimeout;
|
2024-07-03 01:58:58 +08:00
|
|
|
this._restartIntervalMs = null;
|
2023-02-16 22:37:00 +08:00
|
|
|
this.startedOnce = false;
|
2023-05-24 09:07:32 +08:00
|
|
|
this.outputDeviceId = null;
|
2020-12-10 06:00:54 +08:00
|
|
|
}
|
2018-04-27 06:52:46 +08:00
|
|
|
|
2024-07-03 01:58:58 +08:00
|
|
|
get restartIntervalMs() {
|
|
|
|
return this._restartIntervalMs || BridgeService.BASE_MEDIA_TIMEOUT();
|
|
|
|
}
|
|
|
|
|
|
|
|
set restartIntervalMs(value) {
|
|
|
|
this._restartIntervalMs = value;
|
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
get gdmStream() {
|
|
|
|
return this._gdmStream;
|
|
|
|
}
|
2019-09-11 21:17:23 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
set gdmStream(stream) {
|
|
|
|
this._gdmStream = stream;
|
|
|
|
}
|
2018-07-10 05:29:27 +08:00
|
|
|
|
2022-05-09 05:10:43 +08:00
|
|
|
_shouldReconnect() {
|
|
|
|
// Sender/presenter reconnect is *not* implemented yet
|
2023-02-16 06:57:57 +08:00
|
|
|
return this.reconnectionTimeout == null && this.role === RECV_ROLE;
|
2022-05-09 05:10:43 +08:00
|
|
|
}
|
|
|
|
|
2021-08-23 23:36:01 +08:00
|
|
|
/**
|
|
|
|
* Get the RTCPeerConnection object related to the screensharing stream.
|
|
|
|
* @returns {Object} The RTCPeerConnection object related to the presenter/
|
|
|
|
* viewer peer. If there's no stream being shared, returns
|
|
|
|
* null.
|
|
|
|
*/
|
|
|
|
getPeerConnection() {
|
|
|
|
try {
|
|
|
|
let peerConnection = null;
|
|
|
|
|
|
|
|
if (this.broker && this.broker.webRtcPeer) {
|
|
|
|
peerConnection = this.broker.webRtcPeer.peerConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
return peerConnection;
|
|
|
|
} catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
inboundStreamReconnect() {
|
|
|
|
const currentRestartIntervalMs = this.restartIntervalMs;
|
|
|
|
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'screenshare_viewer_reconnect',
|
2020-12-16 01:45:20 +08:00
|
|
|
extraInfo: {
|
|
|
|
reconnecting: this.reconnecting,
|
|
|
|
role: this.role,
|
2022-05-09 05:10:43 +08:00
|
|
|
bridge: BRIDGE_NAME,
|
2020-12-16 01:45:20 +08:00
|
|
|
},
|
2022-05-09 05:10:43 +08:00
|
|
|
}, 'Screenshare viewer is reconnecting');
|
2020-12-16 01:45:20 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
// Cleanly stop everything before triggering a reconnect
|
2022-05-09 04:25:49 +08:00
|
|
|
this._stop();
|
2020-12-10 06:00:54 +08:00
|
|
|
// Create new reconnect interval time
|
|
|
|
this.restartIntervalMs = BridgeService.getNextReconnectionInterval(currentRestartIntervalMs);
|
2020-12-16 01:45:20 +08:00
|
|
|
this.view(this.hasAudio).then(() => {
|
2020-12-10 06:00:54 +08:00
|
|
|
this.clearReconnectionTimeout();
|
2022-05-09 05:10:43 +08:00
|
|
|
}).catch((error) => {
|
2020-12-10 06:00:54 +08:00
|
|
|
// Error handling is a no-op because it will be "handled" in handleViewerFailure
|
|
|
|
logger.debug({
|
|
|
|
logCode: 'screenshare_reconnect_failed',
|
|
|
|
extraInfo: {
|
2021-01-12 23:24:01 +08:00
|
|
|
errorCode: error.errorCode,
|
2020-12-10 06:00:54 +08:00
|
|
|
errorMessage: error.errorMessage,
|
|
|
|
reconnecting: this.reconnecting,
|
|
|
|
role: this.role,
|
|
|
|
bridge: BRIDGE_NAME
|
|
|
|
},
|
|
|
|
}, 'Screensharing reconnect failed');
|
|
|
|
});
|
2019-09-07 02:58:22 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
handleConnectionTimeoutExpiry() {
|
|
|
|
this.reconnecting = true;
|
|
|
|
|
|
|
|
switch (this.role) {
|
|
|
|
case RECV_ROLE:
|
|
|
|
return this.inboundStreamReconnect();
|
2022-05-09 05:10:43 +08:00
|
|
|
|
|
|
|
// Sender/presenter reconnect is *not* implemented yet
|
2020-12-10 06:00:54 +08:00
|
|
|
case SEND_ROLE:
|
|
|
|
default:
|
|
|
|
this.reconnecting = false;
|
|
|
|
logger.error({
|
2022-05-09 05:10:43 +08:00
|
|
|
logCode: 'screenshare_wont_reconnect',
|
|
|
|
extraInfo: {
|
|
|
|
role: this.broker?.role || this.role,
|
|
|
|
started: !!(this.broker?.started),
|
|
|
|
bridge: BRIDGE_NAME,
|
|
|
|
},
|
|
|
|
}, 'Screen sharing will not reconnect');
|
2020-12-10 06:00:54 +08:00
|
|
|
break;
|
2019-09-11 00:20:40 +08:00
|
|
|
}
|
2019-09-07 02:58:22 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
maxConnectionAttemptsReached () {
|
2024-07-03 01:58:58 +08:00
|
|
|
return this.connectionAttempts > BridgeService.MAX_CONN_ATTEMPTS();
|
2020-12-10 06:00:54 +08:00
|
|
|
}
|
2020-08-27 07:30:53 +08:00
|
|
|
|
2023-02-16 22:37:00 +08:00
|
|
|
scheduleReconnect({
|
|
|
|
overrideTimeout,
|
|
|
|
} = { }) {
|
2020-12-10 06:00:54 +08:00
|
|
|
if (this.reconnectionTimeout == null) {
|
2023-02-16 22:37:00 +08:00
|
|
|
let nextRestartInterval = this.restartIntervalMs;
|
|
|
|
if (typeof overrideTimeout === 'number') nextRestartInterval = overrideTimeout;
|
2022-05-09 05:21:22 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
this.reconnectionTimeout = setTimeout(
|
|
|
|
this.handleConnectionTimeoutExpiry.bind(this),
|
2022-05-09 05:21:22 +08:00
|
|
|
nextRestartInterval,
|
2020-12-10 06:00:54 +08:00
|
|
|
);
|
2020-08-27 07:30:53 +08:00
|
|
|
}
|
2020-12-10 06:00:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clearReconnectionTimeout () {
|
|
|
|
this.reconnecting = false;
|
2024-07-03 01:58:58 +08:00
|
|
|
this.restartIntervalMs = BridgeService.BASE_MEDIA_TIMEOUT();
|
2020-08-27 07:30:53 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
if (this.reconnectionTimeout) {
|
|
|
|
clearTimeout(this.reconnectionTimeout);
|
|
|
|
this.reconnectionTimeout = null;
|
|
|
|
}
|
2020-08-27 07:30:53 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 01:51:21 +08:00
|
|
|
setVolume(volume) {
|
2021-12-09 00:24:26 +08:00
|
|
|
const mediaElement = document.getElementById(SCREENSHARE_VIDEO_TAG);
|
2021-11-12 01:51:21 +08:00
|
|
|
|
2021-12-09 00:24:26 +08:00
|
|
|
if (mediaElement) {
|
|
|
|
if (typeof volume === 'number' && volume >= 0 && volume <= 1) {
|
|
|
|
mediaElement.volume = volume;
|
|
|
|
}
|
2021-11-12 01:51:21 +08:00
|
|
|
|
2021-12-09 00:24:26 +08:00
|
|
|
return mediaElement.volume;
|
2021-11-12 01:51:21 +08:00
|
|
|
}
|
2021-12-09 00:24:26 +08:00
|
|
|
|
|
|
|
return DEFAULT_VOLUME;
|
2021-11-12 01:51:21 +08:00
|
|
|
}
|
|
|
|
|
2021-12-09 00:24:26 +08:00
|
|
|
getVolume() {
|
|
|
|
const mediaElement = document.getElementById(SCREENSHARE_VIDEO_TAG);
|
2021-11-12 01:51:21 +08:00
|
|
|
|
2021-12-09 00:24:26 +08:00
|
|
|
if (mediaElement) return mediaElement.volume;
|
2021-11-12 01:51:21 +08:00
|
|
|
|
2021-12-09 00:24:26 +08:00
|
|
|
return DEFAULT_VOLUME;
|
2021-11-12 01:51:21 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
handleViewerStart() {
|
|
|
|
const mediaElement = document.getElementById(SCREENSHARE_VIDEO_TAG);
|
2020-08-27 07:30:53 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
if (mediaElement && this.broker && this.broker.webRtcPeer) {
|
|
|
|
const stream = this.broker.webRtcPeer.getRemoteStream();
|
2023-05-24 09:07:32 +08:00
|
|
|
|
|
|
|
if (this.hasAudio && this.outputDeviceId && typeof this.outputDeviceId === 'string') {
|
|
|
|
setOutputDeviceId(this.outputDeviceId);
|
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
BridgeService.screenshareLoadAndPlayMediaStream(stream, mediaElement, !this.broker.hasAudio);
|
2020-08-27 07:30:53 +08:00
|
|
|
}
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2023-02-16 22:37:00 +08:00
|
|
|
this.startedOnce = true;
|
2020-12-10 06:00:54 +08:00
|
|
|
this.clearReconnectionTimeout();
|
2022-05-09 04:25:49 +08:00
|
|
|
this.connectionAttempts = 0;
|
2020-08-27 07:30:53 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
handleBrokerFailure(error) {
|
|
|
|
mapErrorCode(error);
|
2021-01-12 23:24:01 +08:00
|
|
|
const { errorMessage, errorCode } = error;
|
2020-12-16 01:45:20 +08:00
|
|
|
|
|
|
|
logger.error({
|
2021-01-12 23:24:01 +08:00
|
|
|
logCode: 'screenshare_broker_failure',
|
2020-12-16 01:45:20 +08:00
|
|
|
extraInfo: {
|
2023-02-16 22:37:00 +08:00
|
|
|
errorCode,
|
|
|
|
errorMessage,
|
2020-12-16 01:45:20 +08:00
|
|
|
role: this.broker.role,
|
|
|
|
started: this.broker.started,
|
|
|
|
reconnecting: this.reconnecting,
|
2023-02-16 22:37:00 +08:00
|
|
|
bridge: BRIDGE_NAME,
|
2020-12-16 01:45:20 +08:00
|
|
|
},
|
2021-07-08 03:04:56 +08:00
|
|
|
}, `Screenshare broker failure: ${errorMessage}`);
|
2020-12-16 01:45:20 +08:00
|
|
|
|
2023-02-16 22:37:00 +08:00
|
|
|
notifyStreamStateChange('screenshare', 'failed');
|
2020-12-10 06:00:54 +08:00
|
|
|
// Screensharing was already successfully negotiated and error occurred during
|
|
|
|
// during call; schedule a reconnect
|
2022-05-09 05:10:43 +08:00
|
|
|
if (this._shouldReconnect()) {
|
2022-05-09 05:21:22 +08:00
|
|
|
// this.broker.started => whether the reconnect should happen immediately.
|
2023-02-16 22:37:00 +08:00
|
|
|
// If this session previously established connection (N-sessions back)
|
|
|
|
// and it failed abruptly, then the timeout is overridden to a intermediate value
|
|
|
|
// (BASE_RECONNECTION_TIMEOUT)
|
|
|
|
let overrideTimeout;
|
|
|
|
if (this.broker?.started) {
|
|
|
|
overrideTimeout = 0;
|
|
|
|
} else if (this.startedOnce) {
|
2024-07-03 01:58:58 +08:00
|
|
|
overrideTimeout = BridgeService.BASE_RECONNECTION_TIMEOUT();
|
2023-02-16 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.scheduleReconnect({ overrideTimeout });
|
2018-08-23 23:49:16 +08:00
|
|
|
}
|
2020-12-16 01:45:20 +08:00
|
|
|
|
|
|
|
return error;
|
2017-09-09 01:00:00 +08:00
|
|
|
}
|
|
|
|
|
2023-05-24 09:07:32 +08:00
|
|
|
async view(options = {
|
|
|
|
hasAudio: false,
|
|
|
|
outputDeviceId: null,
|
|
|
|
}) {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const SFU_CONFIG = SETTINGS.public.kurento;
|
|
|
|
const SFU_URL = SFU_CONFIG.wsUrl;
|
|
|
|
const OFFERING = SFU_CONFIG.screenshare.subscriberOffering;
|
|
|
|
const SIGNAL_CANDIDATES = SFU_CONFIG.signalCandidates;
|
|
|
|
const TRACE_LOGS = SFU_CONFIG.traceLogs;
|
|
|
|
const GATHERING_TIMEOUT = SFU_CONFIG.gatheringTimeout;
|
2023-05-24 09:07:32 +08:00
|
|
|
this.hasAudio = options.hasAudio;
|
|
|
|
this.outputDeviceId = options.outputDeviceId;
|
2020-12-10 06:00:54 +08:00
|
|
|
this.role = RECV_ROLE;
|
|
|
|
const iceServers = await BridgeService.getIceServers(Auth.sessionToken);
|
2023-05-24 09:07:32 +08:00
|
|
|
const brokerOptions = {
|
2020-12-10 06:00:54 +08:00
|
|
|
iceServers,
|
|
|
|
userName: Auth.fullname,
|
2023-05-24 09:07:32 +08:00
|
|
|
hasAudio: options.hasAudio,
|
2021-08-12 03:36:32 +08:00
|
|
|
offering: OFFERING,
|
2021-08-11 03:49:24 +08:00
|
|
|
mediaServer: BridgeService.getMediaServerAdapter(),
|
2021-09-24 03:32:14 +08:00
|
|
|
signalCandidates: SIGNAL_CANDIDATES,
|
2021-12-01 04:31:09 +08:00
|
|
|
forceRelay: shouldForceRelay(),
|
2022-07-12 22:19:57 +08:00
|
|
|
traceLogs: TRACE_LOGS,
|
2023-04-06 00:22:38 +08:00
|
|
|
gatheringTimeout: GATHERING_TIMEOUT,
|
feat: add experimental support for ICE restart (#21208)
We currently use full renegotiation for audio, video, and screen sharing
reconnections, which involves re-creating transports and signaling channels
from scratch. While effective in some scenarios, this approach is slow and,
especially with outbound cameras and screen sharing, prone to failures.
To counter that, WebRTC provides a mechanism to restart ICE without needing
to re-create the peer connection. This allows us to avoid full renegotiation
and bypass some server-side signaling limitations. Implementing ICE restart
should make outbound camera/screen sharing reconnections more reliable and
faster.
This commit implements the ICE restart procedure for all WebRTC components'
*outbound* peers. It is based on bbb-webrtc-sfu >= v2.15.0-beta.0, which
added support for ICE restart requests. This feature is *off by default*.
To enable it, adjust the following flags:
- `/etc/bigbluebutton/bbb-webrtc-sfu/production.yml`: `allowIceRestart: true`
- `/etc/bigbluebutton/bbb-html5.yml`: `public.kurento.restartIce`
* Refer to the inline documentation; this can be enabled on the client side
per media type.
* Note: The default max retries for audio is lower than for cameras/screen
sharing (1 vs 3). This is because the full renegotiation process for audio
is more reliable, so ICE restart is attempted first, followed by full
renegotiation if necessary. This approach is less suitable for cameras/
screen sharing, where longer retry periods for ICE restart make sense
since full renegotation there is... iffy.
Endpoints that are inbound/`recvonly` only (client's perspective) do *not*
support ICE restart yet. There are two main reasons:
- Server-side changes are required to support `recvonly` endpoints,
particularly the proper handling of the server’s `setup` role in the
its SDPs during an ICE restart. These changes are too broad for now,
so they are deferred to future releases (SFU@v2.16).
- Full reconnections for `recvonly` endpoints are currently reliable,
unlike for `send*` endpoints. ICE restarts could still provide benefits
for `recvonly` endpoints, but we need the server updates first.
2024-09-20 18:35:32 +08:00
|
|
|
// ICE restart only works for publishers right now - recvonly full
|
|
|
|
// reconnection works ok without it.
|
|
|
|
restartIce: false,
|
2020-12-10 06:00:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.broker = new ScreenshareBroker(
|
|
|
|
Auth.authenticateURL(SFU_URL),
|
|
|
|
BridgeService.getConferenceBridge(),
|
|
|
|
Auth.userID,
|
|
|
|
Auth.meetingID,
|
|
|
|
this.role,
|
2023-05-24 09:07:32 +08:00
|
|
|
brokerOptions,
|
2020-12-10 06:00:54 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
this.broker.onstart = this.handleViewerStart.bind(this);
|
|
|
|
this.broker.onerror = this.handleBrokerFailure.bind(this);
|
2023-03-30 22:40:19 +08:00
|
|
|
if (!this.reconnecting) {
|
|
|
|
this.broker.onended = this.handleEnded.bind(this);
|
|
|
|
}
|
2020-12-10 06:00:54 +08:00
|
|
|
return this.broker.view().finally(this.scheduleReconnect.bind(this));
|
2017-09-09 01:00:00 +08:00
|
|
|
}
|
2017-09-13 04:47:06 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
handlePresenterStart() {
|
|
|
|
logger.info({
|
|
|
|
logCode: 'screenshare_presenter_start_success',
|
|
|
|
}, 'Screenshare presenter started succesfully');
|
|
|
|
this.clearReconnectionTimeout();
|
2023-02-16 22:37:00 +08:00
|
|
|
this.startedOnce = true;
|
2020-12-10 06:00:54 +08:00
|
|
|
this.reconnecting = false;
|
|
|
|
this.connectionAttempts = 0;
|
2017-09-13 04:47:06 +08:00
|
|
|
}
|
2017-11-06 23:39:55 +08:00
|
|
|
|
2021-03-12 08:44:38 +08:00
|
|
|
handleEnded() {
|
|
|
|
screenShareEndAlert();
|
|
|
|
}
|
|
|
|
|
2023-03-24 20:23:17 +08:00
|
|
|
share(stream, onFailure, contentType) {
|
2020-12-16 01:45:20 +08:00
|
|
|
return new Promise(async (resolve, reject) => {
|
2024-07-03 01:58:58 +08:00
|
|
|
const SETTINGS = window.meetingClientSettings;
|
|
|
|
const SFU_CONFIG = SETTINGS.public.kurento;
|
|
|
|
const SFU_URL = SFU_CONFIG.wsUrl;
|
|
|
|
const SIGNAL_CANDIDATES = SFU_CONFIG.signalCandidates;
|
|
|
|
const TRACE_LOGS = SFU_CONFIG.traceLogs;
|
|
|
|
const { screenshare: NETWORK_PRIORITY } = SETTINGS.public.media.networkPriorities || {};
|
|
|
|
const GATHERING_TIMEOUT = SFU_CONFIG.gatheringTimeout;
|
feat: add experimental support for ICE restart (#21208)
We currently use full renegotiation for audio, video, and screen sharing
reconnections, which involves re-creating transports and signaling channels
from scratch. While effective in some scenarios, this approach is slow and,
especially with outbound cameras and screen sharing, prone to failures.
To counter that, WebRTC provides a mechanism to restart ICE without needing
to re-create the peer connection. This allows us to avoid full renegotiation
and bypass some server-side signaling limitations. Implementing ICE restart
should make outbound camera/screen sharing reconnections more reliable and
faster.
This commit implements the ICE restart procedure for all WebRTC components'
*outbound* peers. It is based on bbb-webrtc-sfu >= v2.15.0-beta.0, which
added support for ICE restart requests. This feature is *off by default*.
To enable it, adjust the following flags:
- `/etc/bigbluebutton/bbb-webrtc-sfu/production.yml`: `allowIceRestart: true`
- `/etc/bigbluebutton/bbb-html5.yml`: `public.kurento.restartIce`
* Refer to the inline documentation; this can be enabled on the client side
per media type.
* Note: The default max retries for audio is lower than for cameras/screen
sharing (1 vs 3). This is because the full renegotiation process for audio
is more reliable, so ICE restart is attempted first, followed by full
renegotiation if necessary. This approach is less suitable for cameras/
screen sharing, where longer retry periods for ICE restart make sense
since full renegotation there is... iffy.
Endpoints that are inbound/`recvonly` only (client's perspective) do *not*
support ICE restart yet. There are two main reasons:
- Server-side changes are required to support `recvonly` endpoints,
particularly the proper handling of the server’s `setup` role in the
its SDPs during an ICE restart. These changes are too broad for now,
so they are deferred to future releases (SFU@v2.16).
- Full reconnections for `recvonly` endpoints are currently reliable,
unlike for `send*` endpoints. ICE restarts could still provide benefits
for `recvonly` endpoints, but we need the server updates first.
2024-09-20 18:35:32 +08:00
|
|
|
const {
|
|
|
|
enabled: RESTART_ICE = false,
|
|
|
|
retries: RESTART_ICE_RETRIES = 3,
|
|
|
|
} = SFU_CONFIG.restartIce?.screenshare || {};
|
2020-12-16 01:45:20 +08:00
|
|
|
this.onerror = onFailure;
|
|
|
|
this.connectionAttempts += 1;
|
|
|
|
this.role = SEND_ROLE;
|
|
|
|
this.hasAudio = BridgeService.streamHasAudioTrack(stream);
|
|
|
|
this.gdmStream = stream;
|
|
|
|
|
|
|
|
const onerror = (error) => {
|
|
|
|
const normalizedError = this.handleBrokerFailure(error);
|
2022-05-09 05:10:43 +08:00
|
|
|
if (!this.broker.started) {
|
|
|
|
// Broker hasn't started - if there are retries left, try again.
|
|
|
|
if (this.maxConnectionAttemptsReached()) {
|
|
|
|
this.clearReconnectionTimeout();
|
|
|
|
this.connectionAttempts = 0;
|
|
|
|
onFailure(SCREENSHARING_ERRORS.MEDIA_TIMEOUT);
|
|
|
|
reject(SCREENSHARING_ERRORS.MEDIA_TIMEOUT);
|
|
|
|
}
|
|
|
|
} else if (!this._shouldReconnect()) {
|
|
|
|
// Broker has started - should reconnect? If it shouldn't, end it.
|
|
|
|
onFailure(normalizedError);
|
2020-12-16 01:45:20 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const iceServers = await BridgeService.getIceServers(Auth.sessionToken);
|
|
|
|
const options = {
|
|
|
|
iceServers,
|
|
|
|
userName: Auth.fullname,
|
|
|
|
stream,
|
|
|
|
hasAudio: this.hasAudio,
|
2023-03-24 20:23:17 +08:00
|
|
|
contentType: contentType,
|
2024-07-03 01:58:58 +08:00
|
|
|
bitrate: BridgeService.BASE_BITRATE(),
|
2021-08-12 03:36:32 +08:00
|
|
|
offering: true,
|
2021-04-27 02:39:29 +08:00
|
|
|
mediaServer: BridgeService.getMediaServerAdapter(),
|
2021-09-24 03:32:14 +08:00
|
|
|
signalCandidates: SIGNAL_CANDIDATES,
|
2021-12-01 04:31:09 +08:00
|
|
|
forceRelay: shouldForceRelay(),
|
2022-07-12 22:19:57 +08:00
|
|
|
traceLogs: TRACE_LOGS,
|
2022-08-16 05:24:05 +08:00
|
|
|
networkPriority: NETWORK_PRIORITY,
|
2023-04-06 00:22:38 +08:00
|
|
|
gatheringTimeout: GATHERING_TIMEOUT,
|
feat: add experimental support for ICE restart (#21208)
We currently use full renegotiation for audio, video, and screen sharing
reconnections, which involves re-creating transports and signaling channels
from scratch. While effective in some scenarios, this approach is slow and,
especially with outbound cameras and screen sharing, prone to failures.
To counter that, WebRTC provides a mechanism to restart ICE without needing
to re-create the peer connection. This allows us to avoid full renegotiation
and bypass some server-side signaling limitations. Implementing ICE restart
should make outbound camera/screen sharing reconnections more reliable and
faster.
This commit implements the ICE restart procedure for all WebRTC components'
*outbound* peers. It is based on bbb-webrtc-sfu >= v2.15.0-beta.0, which
added support for ICE restart requests. This feature is *off by default*.
To enable it, adjust the following flags:
- `/etc/bigbluebutton/bbb-webrtc-sfu/production.yml`: `allowIceRestart: true`
- `/etc/bigbluebutton/bbb-html5.yml`: `public.kurento.restartIce`
* Refer to the inline documentation; this can be enabled on the client side
per media type.
* Note: The default max retries for audio is lower than for cameras/screen
sharing (1 vs 3). This is because the full renegotiation process for audio
is more reliable, so ICE restart is attempted first, followed by full
renegotiation if necessary. This approach is less suitable for cameras/
screen sharing, where longer retry periods for ICE restart make sense
since full renegotation there is... iffy.
Endpoints that are inbound/`recvonly` only (client's perspective) do *not*
support ICE restart yet. There are two main reasons:
- Server-side changes are required to support `recvonly` endpoints,
particularly the proper handling of the server’s `setup` role in the
its SDPs during an ICE restart. These changes are too broad for now,
so they are deferred to future releases (SFU@v2.16).
- Full reconnections for `recvonly` endpoints are currently reliable,
unlike for `send*` endpoints. ICE restarts could still provide benefits
for `recvonly` endpoints, but we need the server updates first.
2024-09-20 18:35:32 +08:00
|
|
|
restartIce: RESTART_ICE,
|
|
|
|
restartIceMaxRetries: RESTART_ICE_RETRIES,
|
2020-12-16 01:45:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.broker = new ScreenshareBroker(
|
|
|
|
Auth.authenticateURL(SFU_URL),
|
|
|
|
BridgeService.getConferenceBridge(),
|
|
|
|
Auth.userID,
|
|
|
|
Auth.meetingID,
|
|
|
|
this.role,
|
|
|
|
options,
|
|
|
|
);
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2020-12-16 01:45:20 +08:00
|
|
|
this.broker.onerror = onerror.bind(this);
|
|
|
|
this.broker.onstreamended = this.stop.bind(this);
|
|
|
|
this.broker.onstart = this.handlePresenterStart.bind(this);
|
2021-03-12 08:44:38 +08:00
|
|
|
this.broker.onended = this.handleEnded.bind(this);
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2020-12-16 01:45:20 +08:00
|
|
|
this.broker.share().then(() => {
|
2022-05-08 00:25:31 +08:00
|
|
|
this.scheduleReconnect();
|
|
|
|
return resolve();
|
|
|
|
}).catch((error) => reject(mapErrorCode(error)));
|
2020-12-16 01:45:20 +08:00
|
|
|
});
|
2022-05-08 00:25:31 +08:00
|
|
|
}
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2022-05-09 04:25:49 +08:00
|
|
|
// This is a reconnect-safe internal method. Should be used when one wants
|
|
|
|
// to clear the internal components (ie broker, connection timeouts) without
|
|
|
|
// affecting externally controlled components (ie gDM stream,
|
|
|
|
// media tag, connectionAttempts, ...)
|
|
|
|
_stop() {
|
2020-12-10 06:00:54 +08:00
|
|
|
if (this.broker) {
|
|
|
|
this.broker.stop();
|
|
|
|
// Checks if this session is a sharer and if it's not reconnecting
|
|
|
|
// If that's the case, clear the local sharing state in screen sharing UI
|
|
|
|
// component tracker to be extra sure we won't have any client-side state
|
|
|
|
// inconsistency - prlanzarin
|
2021-07-08 03:09:38 +08:00
|
|
|
if (this.broker && this.broker.role === SEND_ROLE && !this.reconnecting) {
|
2023-03-28 05:40:08 +08:00
|
|
|
setIsSharing(false);
|
2021-07-08 03:09:38 +08:00
|
|
|
}
|
2020-12-10 06:00:54 +08:00
|
|
|
this.broker = null;
|
|
|
|
}
|
2021-07-23 10:27:02 +08:00
|
|
|
|
2022-05-09 04:25:49 +08:00
|
|
|
this.clearReconnectionTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
const mediaElement = document.getElementById(SCREENSHARE_VIDEO_TAG);
|
|
|
|
|
|
|
|
this._stop();
|
|
|
|
this.connectionAttempts = 0;
|
|
|
|
|
2021-07-23 10:27:02 +08:00
|
|
|
if (mediaElement && typeof mediaElement.pause === 'function') {
|
|
|
|
mediaElement.pause();
|
|
|
|
mediaElement.srcObject = null;
|
|
|
|
}
|
|
|
|
|
2022-05-08 00:50:34 +08:00
|
|
|
if (this.gdmStream) {
|
|
|
|
MediaStreamUtils.stopMediaStreamTracks(this.gdmStream);
|
|
|
|
this.gdmStream = null;
|
|
|
|
}
|
2023-05-24 09:07:32 +08:00
|
|
|
|
|
|
|
this.outputDeviceId = null;
|
2017-11-06 23:39:55 +08:00
|
|
|
}
|
2017-09-09 01:00:00 +08:00
|
|
|
}
|