How do I use mediasoup-client with TypeScript and bundlers?

I already used mediasoup-client with JS and it worked fine.

Now I’m transitioning to TypeScript and am currently using browserify as my bundler, but I’m not set on it and would probably prefer snowpack if possible.

Unfortunately I was unable to find any TypeScript mediasoup-client examples.

How would I import mediasoup-client properly given these requirements?

  • Actually transpiles (no errors)
  • Type hints in the IDE
  • Import classes separately (new Device() instead of new mediasoup.Device())

The documentation does not match these requirements, so I’ve tried the following variants:

import {DataConsumer} from 'mediasoup-client'
import {DataConsumer} from 'mediasoup-client/src/types'
import {DataConsumer} from 'mediasoup-client/src/DataConsumer'
import {DataConsumer} from 'mediasoup-client/lib/DataConsumer'

And errors ranged from

SyntaxError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’

to

Error TS2305: Module ‘“./node_modules/mediasoup-client/lib”’ has no exported member ‘DataConsumer’

and

[snowpack] Package “mediasoup-client/src/DataConsumer” not found. Have you installed it?

Regarding snowpack: Is mediasoup-client an ES-Module?

Ideally I would like to bundle mediasoup-client separately from my package, but for now I only want it to work at all.

1 Like

hi,i am learning how to use mediasoup-client with JS,i donot know to get “my-signaling” as below.
import { Device } from ‘mediasoup-client’;
import mySignaling from ‘./my-signaling’; // Our own signaling stuff.
could please show me an example? thanks!!!
my email is:25650944@qq.com

First of all, you should not ask a question unrelated to the topic of a thread. Please keep it organized.

Now, to answer your question:
You need to implement the signaling yourself, using whatever thechnology you want - that’s why the import refers to “my-signaling” - it’s just an example / placeholder.

mediasoup-client does not cover signaling, since it is not part of WebRTC. Usually WebSockets are used for signaling, but other methods may be just as good.

To get started have a look at the demos (I’d recommend this single-page one)

1 Like