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 +----------------+
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
Method | Path | Request | Response |
---|---|---|---|
For producer client | |||
POST | /rooms create room |
|
|
POST | /rooms/:roomId/producer_transports create producer transport |
|
|
POST | /producer_transports/:transportId/connect make transport connect |
||
POST | /producer_transports/:transportId/produce make transport produce |
|
|
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 |
|
|
POST | /rooms/:roomId/consumer_routers get or create router in this room |
|
|
POST | /rooms/:roomId/consumer_transports create consumer transport |
|
|
POST | /router/:routerId/consumer_transports create consumer transport |
|
|
POST | /consumer_transports/:transportId/connect make transport connect |
||
POST | /consumer_transports/:transportId/consume make transport consume |
|
|
POST | /consumers/:consumerId/resume make consumer resume after connected |
||
Utils | |||
POST | /user/:userId/logout make user logout |
|
|
DELETE | /transports/:transportId close producer or consumer transport |
||
GET | /rooms get room list in system |
|
|
GET | /rooms/:roomId get room detail |
|
mediasoup-cluster is MIT Licensed.