Skip to content

The mediasoup cluster can be expanded in horizontally and vertically, serving unlimited clients

License

Notifications You must be signed in to change notification settings

woody146/mediasoup-cluster

Repository files navigation

Mediasoup cluster

Cluster uses PostgreSQL server to save data of slave servers

                                                           +----------------+
        +-----------------+          webrtc                |  slave server  |
        | producer client |------------------------------->|  for producer  |
        +-----------------+                                +----------------+
                  |                                             ^      |
                  |                +---------------+            |      |
                  +--------------->|               |------------+      | mediasoup
                       http        | master server |   http            |   pipe
                  +--------------->|               |------------+      | transport
                  |                +---------------+            |      |
                  |                                             v      v
                  |                                        +----------------+
        +-----------------+                                |  slave server  |
        | consumer client |<-------------------------------|  for consumer  |
        +-----------------+         webrtc                 +----------------+

Quickstart

Build code (must use node v18+)

npm install
npm run build

Copy env.dev file to .env

cp .env.dev .env

Update config in .env file. Detail in example

// your PostgreSQL server info
DATABASE_URL = "postgresql://postgres:123456@localhost:5432/mediasoup"
...
// your ip in internet network
// https://mediasoup.org/documentation/v3/mediasoup/api/#TransportListenIp
MEDIASOUP_WEBRTC_TRANSPORT_LISTEN_IPS = '[
   {
      "ip": "192.168.6.143",
      "announcedIp": null
   }
]'

Create a master server

npm run start:master

Create a slave server to produce

npm run start:slave:producer

Create a slave server to consume

npm run start:slave:consumer

Run demo app

cd examples/rooms/
npm install
npm run dev

Then, navigate to https://localhost:4430

Documentation

Master server API

Method Path Request Response
For producer client
POST /rooms
create room
POST /rooms/:roomId/producer_transports
create producer transport
  • userId: string
POST /producer_transports/:transportId/connect
make transport connect
POST /producer_transports/:transportId/produce
make transport produce
  • id: producer id
POST /producers/:producerId/pause
pause producer
POST /producers/:producerId/resume
resume producer
DELETE /rooms/:roomId
delete the room if no one is in the room
For consumer client
GET /rooms/:roomId/producer_transports
get producer transport list
  • items: array of objects
    • id: transport id
    • userId: user id
    • producers: { id: string; kind: string }[]
POST /rooms/:roomId/consumer_routers
get or create router in this room
  • userId: string
POST /rooms/:roomId/consumer_transports
create consumer transport
  • userId: string
POST /router/:routerId/consumer_transports
create consumer transport
  • userId: string
POST /consumer_transports/:transportId/connect
make transport connect
POST /consumer_transports/:transportId/consume
make transport consume
  • id: consumer id
POST /consumers/:consumerId/resume
make consumer resume after connected
Utils
POST /user/:userId/logout
make user logout
  • roomId?: string
DELETE /transports/:transportId
close producer or consumer transport
GET /rooms
get room list in system
  • page?: number
  • pageSize?: number
  • orderBy?: string
  • items: room objects
    • id: string
    • createDate: Date
  • pagination
    • page: number
    • pageSize: number
    • total: number
GET /rooms/:roomId
get room detail

License

mediasoup-cluster is MIT Licensed.

About

The mediasoup cluster can be expanded in horizontally and vertically, serving unlimited clients

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published