Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create data channel of publisher until sending data message #1118

Merged
merged 4 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/clean-gifts-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Don't create data channel of publisher until sending data message
26 changes: 25 additions & 1 deletion src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
this.emit(EngineEvent.MediaTrackAdded, ev.track, ev.streams[0], ev.receiver);
};

this.createDataChannels();
if (!supportOptionalDatachannel(joinResponse.serverInfo?.protocol)) {
this.createDataChannels();
}
}

private setupSignalClientCallbacks() {
Expand Down Expand Up @@ -1100,11 +1102,21 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
throw new ConnectionError(`${transportName} connection not set`);
}

let needNegotiation = false;
if (!subscriber && !this.dataChannelForKind(kind, subscriber)) {
this.createDataChannels();
needNegotiation = true;
}

if (
!needNegotiation &&
!subscriber &&
!this.pcManager.publisher.isICEConnected &&
this.pcManager.publisher.getICEConnectionState() !== 'checking'
) {
needNegotiation = true;
}
if (needNegotiation) {
// start negotiation
this.negotiate();
}
Expand Down Expand Up @@ -1165,6 +1177,14 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
}

this.pcManager.requirePublisher();
// don't negotiate without any transceivers or data channel, it will generate sdp without ice frag then negotiate failed
if (
this.pcManager.publisher.getTransceivers().length == 0 &&
!this.lossyDC &&
!this.reliableDC
) {
this.createDataChannels();
}

const abortController = new AbortController();

Expand Down Expand Up @@ -1374,3 +1394,7 @@ export type EngineEventCallbacks = {
remoteMute: (trackSid: string, muted: boolean) => void;
offline: () => void;
};

function supportOptionalDatachannel(protocol: number | undefined): boolean {
return protocol !== undefined && protocol > 13;
}
Loading