Skip to content

Commit

Permalink
Don't create data channel of publisher until sending data message (#1118
Browse files Browse the repository at this point in the history
)

* Don't create data channel of publisher until sending data message

* typo

* spell

* check protocol version
  • Loading branch information
cnderrauber authored May 6, 2024
1 parent fdfb7b3 commit 0586b09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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 @@ -436,7 +436,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 @@ -1116,11 +1118,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 @@ -1181,6 +1193,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 @@ -1391,3 +1411,7 @@ export type EngineEventCallbacks = {
remoteMute: (trackSid: string, muted: boolean) => void;
offline: () => void;
};

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

0 comments on commit 0586b09

Please sign in to comment.