mediasoup-client and adapter.js

262 views
Skip to first unread message

Vasil Pavlov

unread,
Sep 27, 2018, 6:37:30 AM9/27/18
to mediasoup
Hi,
I'm trying to integrate mediasoup with our angular application and I have found an issue with adapter.js and mediasoup-client. Basically adapter.js is throwing an exception "Track already exists" on every second call of getUserMedia. It took me a while to find the source, but it seems to be the adapter.js. I was able to isolate the issue in a simpler demo and then I have done this with the mediasoup-demo. To replicate just add "webrtc-adapter": "^6.4.0" to the app/package.json and add import 'webrtc-adapter'; to app/lib/index.jsx for example. Rebuild the demo and run it - you should see the exception "Track already exists" when setWebcamProducer is called on start up. It seems to be thrown from the addStream shims. I also believe that this is the same issue - https://github.com/versatica/mediasoup-client/issues/34. Please advice how this can be fixed (worked arround) and if the problem is in mediasoup-client or adapter.js.

Thanks

Iñaki Baz Castillo

unread,
Sep 27, 2018, 6:43:07 AM9/27/18
to medi...@googlegroups.com
Please, don't use webrtc-adapter in your app. mediasoup-client does
not require adapter. Even more, ugly things may happen.
mediasoup-client properly detects your browser and knows which API it
can use. Just remove adapter.js.
> --
> You received this message because you are subscribed to the Google Groups "mediasoup" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+...@googlegroups.com.
> To post to this group, send email to medi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mediasoup.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mediasoup/09f4ac68-0c60-4d76-8691-64acd60ab767%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Iñaki Baz Castillo
<i...@aliax.net>

Philipp Hancke

unread,
Sep 27, 2018, 6:49:01 AM9/27/18
to medi...@googlegroups.com
mediasoup-client relies on Chrome not throwing on
  pc.addStream(stream);
  pc.addStream(stream)
? That doesn't seem wise...

2018-09-27 12:42 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
Please, don't use webrtc-adapter in your app. mediasoup-client does
not require adapter. Even more, ugly things may happen.
mediasoup-client properly detects your browser and knows which API it
can use. Just remove adapter.js.
On Thu, 27 Sep 2018 at 12:37, Vasil Pavlov <viva.p...@gmail.com> wrote:
>
> Hi,
> I'm trying to integrate mediasoup with our angular application and I have found an issue with adapter.js and mediasoup-client. Basically adapter.js is throwing an exception "Track already exists" on every second call of getUserMedia. It took me a while to find the source, but it seems to be the adapter.js. I was able to isolate the issue in a simpler demo and then I have done this with the mediasoup-demo. To replicate just add "webrtc-adapter": "^6.4.0" to the app/package.json and add import 'webrtc-adapter'; to app/lib/index.jsx for example. Rebuild the demo and run it - you should see the exception "Track already exists" when setWebcamProducer is called on start up. It seems to be thrown from the addStream shims. I also believe that this is the same issue - https://github.com/versatica/mediasoup-client/issues/34. Please advice how this can be fixed (worked arround) and if the problem is in mediasoup-client or adapter.js.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "mediasoup" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+unsubscribe@googlegroups.com.

> To post to this group, send email to medi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mediasoup.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mediasoup/09f4ac68-0c60-4d76-8691-64acd60ab767%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Iñaki Baz Castillo
<i...@aliax.net>
--
You received this message because you are subscribed to the Google Groups "mediasoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+unsubscribe@googlegroups.com.

To post to this group, send email to medi...@googlegroups.com.
Visit this group at https://groups.google.com/group/mediasoup.

Vasil Pavlov

unread,
Sep 27, 2018, 6:56:28 AM9/27/18
to mediasoup
Wow that was fast :)

I know that mediasoup-client doesn't require adapter.js, but it would help if the two can work together. Adapter.js is widely used. In our case we used full mesh before trying mediasoup, we also want to preserve the full mesh for smaller sessions. That might be an adoption stopper for other projects as well.

I also have a follow up question: Is it possible to share a camera and a screen at the same time. I'm pretty sure it is, but some sample or guidelines could help, especially if we should remove adapter.js. 

Anyway thanks for the blazing response.

Iñaki Baz Castillo

unread,
Sep 27, 2018, 7:05:04 AM9/27/18
to medi...@googlegroups.com
On Thu, 27 Sep 2018 at 12:49, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:
>
> mediasoup-client relies on Chrome not throwing on
> pc.addStream(stream);
> pc.addStream(stream)
> ? That doesn't seem wise...

Why should it throw?

