.NET 10 solution for Ping, a Discord style chat app: Domain, Application and Infrastructure projects plus the Api host. SignalR for chat and presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible storage for attachments, and OIDC auth shared with the Musify Zitadel instance. Includes the Compose stack for local development.
28 lines
979 B
C#
28 lines
979 B
C#
using Livekit.Server.Sdk.Dotnet;
|
|
using Ping.Application.Contracts;
|
|
using Ping.Infrastructure.Configuration;
|
|
|
|
namespace Ping.Infrastructure.Services
|
|
{
|
|
public class CallTokenService(LiveKitConfiguration configuration) : ICallTokenService
|
|
{
|
|
public CallAccessToken CreateAccessToken(string roomName, string identity, string? displayName)
|
|
{
|
|
var token = new AccessToken(configuration.ApiKey, configuration.ApiSecret)
|
|
.WithIdentity(identity)
|
|
.WithName(displayName ?? identity)
|
|
.WithGrants(new VideoGrants
|
|
{
|
|
RoomJoin = true,
|
|
Room = roomName,
|
|
CanPublish = true,
|
|
CanSubscribe = true,
|
|
CanPublishData = true,
|
|
})
|
|
.WithTtl(TimeSpan.FromMinutes(configuration.TokenTtlMinutes));
|
|
|
|
return new CallAccessToken(token.ToJwt(), roomName);
|
|
}
|
|
}
|
|
}
|