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

Enable Opus DTX for audio tracks #74

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions app/utils/rxjs/RxjsPeer.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ export class RxjsPeer {
async createSession(peerConnection: RTCPeerConnection) {
console.debug('🆕 creating new session')
const { apiBase } = this.config
// create an offer and set it as the local description
await peerConnection.setLocalDescription(await peerConnection.createOffer())
// create an offer
const offer = await peerConnection.createOffer()
// Turn on Opus DTX to save bandwidth
offer.sdp = offer.sdp!.replace('useinbandfec=1', 'usedtx=1;useinbandfec=1')
nils-ohlmeier marked this conversation as resolved.
Show resolved Hide resolved
// And set the offer as the local description
await peerConnection.setLocalDescription(offer)
const { sessionId, sessionDescription } =
await this.fetchWithRecordedHistory(`${apiBase}/sessions/new?SESSION`, {
method: 'POST',
body: JSON.stringify({
sessionDescription: peerConnection.localDescription,
sessionDescription: offer,
}),
}).then((res) => res.json() as any)
const connected = new Promise((res, rej) => {
Expand Down Expand Up @@ -236,13 +240,19 @@ export class RxjsPeer {
pushedTrackPromise = this.pushTrackDispatcher
.doBulkRequest({ trackName, transceiver }, (tracks) =>
this.taskScheduler.schedule(async () => {
await peerConnection.setLocalDescription(
await peerConnection.createOffer()
// create an offer
const offer = await peerConnection.createOffer()
// Turn on Opus DTX to save bandwidth
offer.sdp = offer.sdp!.replace(
nils-ohlmeier marked this conversation as resolved.
Show resolved Hide resolved
'useinbandfec=1',
'usedtx=1;useinbandfec=1'
)
// And set the offer as the local description
await peerConnection.setLocalDescription(offer)

const requestBody = {
sessionDescription: {
sdp: peerConnection.localDescription?.sdp,
sdp: offer.sdp,
type: 'offer',
},
tracks: tracks.map(({ trackName, transceiver }) => ({
Expand Down