NOTE: Yes, mediasoup-client still uses the old stream based API when
in Chrome. I need to update it for newer versions of Chrome.

Iñaki Baz Castillo

unread,
Sep 27, 2018, 7:08:19 AM9/27/18
to medi...@googlegroups.com
On Thu, 27 Sep 2018 at 12:56, Vasil Pavlov <viva.p...@gmail.com> wrote:
>
> Wow that was fast :)
>
> I know that mediasoup-client doesn't require adapter.js, but it would help if the two can work together. Adapter.js is widely used. In our case we used full mesh before trying mediasoup, we also want to preserve the full mesh for smaller sessions. That might be an adoption stopper for other projects as well.

Good point. Ok, as said in my email above, we need to upgrade the
mediasoup-client Chrome handler to stop using the old "WebRTC stream
based API". Once done, it should work with adapter.js.


> I also have a follow up question: Is it possible to share a camera and a screen at the same time. I'm pretty sure it is, but some sample or guidelines could help, especially if we should remove adapter.js.

You can create as many audio or video Producers as you wish. For
screen sharing, get the corresponding MediaStream, extract the video
track from it, and create a new Producer in your mediasoup-client app
with that video track. That's all.

Anyway, let's please open new email threads for different topics ;)

Philipp Hancke

unread,
Sep 27, 2018, 7:12:22 AM9/27/18
to medi...@googlegroups.com
2018-09-27 13:04 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
On Thu, 27 Sep 2018 at 12:49, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:
>
> mediasoup-client relies on Chrome not throwing on
>   pc.addStream(stream);
>   pc.addStream(stream)
> ? That doesn't seem wise...

Why should it throw?

It does in Firefox. Now if the specification had actually decided to specify the stuff that 95% of the developers use...
 

NOTE: Yes, mediasoup-client still uses the old stream based API when
in Chrome. I need to update it for newer versions of Chrome.

If you do a fully addTrack-based version of things adapter should disappear :-)
But that is a fairly high effort task.
 

--
Iñaki Baz Castillo
<i...@aliax.net>

--
You received this message because you are subscribed to the Google Groups "mediasoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+unsubscribe@googlegroups.com.
To post to this group, send email to medi...@googlegroups.com.
Visit this group at https://groups.google.com/group/mediasoup.

Iñaki Baz Castillo

unread,
Sep 27, 2018, 7:19:24 AM9/27/18
to medi...@googlegroups.com
On Thu, 27 Sep 2018 at 13:12, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:
>> Why should it throw?
>
> It does in Firefox.

Should everything that makes Firefox throw (or directly crash) become
part of the specification? XD


>> NOTE: Yes, mediasoup-client still uses the old stream based API when
>> in Chrome. I need to update it for newer versions of Chrome.
>
> If you do a fully addTrack-based version of things adapter should disappear :-)
> But that is a fairly high effort task.

Still don't know whether use the addTrack-based API or move to
transceivers and unified-plan stuff... HELP PLZ, how stable is what in
latest Chrome?

Philipp Hancke

unread,
Sep 27, 2018, 7:23:50 AM9/27/18
to medi...@googlegroups.com
2018-09-27 13:19 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
On Thu, 27 Sep 2018 at 13:12, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:
>> Why should it throw?
>
> It does in Firefox.

Should everything that makes Firefox throw (or directly crash) become
part of the specification? XD

Calling addStream twice with the same stream is silly :-p

>> NOTE: Yes, mediasoup-client still uses the old stream based API when
>> in Chrome. I need to update it for newer versions of Chrome.
>
> If you do a fully addTrack-based version of things adapter should disappear :-)
> But that is a fairly high effort task.

Still don't know whether use the addTrack-based API or move to
transceivers and unified-plan stuff... HELP PLZ, how stable is what in
latest Chrome?

adoption of addTransceiver is at 0.000076% of page loads.
 

--
Iñaki Baz Castillo
<i...@aliax.net>

--
You received this message because you are subscribed to the Google Groups "mediasoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+unsubscribe@googlegroups.com.
To post to this group, send email to medi...@googlegroups.com.
Visit this group at https://groups.google.com/group/mediasoup.

Iñaki Baz Castillo

unread,
Sep 27, 2018, 7:35:21 AM9/27/18
to medi...@googlegroups.com
On Thu, 27 Sep 2018 at 13:23, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:

> Calling addStream twice with the same stream is silly :-p

Why? Just ignore already handled tracks.


>> Still don't know whether use the addTrack-based API or move to
>> transceivers and unified-plan stuff... HELP PLZ, how stable is what in
>> latest Chrome?
>
> adoption of addTransceiver is at 0.000076% of page loads.

