Hi! I’m trying to use a Router that handles all default codecs supported by mediasoup; for this, the docs are not too explicit (or I’m blind and didn’t see it) because they always show examples where some specific codecs are passed to worker.createRouter(RouterOptions)
, but I wasn’t able to find some example where no codecs are specified (“use everything you can”)
First attempt: worker.createRouter({})
So first I saw that RouterOptions.mediaCodecs
is optional, but RouterOptions itself is required in worker.createRouter(RouterOptions)
, hence I pass an empty object:
let router = await worker.createRouter({});
This doesn’t work; what it does is the same as if an empty array had been passed, i.e. it is equivalent to this:
let router = await worker.createRouter({ mediaCodecs: [] });
which means the opposite of what I wanted: now mediasoup is configured to work without any codec.
This causes an error later down the way, while trying to produce on some transport:
mediasoup:Transport produce()
mediasoup:Channel request() [method:transport.produce, id:4]
mediasoup:ERROR:Channel [pid:75547 RTC::RtpParameters::RtpParameters() | throwing MediaSoupTypeError: empty codecs
mediasoup:ERROR:Channel [pid:75547 Worker::OnChannelRequest() | throwing MediaSoupTypeError: empty codecs [method:transport.produce]
mediasoup:WARN:Channel request failed [method:transport.produce, id:4]: [method:transport.produce]
Notice the error: empty codecs.
- Q: Is that how it should work? I expected that the
mediaCodecs
field is not required precisely to be able to not restrict the set of codecs used by mediasoup. If this is however working as expected, maybe a line in the docs could be helpful to clarify that.
Second attempt: getSupportedRtpCapabilities()
I found this function, so now I’m trying to call
worker.createRouter({
mediaCodecs: Mediasoup.getSupportedRtpCapabilities().codecs
});
but it throws an error:
mediasoup:Worker createRouter()
TypeError: duplicated codec.preferredPayloadType: 13
(the original code doesn’t print the problematic value, that’s something I added to the .js)
Fair enough, as I know the default capabilities come with some repeated PTs.
However, removing all preferredPayloadType
fields also causes the same error, with the same PT number:
worker.createRouter({
mediaCodecs: Mediasoup.getSupportedRtpCapabilities().codecs?.map((c) => {
delete c.preferredPayloadType;
return c;
})
});
mediasoup:Worker createRouter()
TypeError: duplicated codec.preferredPayloadType: 13
(and the resulting object doesn’t contain any PTs, I verified)
So this also doesn’t work
- Q: Is there a recommended way to tell mediasoup “just use everything” instead of having to be explicit about the codecs that should be used? Is it maybe considered a bad practice to do so?
Thanks