-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
210 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using k8s; | ||
using k8s.Models; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace BlazorApp.Chat; | ||
|
||
public class ChatHub : Hub, IChatHub | ||
public class ChatHub : Hub | ||
{ | ||
public async Task SendMessage(string message) | ||
{ | ||
Console.WriteLine("收到" + message); | ||
await Clients.All.SendAsync("ReceiveMessage", message); | ||
} | ||
|
||
public Task SendWatchEvent(string message) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using k8s; | ||
using k8s.Models; | ||
|
||
namespace BlazorApp.Chat; | ||
|
||
public interface IChatHub | ||
public interface IChatHub<in T> where T : IKubernetesObject<V1ObjectMeta> | ||
{ | ||
public Task SendMessage(string message); | ||
} | ||
public Task SendMessage(string message); | ||
public Task SendWatchEvent(string message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using BlazorApp.Service; | ||
using k8s; | ||
using k8s.Models; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BlazorApp.Chat; | ||
|
||
public class SignalSendService<T> where T : IKubernetesObject<V1ObjectMeta> | ||
{ | ||
private readonly IHubContext<ChatHub> _ctx; | ||
|
||
public SignalSendService(IHubContext<ChatHub> ctx) | ||
{ | ||
_ctx = ctx; | ||
} | ||
|
||
public void Send(WatchEventType type, T item) | ||
{ | ||
_ctx.Clients.All.SendAsync("Resource", (type, item)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.