99
1010namespace OnnxStack . Web . Hubs
1111{
12- public class StableDiffusionHub : Hub
12+ public class StableDiffusionHub : Hub < IStableDiffusionClient >
1313 {
1414 private readonly ILogger < StableDiffusionHub > _logger ;
1515 private readonly IWebHostEnvironment _webHostEnvironment ;
@@ -38,7 +38,7 @@ public StableDiffusionHub(ILogger<StableDiffusionHub> logger, IStableDiffusionSe
3838 public override async Task OnConnectedAsync ( )
3939 {
4040 _logger . Log ( LogLevel . Information , "[OnConnectedAsync], Id: {0}" , Context . ConnectionId ) ;
41- await Clients . Caller . SendAsync ( " OnMessage" , "OnConnectedAsync" ) ;
41+ await Clients . Caller . OnMessage ( "OnConnectedAsync" ) ;
4242 await base . OnConnectedAsync ( ) ;
4343 }
4444
@@ -50,7 +50,7 @@ public override async Task OnConnectedAsync()
5050 public override async Task OnDisconnectedAsync ( Exception exception )
5151 {
5252 _logger . Log ( LogLevel . Information , "[OnDisconnectedAsync], Id: {0}" , Context . ConnectionId ) ;
53- await Clients . Caller . SendAsync ( " OnMessage" , "OnDisconnectedAsync" ) ;
53+ await Clients . Caller . OnMessage ( "OnDisconnectedAsync" ) ;
5454 await base . OnDisconnectedAsync ( exception ) ;
5555 }
5656
@@ -117,12 +117,12 @@ private async Task<bool> RunStableDiffusion(PromptOptions promptOptions, Schedul
117117 }
118118 catch ( OperationCanceledException tex )
119119 {
120- await Clients . Caller . SendAsync ( " OnCanceled" , tex . Message ) ;
120+ await Clients . Caller . OnCanceled ( tex . Message ) ;
121121 _logger . Log ( LogLevel . Warning , tex , "[OnExecuteTextToImage] - Operation canceled, Connection: {0}" , Context . ConnectionId ) ;
122122 }
123123 catch ( Exception ex )
124124 {
125- await Clients . Caller . SendAsync ( " OnError" , ex . Message ) ;
125+ await Clients . Caller . OnError ( ex . Message ) ;
126126 _logger . Log ( LogLevel . Error , ex , "[OnExecuteTextToImage] - Error generating image, Connection: {0}" , Context . ConnectionId ) ;
127127 }
128128 return false ;
@@ -197,7 +197,7 @@ private Action<int, int> ProgressCallback()
197197 return async ( progress , total ) =>
198198 {
199199 _logger . Log ( LogLevel . Information , "[OnExecuteTextToImage] - Progress: {0}/{1}, Connection: {2}" , progress , total , Context . ConnectionId ) ;
200- await Clients . Caller . SendAsync ( " OnProgress" , new ProgressResult ( progress , total ) ) ;
200+ await Clients . Caller . OnProgress ( new ProgressResult ( progress , total ) ) ;
201201 } ;
202202 }
203203
@@ -226,4 +226,5 @@ private string CreateOutputUrl(string folder, string file)
226226 return $ "/images/results/{ folder } /{ file } ";
227227 }
228228 }
229+
229230}
0 commit comments