Yes. My concern is whether I should ove now to the track based API or
wait a bit and directly move to transceivers.

NOTE: mediasoup-client already uses the track based API in Firefox and
the transceivers API in Safari.

Philipp Hancke

unread,
Sep 27, 2018, 7:37:59 AM9/27/18
to medi...@googlegroups.com
2018-09-27 13:35 GMT+02:00 Iñaki Baz Castillo <i...@aliax.net>:
On Thu, 27 Sep 2018 at 13:23, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:

> Calling addStream twice with the same stream is silly :-p

Why? Just ignore already handled tracks.

I'd rather not enourage developers to do silly things :-p
 

>> Still don't know whether use the addTrack-based API or move to
>> transceivers and unified-plan stuff... HELP PLZ, how stable is what in
>> latest Chrome?
>
> adoption of addTransceiver is at 0.000076% of page loads.

Yes. My concern is whether I should ove now to the track based API or
wait a bit and directly move to transceivers.

NOTE: mediasoup-client already uses the track based API in Firefox and
the transceivers API in Safari.

Have you tried using your Firefox code in Chrome? That might be low-effort even :-)
 

--
Iñaki Baz Castillo
<i...@aliax.net>

--
You received this message because you are subscribed to the Google Groups "mediasoup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+unsubscribe@googlegroups.com.
To post to this group, send email to medi...@googlegroups.com.
Visit this group at https://groups.google.com/group/mediasoup.

Iñaki Baz Castillo

unread,
Sep 27, 2018, 7:50:41 AM9/27/18
to medi...@googlegroups.com
On Thu, 27 Sep 2018 at 13:38, 'Philipp Hancke' via mediasoup
<medi...@googlegroups.com> wrote:
>> Why? Just ignore already handled tracks.
>
> I'd rather not enourage developers to do silly things :-p


navigator.mediaDevices.getUserMedia({ audio: true })
.then((stream) =>
{
const track = stream.getAudioTracks()[0];

stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);
stream.addTrack(track);

console.log(stream.getTracks());
});


It prints: `[MediaStreamTrack]`, this is, a single track.




>> Yes. My concern is whether I should ove now to the track based API or
>> wait a bit and directly move to transceivers.
>>
>> NOTE: mediasoup-client already uses the track based API in Firefox and
>> the transceivers API in Safari.
>
>
> Have you tried using your Firefox code in Chrome? That might be low-effort even :-)

Will do :)

Iñaki Baz Castillo

unread,
Sep 27, 2018, 11:33:28 AM9/27/18
to medi...@googlegroups.com
Hi, mediasoup-client 2.1.4 has been released with a new handler for
Chrome >= 69 that uses the WebRTC track based API instead of the old
stream based API.

Not sure if this will avoid the original issue in this thread when
working with adapter.js. Can you please check?

Vasil Pavlov

unread,
Sep 28, 2018, 2:43:16 AM9/28/18
to mediasoup
Hi,
I have updated mediasoup-client to version 2.1.4 and the issue is solved! So for now I can confirm mediasoup-client 2.1.4 and webrtc-adapter can work together. I will write if I stumble in any other issues.

Thanks for the quick reaction!

Christoph Eggert

unread,
Sep 28, 2018, 3:36:10 AM9/28/18
to mediasoup
This is great news! I had to modify my adapter.js versions so far and am glad to hear it can work out of the box now, makes update processes much less problematic. 

Thanks for the ping as well. 

Iñaki Baz Castillo

unread,
Sep 28, 2018, 7:07:04 AM9/28/18
to medi...@googlegroups.com
Nice :)
> --
> You received this message because you are subscribed to the Google Groups "mediasoup" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+...@googlegroups.com.
> To post to this group, send email to medi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mediasoup.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mediasoup/83e4678c-e416-413c-9d6f-edeed42dc4c0%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



mkh

unread,
May 11, 2019, 9:32:46 AM5/11/19
to mediasoup
Please, don't use webrtc-adapter in your app. mediasoup-client does 
not require adapter. Even more, ugly things may happen. 
mediasoup-client properly detects your browser and knows which API it 
can use. Just remove adapter.js.

Is it still advised to not use adapter.js in mediasoup-client v3?

Iñaki Baz Castillo

unread,
May 12, 2019, 1:22:36 PM5/12/19
to medi...@googlegroups.com
No idea. It may work or not. Just avoid it if possible.
> --
> You received this message because you are subscribed to the Google Groups "mediasoup" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mediasoup+...@googlegroups.com.
> To post to this group, send email to medi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mediasoup.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mediasoup/6453641a-1474-4862-baf7-470d841cb6ed%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages