public PlaybackService( WebApiManager webApiManager, WebPlaybackSdkManager webPlaybackSdkManager, MediaSessionManager mediaSessionManager, AuthorizationService spotifyServiceAuth, SpotifyServiceConfiguration spotifyServiceConfiguration) { dispatcher = webApiManager; player = webPlaybackSdkManager; mediaSession = mediaSessionManager; auth = spotifyServiceAuth; config = spotifyServiceConfiguration; PlaybackChanged += OnDevicePotentiallyChanged; PlaybackChanged += mediaSession.SetMetadata; auth.AuthStateChanged += OnReInitializationPotenitallyNeeded; playbackContextPollingTimer = new( callback : async _ => { if (await auth.IsUserLoggedIn()) { await FirePlaybackContextChanged(await GetPlayback()); } }, state : null, dueTime : 0, period : 1000); playbackUpdateTimer = new( callback : async _ => { if (await auth.IsUserLoggedIn()) { PlaybackDisplayUpdate?.Invoke(GetProgressMs()); } }, state : null, dueTime : 0, period : 33); int playbackKeepAliveTimerPeriod = Convert.ToInt32(TimeSpan.FromMinutes(1).TotalMilliseconds); playbackKeepAliveTimer = new( callback : async _ => { if (await auth.IsUserLoggedIn()) { await KeepPlaybackAlive(); } }, state : null, dueTime : playbackKeepAliveTimerPeriod, period : playbackKeepAliveTimerPeriod); }
public AuthorizationService( WebApiManager webApiManager, AuthManagerBase authManagerBase, SpotifyServiceConfiguration spotifyServiceConfiguration) { dispatcher = webApiManager; authManager = authManagerBase; config = spotifyServiceConfiguration; authPollingTimer = new( callback : async _ => { await HandleAuthStatePotentiallyChanged(); }, state : null, dueTime : 1000, period : 1000); }
public AuthorizationCodeAuthManager(ILocalStorage localStorage, NavigationManager navigatorManager, SpotifyServiceConfiguration configuration) : base(localStorage, navigatorManager) { this.configuration = configuration; }
/// <summary> /// Extension method to register a SpotifyService and all its dependecies. /// </summary> public static IServiceCollection AddSpotify(this IServiceCollection services, SpotifyServiceConfiguration configuration) { // LocalStorage services.AddStorage(); // IndexedDB services.AddIndexedDB(dbStore => { dbStore.DbName = nameof(SpotifyService); dbStore.Version = 4; var stores = new List <string>() { nameof(SavedTrack), nameof(TrackAudioFeatures), nameof(AudioFeaturesManager), nameof(Web.ViewModels.Sections) }; foreach (var name in stores) { dbStore.Stores.Add(new StoreSchema { Name = name, PrimaryKey = new IndexSpec { Auto = true } }); } }); // "Blazor WebAssembly apps don't currently have a concept of DI scopes. Scoped-registered services behave like Singleton services." <see ref="https://docs.microsoft.com/en-us/aspnet/core/blazor/dependency-injection?view=aspnetcore-3.1"/> services.AddScoped <SpotifyServiceConfiguration>(_ => configuration); services.AddScoped <Api>(); services.AddScoped <IndexedDbCache <SavedTrack> >(); services.AddScoped <SavedTrackManager>(); services.AddScoped <IndexedDbCache <TrackAudioFeatures> >(); services.AddScoped <IndexedDbCache <string> >(); services.AddScoped <AudioFeaturesManager>(); if (configuration.AuthServerApiBase is null) { services.AddScoped <AuthManagerBase, ImplicitGrantAuthManager>(); } else { services.AddScoped <AuthManagerBase, AuthorizationCodeAuthManager>(); } services.AddScoped <WebApiManager>(); services.AddScoped <WebPlaybackSdkManager>(); services.AddScoped <MediaSessionManager>(); // The dependency injection module will take care of the Dispose() calls services.AddScoped <AuthorizationService>(); services.AddScoped <PlaybackService>(); services.AddScoped <UserService>(); services.AddScoped <ContextsService>(); services.AddScoped <ExploreService>(); services.AddScoped <LibraryService>(); services.AddScoped <SpotifyService>(); return(services); }