Use IHostedService for Live TV

This commit is contained in:
Patrick Barron 2024-02-06 16:23:18 -05:00
parent 690e603b90
commit c9311c9e7e
3 changed files with 33 additions and 21 deletions

View File

@ -7,6 +7,7 @@ using System.Text;
using Emby.Server.Implementations.EntryPoints; using Emby.Server.Implementations.EntryPoints;
using Jellyfin.Api.Middleware; using Jellyfin.Api.Middleware;
using Jellyfin.LiveTv; using Jellyfin.LiveTv;
using Jellyfin.LiveTv.EmbyTV;
using Jellyfin.LiveTv.Extensions; using Jellyfin.LiveTv.Extensions;
using Jellyfin.MediaEncoding.Hls.Extensions; using Jellyfin.MediaEncoding.Hls.Extensions;
using Jellyfin.Networking; using Jellyfin.Networking;
@ -127,6 +128,7 @@ namespace Jellyfin.Server
services.AddHlsPlaylistGenerator(); services.AddHlsPlaylistGenerator();
services.AddLiveTvServices(); services.AddLiveTvServices();
services.AddHostedService<LiveTvHost>();
services.AddHostedService<AutoDiscoveryHost>(); services.AddHostedService<AutoDiscoveryHost>();
services.AddHostedService<PortForwardingHost>(); services.AddHostedService<PortForwardingHost>();
services.AddHostedService<NfoUserDataSaver>(); services.AddHostedService<NfoUserDataSaver>();

View File

@ -1,21 +0,0 @@
#pragma warning disable CS1591
using System.Threading.Tasks;
using MediaBrowser.Controller.Plugins;
namespace Jellyfin.LiveTv.EmbyTV
{
public sealed class EntryPoint : IServerEntryPoint
{
/// <inheritdoc />
public Task RunAsync()
{
return EmbyTV.Current.Start();
}
/// <inheritdoc />
public void Dispose()
{
}
}
}

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.LiveTv;
using Microsoft.Extensions.Hosting;
namespace Jellyfin.LiveTv.EmbyTV;
/// <summary>
/// <see cref="IHostedService"/> responsible for initializing Live TV.
/// </summary>
public sealed class LiveTvHost : IHostedService
{
private readonly EmbyTV _service;
/// <summary>
/// Initializes a new instance of the <see cref="LiveTvHost"/> class.
/// </summary>
/// <param name="services">The available <see cref="ILiveTvService"/>s.</param>
public LiveTvHost(IEnumerable<ILiveTvService> services)
{
_service = services.OfType<EmbyTV>().First();
}
/// <inheritdoc />
public Task StartAsync(CancellationToken cancellationToken) => _service.Start();
/// <inheritdoc />
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}