Skip to content

Commit

Permalink
add ipv6 options
Browse files Browse the repository at this point in the history
  • Loading branch information
N7Remus authored Jan 7, 2025
1 parent ab87653 commit bfd5d96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
40 changes: 33 additions & 7 deletions src/MediaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ interface MetricsData {
}

export interface MediaServiceOptions {
ip: string;
ip?: string;
ip6?: string;
announcedIp?: string;
announcedIp6?: string;
initialAvailableOutgoingBitrate: number;
maxIncomingBitrate: number;
maxOutgoingBitrate: number;
Expand All @@ -88,8 +90,10 @@ export default class MediaService {
}

public closed = false;
public ip: string;
public ipv: string;
public ipv6: string;
public announcedIp?: string;
public announcedIp6?: string;
public initialAvailableOutgoingBitrate: number;
public maxIncomingBitrate: number;
public maxOutgoingBitrate: number;
Expand All @@ -101,7 +105,9 @@ export default class MediaService {

constructor({
ip,
ip6,
announcedIp,
announcedIp6,
initialAvailableOutgoingBitrate,
maxIncomingBitrate,
maxOutgoingBitrate,
Expand All @@ -113,8 +119,10 @@ export default class MediaService {
logger.debug('constructor()');

this.ip = ip;
this.ip6 = ip6;

if (announcedIp && announcedIp !== ip) this.announcedIp = announcedIp;
if (announcedIp6 && announcedIp6 !== ip6) this.announcedIp6 = announcedIp6;

this.initialAvailableOutgoingBitrate = initialAvailableOutgoingBitrate;
this.maxIncomingBitrate = maxIncomingBitrate;
Expand Down Expand Up @@ -167,17 +175,35 @@ export default class MediaService {
const worker = await mediasoup.createWorker(settings);
const workerData = worker.appData as unknown as WorkerData;

const webRtcServer = await worker.createWebRtcServer({
listenInfos: [ {
let options = {
listenInfos: []
};
if (this.ip)
options.listenInfos.push({
protocol: 'udp',
ip: this.ip,
announcedIp: this.announcedIp,
}, {
},
{
protocol: 'tcp',
ip: this.ip,
announcedIp: this.announcedIp,
} ]
});
});
};
if (this.ip6)
options.listenInfos.push({
protocol: 'udp',
ip: this.ip6,
announcedIp: this.announcedIp6,
},
{
protocol: 'tcp',
ip: this.ip6,
announcedIp: this.announcedIp6,
});
};

const webRtcServer = await worker.createWebRtcServer(options);

workerData.webRtcServer = webRtcServer;

Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/transportMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const createTransportMiddleware = ({
const routerData = router.appData as unknown as RouterData;
const transport = await router.createPipeTransport({
listenIp: {
ip: internal ? '127.0.0.1' : mediaService.ip,
announcedIp: internal ? undefined : mediaService.announcedIp
ip: internal ? '127.0.0.1' : (mediaService.ip || mediaService.ip6),
announcedIp: internal ? undefined : (mediaService.ip || mediaService.ip6)
},
enableSrtp: !internal,
enableSctp: true,
Expand Down
12 changes: 10 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ const showUsage = () => {
logger.debug(' The path to the key file used for socket.\n\n');
logger.debug(' --ip <ip> (required)');
logger.debug(' The IP address used to create mediasoup transports.\n\n');
logger.debug(' --ip6 <ip> (required)');
logger.debug(' The IPv6 address used to create mediasoup transports.\n\n');
logger.debug(' --announcedIp <ip> (optional, default: none)');
logger.debug(' The IP address to be announced to clients for mediasoup transports.\n\n');
logger.debug(' The IPv4 address to be announced to clients for mediasoup transports.\n\n');
logger.debug(' --announcedIp6 <ip> (optional, default: none)');
logger.debug(' The IPv6 address to be announced to clients for mediasoup transports.\n\n');
logger.debug(' --initialAvailableOutgoingBitrate <bitrate> (optional, default: 600000)');
logger.debug(' The initial available outgoing bitrate for mediasoup transports.\n\n');
logger.debug(' --maxIncomingBitrate <bitrate> (optional, default: 10000000)');
Expand Down Expand Up @@ -108,7 +112,9 @@ export const cancelDrain = () => {
cert = './certs/edumeet-demo-cert.pem',
key = './certs/edumeet-demo-key.pem',
ip,
ip6,
announcedIp,
announcedIp6,
initialAvailableOutgoingBitrate = 600000,
maxIncomingBitrate = 10000000,
maxOutgoingBitrate = 10000000,
Expand All @@ -127,13 +133,15 @@ export const cancelDrain = () => {
return process.exit(1);
}

logger.debug('Starting...', { listenPort, listenHost, ip, announcedIp });
logger.debug('Starting...', { listenPort, listenHost, ip, announcedIp, ip6, announcedIp6 });

interactiveServer(roomServerConnections, roomServers);

const mediaService = await MediaService.create({
ip,
ip6,
announcedIp,
announcedIp6,
initialAvailableOutgoingBitrate,
maxIncomingBitrate,
maxOutgoingBitrate,
Expand Down

0 comments on commit bfd5d96

Please sign in to comment.