working!
This commit is contained in:
parent
5fa4fe6fb5
commit
b89a557af1
7
NoteContext.cs
Normal file
7
NoteContext.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace BinaryDad.Notes
|
||||||
|
{
|
||||||
|
public static class NoteContext
|
||||||
|
{
|
||||||
|
public static IDictionary<string, string> ClientNotes { get; } = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
|
}
|
18
NoteHub.cs
18
NoteHub.cs
@ -12,11 +12,27 @@ namespace BinaryDad.Notes
|
|||||||
this.noteService = noteService;
|
this.noteService = noteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task OnConnectedAsync()
|
||||||
|
{
|
||||||
|
var noteName = Context.GetHttpContext().Request.Query["noteName"];
|
||||||
|
|
||||||
|
NoteContext.ClientNotes[Context.ConnectionId] = noteName;
|
||||||
|
|
||||||
|
return base.OnConnectedAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SaveNote(string content, string? noteName)
|
public async Task SaveNote(string content, string? noteName)
|
||||||
{
|
{
|
||||||
noteService.Save(content, noteName);
|
noteService.Save(content, noteName);
|
||||||
|
|
||||||
await Clients.Others.SendAsync("updateNote", content);
|
var clientConnections = NoteContext.ClientNotes
|
||||||
|
.Where(c => c.Value == noteName && c.Key != Context.ConnectionId)
|
||||||
|
.Select(c => c.Key)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
await Clients
|
||||||
|
.Clients(clientConnections)
|
||||||
|
.SendAsync("updateNote", content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
let connection = new signalR.HubConnectionBuilder()
|
let connection = new signalR.HubConnectionBuilder()
|
||||||
.withAutomaticReconnect()
|
.withAutomaticReconnect()
|
||||||
.withUrl("/noteHub")
|
.withUrl(`/noteHub?noteName=${noteName}`)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
Loading…
Reference in New Issue
Block a user