public BackgroundSongController( IGetLocalHubUrlService getLocalHubUrlService, IYTMusicPlayerService ytMusicPlayerService) { _getLocalHubUrlService = getLocalHubUrlService; _ytMusicPlayerService = ytMusicPlayerService; }
public ApiSignalRService( IConfigService configService, ISecretService secretService, IYTMusicPlayerService ytMusicPlayerService, IClientTriggerClient clientTriggerClient ) { _ytMusicPlayerService = ytMusicPlayerService; _clientTriggerClient = clientTriggerClient; var baseUrl = configService.Get <string>("ApiBaseAddress"); _backgroundSongHubConnection = new HubConnectionBuilder() .WithUrl($"{baseUrl}{APIHubConstants.BackgroundSongHubPath}", options => { options.AccessTokenProvider = () => Task.FromResult(secretService.GetSecret <string>("JwtTokenString")); }) .Build(); _backgroundSongHubConnection.Closed += async(error) => { _reconnectTask = new Timer(async e => { await _backgroundSongHubConnection.StartAsync(); if (_backgroundSongHubConnection.State == HubConnectionState.Connected) { _reconnectTask.Dispose(); _reconnectTask = null; } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5)); }; _backgroundSongHubConnection.On <string>("BackgroundSongCheck", (username) => { BackgroundSongCheck(username); }); _backgroundSongHubConnection.On("Heartbeat", () => { }); _backgroundSongHubConnection.StartAsync().Wait(); }