Skip to content

Commit

Permalink
Complete linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
feast107 committed Nov 11, 2024
1 parent e2b2aed commit dde2288
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public static IServiceCollection AddMediasoup<T>(this IServiceCollection service
.AddSingleton<Mediasoup>();
return services;
}

private static void Correct<T>(this WorkerSettings<T> options)
{
options.Apply(MediasoupOptionsContext<T>.Default.WorkerSettings.NotNull());
}

private static void Correct<T>(this RouterOptions<T> options)
{
foreach (var codec in options.MediaCodecs.Where(static m => m.Parameters != null))
Expand All @@ -49,20 +50,23 @@ private static void Correct<T>(this RouterOptions<T> options)
}
}
}

private static void Correct<T>(this WebRtcServerOptions<T> options)
{
options.ListenInfos = options.ListenInfos.Correct();
}

private static void Correct<T>(this WebRtcTransportOptions<T> options)
{
options.ListenInfos = options.ListenInfos.Correct();
}

private static void Correct<T>(this PlainTransportOptions<T> options)
{
options.Apply(MediasoupOptionsContext<T>.Default.PlainTransportOptions.NotNull());
options.ListenInfo.Correct();
}

private static ListenInfoT[] Correct(this ListenInfoT[] listenInfos)
{
foreach (var listenInfo in listenInfos)
Expand All @@ -72,9 +76,12 @@ private static ListenInfoT[] Correct(this ListenInfoT[] listenInfos)

if (listenInfos.Length != 0) return listenInfos;

var create = AddressFamily.InterNetwork.GetLocalIPAddresses()
.Where(static m => !Equals(m, IPAddress.Loopback))
.Select(x => x.ToString())
var create =
(Environment.GetEnvironmentVariable("MEDIASOUP_ANNOUNCED_IP") is { } announcedId
? (string[]) [announcedId]
: AddressFamily.InterNetwork.GetLocalIPAddresses()
.Where(static m => !Equals(m, IPAddress.Loopback))
.Select(x => x.ToString()))
.SelectMany(static x => (ListenInfoT[])
[
new ListenInfoT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\Antelcat.MediasoupSharp.AspNetCore\Antelcat.MediasoupSharp.AspNetCore.csproj"/>
<ProjectReference Include="..\Antelcat.MediasoupSharp.runtime\Antelcat.MediasoupSharp.runtime.linux-x64.csproj" />
<ProjectReference Include="..\Antelcat.MediasoupSharp.runtime\Antelcat.MediasoupSharp.runtime.win-x64.csproj"/>
</ItemGroup>

Expand Down
26 changes: 1 addition & 25 deletions src/Antelcat.MediasoupSharp.Demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
FROM ubuntu:22.04 as build

RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
RUN apt-get clean
RUN apt-get update

RUN apt-get install -y build-essential
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y curl
RUN apt-get install -y git
RUN curl -fsSL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt-get install -y nodejs
RUN apt-get clean

WORKDIR /build

COPY package.json package.json

RUN npm install

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
COPY . .
COPY --from=build /build/node_modules/mediasoup/worker/out/Release/mediasoup-worker ./runtimes/linux-x64/native/

EXPOSE 80

ENTRYPOINT ["dotnet", "Antelcat.MediasoupSharp.Demo.dll"]
2 changes: 0 additions & 2 deletions src/Antelcat.MediasoupSharp.Demo/MediasoupOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Antelcat.MediasoupSharp.AspNetCore;
using FBS.RtpParameters;
using FBS.Transport;

namespace Antelcat.MediasoupSharp.Demo;

Expand Down
4 changes: 3 additions & 1 deletion src/Antelcat.MediasoupSharp.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async Task RunMediasoupWorkersAsync()

var useWebRtcServer = Environment.GetEnvironmentVariable("MEDIASOUP_USE_WEBRTC_SERVER") != "false";

Console.WriteLine(new AppSerialization().Serialize(options));
foreach (var task in Mediasoup.CreateWorkers(options.WorkerSettings.NotNull(), options.NumWorkers.NotNull()))
{
var worker = await task;
Expand Down Expand Up @@ -377,7 +378,8 @@ public AppSerialization()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true
};
foreach (var converter in Mediasoup.JsonConverters) options.Converters.Add(converter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Antelcat.MediasoupSharp.Demo/mediasoup.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
"protocol": "udp",
"ip": "0.0.0.0",
"announcedAddress": null,
"port": 40044
"port": 44444
},
{
"protocol": "tcp",
"ip": "0.0.0.0",
"announcedAddress": null,
"port": 40044
"port": 44444
}
]
},
Expand Down

0 comments on commit dde2288

Please sign in to comment.