Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit a7ec339

Browse files
committed
Strongly type hub client endpoints
1 parent 145ff24 commit a7ec339

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using OnnxStack.WebUI.Models;
2+
3+
namespace OnnxStack.Web.Hubs
4+
{
5+
public interface IStableDiffusionClient
6+
{
7+
Task OnError(string error);
8+
Task OnMessage(string message);
9+
Task OnCanceled(string message);
10+
Task OnProgress(ProgressResult progress);
11+
}
12+
13+
}

OnnxStack.WebUI/Hubs/StableDiffusionHub.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace 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

Comments
 (0)