// Copyright (c) Arlo Godfrey. All Rights Reserved. // Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms. // See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information. using System; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using OwlCore.Remoting; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.BaseModels; using StrixMusic.Sdk.CoreModels; using StrixMusic.Sdk.MediaPlayback; namespace StrixMusic.Sdk.Plugins.CoreRemote { /// /// Wraps around an instance of an to enable controlling it remotely, or takes a remotingId to control another instance remotely. /// public sealed class RemoteCoreDevice : ICoreDevice { private MemberRemote _memberRemote; /// /// Creates a new instance of a . /// [JsonConstructor] public RemoteCoreDevice(string sourceCoreInstanceId, string id) { SourceCore = RemoteCore.GetInstance(sourceCoreInstanceId, RemotingMode.Client); Id = id; Name = string.Empty; _memberRemote = new MemberRemote(this, $"{sourceCoreInstanceId}.{nameof(RemoteCoreDevice)}.{id}", RemoteCoreMessageHandler.SingletonClient); } /// /// Creates a new instance of a . /// internal RemoteCoreDevice(ICoreDevice device) { SourceCore = RemoteCore.GetInstance(device.SourceCore.InstanceId, RemotingMode.Host); _memberRemote = new MemberRemote(this, $"{device.SourceCore.InstanceId}.{nameof(RemoteCoreDevice)}.{device.Id}", RemoteCoreMessageHandler.SingletonHost); Id = device.Id; Name = device.Name; } /// [RemoteProperty] public string Id { get; set; } /// [RemoteProperty] public string Name { get; set; } /// public ICoreTrackCollection? PlaybackQueue { get; set; } /// public ICoreTrack? NowPlaying { get; set; } /// public ICore SourceCore { get; set; } /// public bool IsActive { get; set; } /// public IPlayableBase? PlaybackContext { get; set; } /// public DeviceType Type { get; set; } /// public bool ShuffleState { get; set; } /// public RepeatState RepeatState { get; set; } /// public bool IsSeekAsyncAvailable { get; set; } /// public bool IsResumeAsyncAvailable { get; set; } /// public bool IsPauseAsyncAvailable { get; set; } /// public bool IsChangeVolumeAsyncAvailable { get; set; } /// public bool IsChangePlaybackSpeedAvailable { get; set; } /// public bool IsNextAsyncAvailable { get; set; } /// public bool IsPreviousAsyncAvailable { get; set; } /// public bool IsToggleShuffleAsyncAvailable { get; set; } /// public bool IsToggleRepeatAsyncAvailable { get; set; } /// public TimeSpan Position { get; set; } /// public PlaybackState PlaybackState { get; set; } /// public double Volume { get; set; } /// public double PlaybackSpeed { get; set; } /// public event EventHandler? NowPlayingChanged; /// public event EventHandler? IsActiveChanged; /// public event EventHandler? PlaybackContextChanged; /// public event EventHandler? ShuffleStateChanged; /// public event EventHandler? RepeatStateChanged; /// public event EventHandler? PositionChanged; /// public event EventHandler? PlaybackStateChanged; /// public event EventHandler? VolumeChanged; /// public event EventHandler? PlaybackSpeedChanged; /// public Task ChangePlaybackSpeedAsync(double speed, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// public Task ChangeVolumeAsync(double volume, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task NextAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task PauseAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task PreviousAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task ResumeAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// public Task SeekAsync(TimeSpan position, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task SwitchToAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task ToggleRepeatAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// A cancellation token that may be used to cancel the ongoing task. /// public Task ToggleShuffleAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } /// public ValueTask DisposeAsync() => new ValueTask(Task.Run(() => { _memberRemote.Dispose(); return Task.CompletedTask; })); } }