Skip to content

Commit

Permalink
fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
N7Remus authored Jan 7, 2025
1 parent 765f830 commit ab30f2a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
68 changes: 38 additions & 30 deletions src/MediaService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as mediasoup from 'mediasoup';
import { Router } from 'mediasoup/node/lib/Router';
import { Consumer } from 'mediasoup/node/lib/Consumer';
import { Transport } from 'mediasoup/node/lib/Transport';
import { Transport, TransportListenInfo } from 'mediasoup/node/lib/Transport';
import { RtpHeaderExtension } from 'mediasoup/node/lib/RtpParameters';
import {
Worker,
Expand Down Expand Up @@ -90,8 +90,8 @@ export default class MediaService {
}

public closed = false;
public ip: string;
public ip6: string;
public ip: string | undefined;
public ip6: string | undefined;
public announcedIp?: string;
public announcedIp6?: string;
public initialAvailableOutgoingBitrate: number;
Expand All @@ -118,8 +118,10 @@ export default class MediaService {
}: MediaServiceOptions) {
logger.debug('constructor()');

this.ip = ip;
this.ip6 = ip6;
if (ip)
this.ip = ip;
if (ip6)
this.ip6 = ip6;

if (announcedIp && announcedIp !== ip) this.announcedIp = announcedIp;
if (announcedIp6 && announcedIp6 !== ip6) this.announcedIp6 = announcedIp6;
Expand Down Expand Up @@ -175,33 +177,39 @@ export default class MediaService {
const worker = await mediasoup.createWorker(settings);
const workerData = worker.appData as unknown as WorkerData;

let options = {
const options: { listenInfos: Array<TransportListenInfo> } = {
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,
});
};

if (this.ip) {
options.listenInfos.push(
{
protocol: 'udp',
ip: this.ip,
announcedIp: this.announcedIp || undefined, // Ensure announcedIp is undefined if not provided
},
{
protocol: 'tcp',
ip: this.ip,
announcedIp: this.announcedIp || undefined,
}
);
}

if (this.ip6) {
options.listenInfos.push(
{
protocol: 'udp',
ip: this.ip6,
announcedIp: this.announcedIp6 || undefined,
},
{
protocol: 'tcp',
ip: this.ip6,
announcedIp: this.announcedIp6 || undefined,
}
);
}

const webRtcServer = await worker.createWebRtcServer(options);

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 || mediaService.ip6),
announcedIp: internal ? undefined : (mediaService.ip || mediaService.ip6)
ip: internal ? '127.0.0.1' : (mediaService.ip || mediaService.ip6 || '127.0.0.1'),
announcedIp: internal ? undefined : (mediaService.announcedIp || mediaService.announcedIp6)
},
enableSrtp: !internal,
enableSctp: true,
Expand Down

0 comments on commit ab30f2a

Please sign in to comment.