Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Configure TURN server only once
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Jun 18, 2024
1 parent 75039d4 commit 25f3355
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/webrtc/webRTCEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,7 @@ export class WebRTCEndpoint<EndpointMetadata = any, TrackMetadata = any> extends
let data;
switch (deserializedMediaEvent.type) {
case "offerData": {
const turnServers = deserializedMediaEvent.data.integratedTurnServers;
this.setTurns(turnServers);

const offerData = new Map<string, number>(Object.entries(deserializedMediaEvent.data.tracksTypes));

this.onOfferData(offerData);
this.onOfferData(deserializedMediaEvent);
break;
}
case "tracksAdded": {
Expand Down Expand Up @@ -1678,8 +1673,11 @@ export class WebRTCEndpoint<EndpointMetadata = any, TrackMetadata = any> extends
private checkIfTrackBelongToEndpoint = (trackId: string, endpoint: Endpoint<EndpointMetadata, TrackMetadata>) =>
Array.from(endpoint.tracks.keys()).some((track) => trackId.startsWith(track));

private onOfferData = async (offerData: Map<string, number>) => {
private onOfferData = async (offerData: MediaEvent) => {
if (!this.connection) {
const turnServers = offerData.data.integratedTurnServers;
this.setTurns(turnServers);

this.connection = new RTCPeerConnection(this.rtcConfig);
this.connection.onicecandidate = this.onLocalCandidate();
this.connection.onicecandidateerror = this.onIceCandidateError as (event: Event) => void;
Expand All @@ -1692,10 +1690,15 @@ export class WebRTCEndpoint<EndpointMetadata = any, TrackMetadata = any> extends

this.connection.getTransceivers().forEach((transceiver) => (transceiver.direction = "sendonly"));
} else {
console.log(JSON.stringify(this.connection.getConfiguration()));
this.connection.restartIce();
console.log("ICE restarted");
console.log(JSON.stringify(this.connection.getConfiguration()));
}

this.addTransceiversIfNeeded(offerData);
const tracks = new Map<string, number>(Object.entries(offerData.data.tracksTypes));

this.addTransceiversIfNeeded(tracks);

await this.createAndSendOffer();
};
Expand Down

0 comments on commit 25f3355

Please sign in to comment.