Skip to content

Commit

Permalink
openvidu-browser: add OpenViduAdvancedConfiguration.rtcConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Jun 5, 2024
1 parent 86c4aba commit dfd614a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions openvidu-browser/src/OpenVidu/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ export class Stream {
onIceCandidate: this.connection.sendIceCandidate.bind(this.connection),
onIceConnectionStateException: this.onIceConnectionStateExceptionHandler.bind(this),
iceServers: this.getIceServersConf(),
rtcConfiguration: this.session.openvidu.advancedConfiguration.rtcConfiguration,
mediaStream: this.mediaStream,
mediaServer: this.session.openvidu.mediaServer,
typeOfVideo: this.typeOfVideo ? TypeOfVideo[this.typeOfVideo] : undefined
Expand Down Expand Up @@ -1412,6 +1413,7 @@ export class Stream {
onIceCandidate: this.connection.sendIceCandidate.bind(this.connection),
onIceConnectionStateException: this.onIceConnectionStateExceptionHandler.bind(this),
iceServers: this.getIceServersConf(),
rtcConfiguration: this.session.openvidu.advancedConfiguration.rtcConfiguration,
mediaServer: this.session.openvidu.mediaServer,
typeOfVideo: this.typeOfVideo ? TypeOfVideo[this.typeOfVideo] : undefined
};
Expand Down Expand Up @@ -1728,6 +1730,8 @@ export class Stream {
this.session.openvidu.advancedConfiguration.iceServers === 'freeice'
? undefined
: this.session.openvidu.advancedConfiguration.iceServers;
} else if (!!this.session.openvidu.advancedConfiguration.rtcConfiguration?.iceServers) {
returnValue = this.session.openvidu.advancedConfiguration.rtcConfiguration.iceServers;
} else if (this.session.openvidu.iceServers) {
returnValue = this.session.openvidu.iceServers;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
*/
export interface OpenViduAdvancedConfiguration {
/**
* Array of [RTCIceServer](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer) to be used by OpenVidu Browser. By default OpenVidu will generate the required credentials to use the COTURN server hosted along OpenVidu Server
* Array of [RTCIceServer](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer) to be used by OpenVidu Browser. By default OpenVidu will generate the required credentials to use the COTURN server hosted along OpenVidu Server.
* You can also set this property to string 'freeice' to force the use of free STUN servers instead (got thanks to [freeice](https://github.com/DamonOehlman/freeice) library).
*
* > **WARNING**: this value has priority over the standard `iceServers` property of [[rtcConfiguration]]. It will override any value in `OpenViduAdvancedConfiguration.rtcConfiguration.iceServers`
*/
iceServers?: RTCIceServer[] | string;

/**
* Custom configuration for all [RTCPeerConnection](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection#parameters) objects. This object will be passed as is to all RTCPeerConnection constructor (all Publishers and Subscribers).
*/
rtcConfiguration?: RTCConfiguration;

/**
* URL to a custom screen share extension for Chrome (always based on ours: [openvidu-screen-sharing-chrome-extension](https://github.com/OpenVidu/openvidu-screen-sharing-chrome-extension)) to be used instead of the default one.
* Must be something like this: `https://chrome.google.com/webstore/detail/YOUR_WEBSTORE_EXTENSION_NAME/YOUR_EXTENSION_ID`
Expand Down
10 changes: 9 additions & 1 deletion openvidu-browser/src/OpenViduInternal/WebRtcPeer/WebRtcPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface WebRtcPeerConfiguration {
onIceCandidate: (event: RTCIceCandidate) => void;
onIceConnectionStateException: (exceptionName: ExceptionEventName, message: string, data?: any) => void;
iceServers?: RTCIceServer[];
rtcConfiguration?: RTCConfiguration;
mediaStream?: MediaStream | null;
mode?: 'sendonly' | 'recvonly' | 'sendrecv';
id?: string;
Expand All @@ -63,14 +64,21 @@ export class WebRtcPeer {
this.configuration = {
...configuration,
iceServers: !!configuration.iceServers && configuration.iceServers.length > 0 ? configuration.iceServers : freeice(),
rtcConfiguration: configuration.rtcConfiguration !== undefined ? configuration.rtcConfiguration : {},
mediaStream: configuration.mediaStream !== undefined ? configuration.mediaStream : null,
mode: !!configuration.mode ? configuration.mode : 'sendrecv',
id: !!configuration.id ? configuration.id : this.generateUniqueId()
};
// prettier-ignore
logger.debug(`[WebRtcPeer] configuration:\n${JSON.stringify(this.configuration, null, 2)}`);

this.pc = new RTCPeerConnection({ iceServers: this.configuration.iceServers });
let rtcConfiguration: RTCConfiguration = this.configuration.rtcConfiguration
? this.configuration.rtcConfiguration
: { iceServers: this.configuration.iceServers };
if (!rtcConfiguration.iceServers && this.configuration.iceServers) {
rtcConfiguration.iceServers = this.configuration.iceServers;
}
this.pc = new RTCPeerConnection(rtcConfiguration);

this.pc.addEventListener('icecandidate', (event: RTCPeerConnectionIceEvent) => {
if (event.candidate !== null) {
Expand Down

0 comments on commit dfd614a

Please sign in to comment.