-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
DATABASE_URL = "postgresql://postgres:123456@localhost:5432/mediasoup" | ||
DATABASE_SYNC = 1 | ||
DATABASE_LOGGING = 1 | ||
|
||
PORT = 3000 | ||
|
||
MEDIASOUP_LOG_LEVEL = warn | ||
MEDIASOUP_LOG_TAGS = 'info ice dtls rtp srtp rtcp rtx bwe score simulcast svc sctp' | ||
MEDIASOUP_NUMBER_OF_WORKERS = 10 | ||
MEDIASOUP_RTC_MIN_PORT = 20000 | ||
MEDIASOUP_RTC_MAX_PORT = 40000 | ||
MEDIASOUP_MEDIA_CODECS = ' | ||
[ | ||
{ | ||
kind : "audio", | ||
mimeType : "audio/opus", | ||
clockRate : 48000, | ||
channels : 2 | ||
}, | ||
{ | ||
kind : "video", | ||
mimeType : "video/VP8", | ||
clockRate : 90000, | ||
parameters : | ||
{ | ||
"x-google-start-bitrate" : 1000 | ||
} | ||
}, | ||
{ | ||
kind : "video", | ||
mimeType : "video/VP9", | ||
clockRate : 90000, | ||
parameters : | ||
{ | ||
"profile-id" : 2, | ||
"x-google-start-bitrate" : 1000 | ||
} | ||
}, | ||
{ | ||
kind : "video", | ||
mimeType : "video/h264", | ||
clockRate : 90000, | ||
parameters : | ||
{ | ||
"packetization-mode" : 1, | ||
"profile-level-id" : "4d0032", | ||
"level-asymmetry-allowed" : 1, | ||
"x-google-start-bitrate" : 1000 | ||
} | ||
}, | ||
{ | ||
kind : "video", | ||
mimeType : "video/h264", | ||
clockRate : 90000, | ||
parameters : | ||
{ | ||
"packetization-mode" : 1, | ||
"profile-level-id" : "42e01f", | ||
"level-asymmetry-allowed" : 1, | ||
"x-google-start-bitrate" : 1000 | ||
} | ||
} | ||
]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import mediasoup, { type types } from 'mediasoup'; | ||
|
||
class MediasoupWorkerManager { | ||
workers: types.Worker[] = []; | ||
currentWorker = 0; | ||
|
||
async init() { | ||
const numWorkers = Number(process.env.MEDIASOUP_NUMBER_OF_WORKERS || '1'); | ||
|
||
for (let i = 0; i < numWorkers; ++i) { | ||
const worker = await mediasoup.createWorker({ | ||
logLevel: (process.env.MEDIASOUP_LOG_LEVEL || 'none') as any, | ||
logTags: (process.env.MEDIASOUP_LOG_TAGS || ' ').split(' ') as any, | ||
rtcMinPort: Number(process.env.MEDIASOUP_RTC_MIN_PORT), | ||
rtcMaxPort: Number(process.env.MEDIASOUP_RTC_MAX_PORT), | ||
}); | ||
|
||
worker.on('died', (e) => { | ||
console.error(e); | ||
}); | ||
|
||
this.workers.push(worker); | ||
} | ||
} | ||
|
||
getWorker() { | ||
const result = this.workers[this.currentWorker]; | ||
this.currentWorker += 1; | ||
if (this.currentWorker === this.workers.length) { | ||
this.currentWorker = 0; | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
export const mediasoupWorkerManager = new MediasoupWorkerManager(); |