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

[RTC-556] Only set turn servers once #51

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/webrtc/webRTCEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,7 @@ export class WebRTCEndpoint<
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 @@ -1482,8 +1475,11 @@ export class WebRTCEndpoint<
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 (
Expand Down Expand Up @@ -1513,7 +1509,11 @@ export class WebRTCEndpoint<
}
});

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

this.addTransceiversIfNeeded(tracks);

await this.createAndSendOffer();
};
Expand Down
Loading