Skip to content

Commit

Permalink
fix setcodec issue #110 (#111)
Browse files Browse the repository at this point in the history
Co-authored-by: Yohan Totting <[email protected]>
  • Loading branch information
Yohan Totting and tyohan authored Apr 21, 2024
1 parent b4557fb commit 91fefc5
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions packages/room/peer/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
)

const systemAudioCodecs =
RTCRtpSender.getCapabilities('audio')?.codecs || []
RTCRtpReceiver.getCapabilities('audio')?.codecs || []
const preferredAudioCodecs = []

if (stream.source === 'media' && systemAudioCodecs.length > 0) {
Expand All @@ -479,38 +479,28 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
audioCodec.toLowerCase()
) {
preferredAudioCodecs.push(systemAudioCodec)
systemAudioCodecs.splice(
systemAudioCodecs.indexOf(systemAudioCodec),
1
)
}
}
}
} else {
for (const systemAudioCodec of systemAudioCodecs) {
if (systemAudioCodec.mimeType === 'audio/red') {
preferredAudioCodecs.push(systemAudioCodec)
systemAudioCodecs.splice(
systemAudioCodecs.indexOf(systemAudioCodec),
1
)
}
}
for (const systemAudioCodec of systemAudioCodecs) {
if (systemAudioCodec.mimeType === 'audio/opus') {
preferredAudioCodecs.push(systemAudioCodec)
systemAudioCodecs.splice(
systemAudioCodecs.indexOf(systemAudioCodec),
1
)
}
}
}
}

// Add all remaining codecs
for (const audioCodec of systemAudioCodecs) {
preferredAudioCodecs.push(audioCodec)
if (!['audio/red', 'audio/opus'].includes(audioCodec.mimeType)) {
preferredAudioCodecs.push(audioCodec)
}
}

if (supportsSetCodecPreferences) {
Expand Down Expand Up @@ -555,7 +545,9 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {

if (videoTrack) {
const systemVideoCodecs =
RTCRtpSender.getCapabilities('video')?.codecs || []
RTCRtpReceiver.getCapabilities('video')?.codecs || []

console.log('systemVideoCodecs', systemVideoCodecs)

for (const videoCodec of config.media[type].videoCodecs) {
for (const systemVideoCodec of systemVideoCodecs) {
Expand All @@ -564,17 +556,18 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
videoCodec.toLowerCase()
) {
preferredCodecs.push(systemVideoCodec)
systemVideoCodecs.splice(
systemVideoCodecs.indexOf(systemVideoCodec),
1
)
}
}
}

console.log('preferredCodecs', preferredCodecs)

// Add all remaining codecs
for (const videoCodec of systemVideoCodecs) {
preferredCodecs.push(videoCodec)
if (!config.media[type].videoCodecs.includes(videoCodec.mimeType)) {
console.log('videoCodec', videoCodec)
preferredCodecs.push(videoCodec)
}
}

/** @type {RTCRtpTransceiverInit} */
Expand Down

0 comments on commit 91fefc5

Please sign in to comment.