Problem with mediasoup-client load

Hey there…
I have a problem with the mediasoup-client device.load while providing routerRtpCapabilities. I got router capabilities with socket.io and passing it to the device.load and got caps in not an object error.

After read of code, i found that the parameter passed is undefined in the load function. As the parameter is not getting the real value of the capabilities.

Please help me to solve this.

1 Like

We don’t know your problem, sorry. Inspect the routerRtpParameters you are passing to load() method. Do your homework please.

Have you resolved this?I am also in this problem!Please help me!

Sorry guys, you don’t even paste a single log.

@lzxysf i just got the same problem and after reading and debugging the mediasoup client code… I just solved the error…

You just need to create an javascript object…

var caps = { rtpCapabilities: [data]};
await device.load({caps});

Change data with your capabilities received from another side…

thanks your answer,but the problem again.
My code is
const rtpCapabilities = JSON.parse(rtpCapabilities_json);
console.log(rtpCapabilities);
var caps = {rtpCapabilities: rtpCapabilities};
await device.load(caps);

Or you can visit https://lishifu.work/mediasoup/main.html and pressF12 to see the problem.thanks very much

It shows connected…

what?Do it works?

Yesss

I know, here should be routerRtpCapabilities:yourreceive,the rtpCapabilities can not get.

Just create another JS object like this

var cap = {routerRtpCapabilities: rtpCapabilities};
device.load({cap});

2 Likes

Still issues loading device.

After a lot of work, and the helpful comments here I got this working using the following code (simplified);

ws.onmessage = async function(e) {
  var capsInExpandedJSOBject =  {routerRtpCapabilities:JSON.parse(e.data)};
  device.load(capsInExpandedJSOBject);
};

The problem is, although I am not seeing any errors, and the object seems built correctly, Device.loaded returns false, so accessing any of those values is not possible.

Again, I ask for help, if this takes much longer I’m going to be forced to ditch media-soup as a platform and go for a simpler solution.

I did solve this eventually, I’m new to JS and haven’t used Async functions before in js. This was an issue with waiting for the device to load before doing the later stuffs, completely my fault and not mediasoup related.

did u resolve this?