Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const app = require('http').createServer();
const io = require('socket.io')(app);
const config = require('./config');
const mediasoup = require('mediasoup');
const port = config.server.port;
// Map of Room instances indexed by roomId.
const rooms = new Map();
app.listen(port, () => console.log(`MediaSoup server is listening on port ${port}!`));
// MediaSoup server
const mediaServer = mediasoup.Server({
numWorkers: null, // Use as many CPUs as available.
logLevel: config.mediasoup.logLevel,
logTags: config.mediasoup.logTags,
rtcIPv4: config.mediasoup.rtcIPv4,
rtcIPv6: config.mediasoup.rtcIPv6,
rtcAnnouncedIPv4: config.mediasoup.rtcAnnouncedIPv4,
rtcAnnouncedIPv6: config.mediasoup.rtcAnnouncedIPv6,
rtcMinPort: config.mediasoup.rtcMinPort,
rtcMaxPort: config.mediasoup.rtcMaxPort
});
// Handle socket connection and its messages
io.on('connection', (socket) => {
console.log('New socket connection:', socket.handshake.query);
// Used for mediaSoup room
if (process.env.RTC_ANNOUNCED_IPV4) {
// This is the external IP address that routes to the current
// instance. For cloud providers or Kubernetes, this
// will be a different address than the connected network
// interface will use.
msOptions.rtcAnnouncedIPv4 = process.env.RTC_ANNOUNCED_IPV4;
}
if (process.env.RTC_ANNOUNCED_IPV6) {
msOptions.rtcAnnouncedIPv6 = process.env.RTC_ANNOUNCED_IPV6;
}
if (process.env.LOG_LEVEL) {
console.log('Setting logLevel to', process.env.LOG_LEVEL)
msOptions.logLevel = process.env.LOG_LEVEL;
msOptions.logTags = [ 'info', 'ice', 'dlts', 'rtp', 'srtp', 'rtcp', 'rbe', 'rtx' ];
}
const ms = mediasoup.Server(msOptions);
const PUBLISHER_PEER = 'publisher';
const rooms = {};
const MEDIA_CODECS = [
{
kind : "audio",
name : "opus",
clockRate : 48000,
channels : 2,
parameters :
{
useinbandfec : 1
}
},
/*
// FIXME: Safari 11 doesn't suppport vp8, so we need just h264 for portability.
const mediasoup = require('mediasoup');
const readline = require('readline');
const colors = require('colors/safe');
const repl = require('repl');
const homer = require('./lib/homer');
const config = require('./config');
// mediasoup server.
const mediaServer = mediasoup.Server(
{
numWorkers : 1,
logLevel : config.mediasoup.logLevel,
logTags : config.mediasoup.logTags,
rtcIPv4 : config.mediasoup.rtcIPv4,
rtcIPv6 : config.mediasoup.rtcIPv6,
rtcAnnouncedIPv4 : config.mediasoup.rtcAnnouncedIPv4,
rtcAnnouncedIPv6 : config.mediasoup.rtcAnnouncedIPv6,
rtcMinPort : config.mediasoup.rtcMinPort,
rtcMaxPort : config.mediasoup.rtcMaxPort
});
// Do Homer stuff.
if (process.env.MEDIASOUP_HOMER_OUTPUT)
homer(mediaServer);
listen(options) {
this.options = options;
this.mediaServer = mediasoup.Server(options);
if(!this.webServer) {
this.startWebServer();
}
this.startSocketIoServer();
setTimeout(() => {
this.emit('listen');
}, 0);
return this;
}
constructor(options){
this.options = options;
this.ip = ip.address();
this.hostname = os.hostname();
this.connections = {};
this.start();
this.connections = {};
this.rooms = {};
this.roomsList = {};
this.mediaServer = mediasoup.Server(options);
}