@@ -35,12 +35,15 @@ public class LiveTvService : ILiveTvService
3535
3636 public DateTime LastRecordingChange = DateTime . MinValue ;
3737
38- private readonly HttpClient _httpClient ;
38+ private IHttpClientFactory _httpClientFactory ;
39+
40+ public static LiveTvService Instance { get ; private set ; }
3941
4042 public LiveTvService ( ILogger < LiveTvService > logger , IHttpClientFactory httpClientFactory )
4143 {
4244 _logger = logger ;
43- _httpClient = GetHttpClient ( httpClientFactory ) ;
45+ _httpClientFactory = httpClientFactory ;
46+ Instance = this ;
4447 }
4548
4649
@@ -49,7 +52,7 @@ public LiveTvService(ILogger<LiveTvService> logger, IHttpClientFactory httpClien
4952 /// </summary>
5053 /// <param name="cancellationToken"></param>
5154 /// <returns></returns>
52- private async Task EnsureConnectionAsync ( CancellationToken cancellationToken )
55+ public async Task EnsureConnectionAsync ( CancellationToken cancellationToken )
5356 {
5457 _logger . LogInformation ( "[Enigma2] Start EnsureConnectionAsync" ) ;
5558
@@ -151,9 +154,9 @@ private async Task EnsureConnectionAsync(CancellationToken cancellationToken)
151154 /// </summary>
152155 /// <param name="httpClientFactory"></param>
153156 /// <returns></returns>
154- private HttpClient GetHttpClient ( IHttpClientFactory httpClientFactory )
157+ private HttpClient GetHttpClient ( )
155158 {
156- var httpClient = httpClientFactory . CreateClient ( NamedClient . Default ) ;
159+ var httpClient = _httpClientFactory . CreateClient ( NamedClient . Default ) ;
157160 httpClient . DefaultRequestHeaders . UserAgent . Add (
158161 new ProductInfoHeaderValue ( Name , Plugin . Instance . Version . ToString ( ) ) ) ;
159162
@@ -189,7 +192,7 @@ public async Task<string> InitiateSession(CancellationToken cancellationToken, s
189192 var url = string . Format ( "{0}/web/getservices" , baseUrl ) ;
190193 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] InitiateSession url: {0}" , url ) ) ;
191194
192- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
195+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
193196 {
194197 using ( var reader = new StreamReader ( stream ) )
195198 {
@@ -290,7 +293,7 @@ public async Task<IEnumerable<ChannelInfo>> GetChannelsAsync(CancellationToken c
290293 baseUrlPicon = protocol + "://" + Plugin . Instance . Configuration . WebInterfaceUsername + ":" + Plugin . Instance . Configuration . WebInterfacePassword + "@" + Plugin . Instance . Configuration . HostName + ":" + Plugin . Instance . Configuration . WebInterfacePort ;
291294 }
292295
293- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
296+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
294297 {
295298 using ( var reader = new StreamReader ( stream ) )
296299 {
@@ -454,7 +457,7 @@ public async Task<List<ChannelInfo>> GetChannelsForTVBouquetAsync(CancellationTo
454457 baseUrlPicon = protocol + "://" + Plugin . Instance . Configuration . WebInterfaceUsername + ":" + Plugin . Instance . Configuration . WebInterfacePassword + "@" + Plugin . Instance . Configuration . HostName + ":" + Plugin . Instance . Configuration . WebInterfacePort ;
455458 }
456459
457- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
460+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
458461 {
459462 using ( var reader = new StreamReader ( stream ) )
460463 {
@@ -555,11 +558,11 @@ public async Task<List<ChannelInfo>> GetChannelsForTVBouquetAsync(CancellationTo
555558 /// Gets the Recordings async
556559 /// </summary>
557560 /// <param name="cancellationToken">The cancellation token.</param>
558- /// <returns>Task{IEnumerable{RecordingInfo }}</returns>
559- public async Task < IEnumerable < RecordingInfo > > GetRecordingsAsync ( CancellationToken cancellationToken )
561+ /// <returns>Task{IEnumerable{MyRecordingInfo }}</returns>
562+ public async Task < IEnumerable < MyRecordingInfo > > GetRecordingsAsync ( CancellationToken cancellationToken )
560563 {
561564 await Task . Delay ( 0 ) ; //to avoid await warnings
562- return new List < RecordingInfo > ( ) ;
565+ return new List < MyRecordingInfo > ( ) ;
563566 }
564567
565568 public async Task < IEnumerable < MyRecordingInfo > > GetAllRecordingsAsync ( CancellationToken cancellationToken )
@@ -578,7 +581,7 @@ public async Task<IEnumerable<MyRecordingInfo>> GetAllRecordingsAsync(Cancellati
578581 var url = string . Format ( "{0}/web/movielist" , baseUrl ) ;
579582 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] GetRecordingsAsync url: {0}" , url ) ) ;
580583
581- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
584+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
582585 {
583586 using ( var reader = new StreamReader ( stream ) )
584587 {
@@ -757,7 +760,7 @@ public async Task DeleteRecordingAsync(string recordingId, CancellationToken can
757760 var url = string . Format ( "{0}/web/moviedelete?sRef={1}" , baseUrl , recordingId ) ;
758761 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] DeleteRecordingAsync url: {0}" , url ) ) ;
759762
760- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
763+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
761764 {
762765 using ( var reader = new StreamReader ( stream ) )
763766 {
@@ -772,7 +775,7 @@ public async Task DeleteRecordingAsync(string recordingId, CancellationToken can
772775 var e2simplexmlresult = xml . GetElementsByTagName ( "e2simplexmlresult" ) ;
773776 foreach ( XmlNode xmlNode in e2simplexmlresult )
774777 {
775- var recordingInfo = new RecordingInfo ( ) ;
778+ var recordingInfo = new MyRecordingInfo ( ) ;
776779
777780 var e2state = "?" ;
778781 var e2statetext = "?" ;
@@ -837,7 +840,7 @@ public async Task CancelTimerAsync(string timerId, CancellationToken cancellatio
837840 var url = string . Format ( "{0}/web/timerdelete?sRef={1}&begin={2}&end={3}" , baseUrl , sRef , begin , end ) ;
838841 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] CancelTimerAsync url: {0}" , url ) ) ;
839842
840- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
843+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
841844 {
842845 using ( var reader = new StreamReader ( stream ) )
843846 {
@@ -852,7 +855,7 @@ public async Task CancelTimerAsync(string timerId, CancellationToken cancellatio
852855 var e2simplexmlresult = xml . GetElementsByTagName ( "e2simplexmlresult" ) ;
853856 foreach ( XmlNode xmlNode in e2simplexmlresult )
854857 {
855- var recordingInfo = new RecordingInfo ( ) ;
858+ var recordingInfo = new MyRecordingInfo ( ) ;
856859
857860 var e2state = "?" ;
858861 var e2statetext = "?" ;
@@ -920,7 +923,7 @@ public async Task CreateTimerAsync(TimerInfo info, CancellationToken cancellatio
920923
921924 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] CreateTimerAsync url: {0}" , url ) ) ;
922925
923- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
926+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
924927 {
925928 using ( var reader = new StreamReader ( stream ) )
926929 {
@@ -935,7 +938,7 @@ public async Task CreateTimerAsync(TimerInfo info, CancellationToken cancellatio
935938 var e2simplexmlresult = xml . GetElementsByTagName ( "e2simplexmlresult" ) ;
936939 foreach ( XmlNode xmlNode in e2simplexmlresult )
937940 {
938- var recordingInfo = new RecordingInfo ( ) ;
941+ var recordingInfo = new MyRecordingInfo ( ) ;
939942
940943 var e2state = "?" ;
941944 var e2statetext = "?" ;
@@ -992,7 +995,7 @@ public async Task<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cance
992995 var url = string . Format ( "{0}/web/timerlist" , baseUrl ) ;
993996 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] GetTimersAsync url: {0}" , url ) ) ;
994997
995- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
998+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
996999 {
9971000 using ( var reader = new StreamReader ( stream ) )
9981001 {
@@ -1215,7 +1218,7 @@ public async Task ZapToChannel(CancellationToken cancellationToken, string chann
12151218 var url = string . Format ( "{0}/web/zap?sRef={1}" , baseUrl , channelOid ) ;
12161219 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] ZapToChannel url: {0}" , url ) ) ;
12171220
1218- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
1221+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
12191222 {
12201223 using ( var reader = new StreamReader ( stream ) )
12211224 {
@@ -1230,7 +1233,7 @@ public async Task ZapToChannel(CancellationToken cancellationToken, string chann
12301233 var e2simplexmlresult = xml . GetElementsByTagName ( "e2simplexmlresult" ) ;
12311234 foreach ( XmlNode xmlNode in e2simplexmlresult )
12321235 {
1233- var recordingInfo = new RecordingInfo ( ) ;
1236+ var recordingInfo = new MyRecordingInfo ( ) ;
12341237
12351238 var e2state = "?" ;
12361239 var e2statetext = "?" ;
@@ -1314,7 +1317,7 @@ public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, D
13141317 var url = string . Format ( "{0}/web/epgservice?sRef={1}" , baseUrl , channelId ) ;
13151318 UtilsHelper . DebugInformation ( _logger , string . Format ( "[Enigma2] GetProgramsAsync url: {0}" , url ) ) ;
13161319
1317- using ( var stream = await _httpClient . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
1320+ using ( var stream = await GetHttpClient ( ) . GetStreamAsync ( url , cancellationToken ) . ConfigureAwait ( false ) )
13181321 {
13191322 using ( var reader = new StreamReader ( stream ) )
13201323 {
@@ -1476,7 +1479,7 @@ public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, D
14761479 /// </summary>
14771480 /// <param name="cancellationToken">The CancellationToken</param>
14781481 /// <returns>LiveTvServiceStatusInfo</returns>
1479- public async Task < LiveTvServiceStatusInfo > GetStatusInfoAsync ( CancellationToken cancellationToken )
1482+ /* public async Task<LiveTvServiceStatusInfo> GetStatusInfoAsync(CancellationToken cancellationToken)
14801483 {
14811484 _logger.LogInformation("[Enigma2] Start GetStatusInfoAsync Async, retrieve status details");
14821485 await EnsureConnectionAsync(cancellationToken).ConfigureAwait(false);
@@ -1555,7 +1558,7 @@ public async Task<LiveTvServiceStatusInfo> GetStatusInfoAsync(CancellationToken
15551558
15561559 }
15571560 }
1558- }
1561+ }*/
15591562
15601563
15611564 /// <summary>
@@ -1581,8 +1584,12 @@ public async Task<MediaSourceInfo> GetRecordingStream(string recordingId, string
15811584
15821585 public async Task CloseLiveStream ( string id , CancellationToken cancellationToken )
15831586 {
1584- await Task . Delay ( 0 ) ; //to avoid await warnings
1585- throw new NotImplementedException ( ) ;
1587+ await Task . Factory . StartNew < string > ( ( ) =>
1588+ {
1589+ _logger . LogDebug ( "[Enigma2] LiveTvService.CloseLiveStream: closed stream for subscriptionId: {id}" , id ) ;
1590+ return id ;
1591+ } ) ;
1592+
15861593 }
15871594
15881595
@@ -1676,21 +1683,21 @@ public Task ResetTuner(string id, CancellationToken cancellationToken)
16761683 }
16771684
16781685
1679- public Task < ImageStream > GetChannelImageAsync ( string channelId , CancellationToken cancellationToken )
1686+ public Task < Stream > GetChannelImageAsync ( string channelId , CancellationToken cancellationToken )
16801687 {
16811688 // Leave as is. This is handled by supplying image url to ChannelInfo
16821689 throw new NotImplementedException ( ) ;
16831690 }
16841691
16851692
1686- public Task < ImageStream > GetProgramImageAsync ( string programId , string channelId , CancellationToken cancellationToken )
1693+ public Task < Stream > GetProgramImageAsync ( string programId , string channelId , CancellationToken cancellationToken )
16871694 {
16881695 // Leave as is. This is handled by supplying image url to ProgramInfo
16891696 throw new NotImplementedException ( ) ;
16901697 }
16911698
16921699
1693- public Task < ImageStream > GetRecordingImageAsync ( string recordingId , CancellationToken cancellationToken )
1700+ public Task < Stream > GetRecordingImageAsync ( string recordingId , CancellationToken cancellationToken )
16941701 {
16951702 // Leave as is. This is handled by supplying image url to RecordingInfo
16961703 throw new NotImplementedException ( ) ;
0 commit comments