-
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
1 parent
01dff18
commit 40f9117
Showing
42 changed files
with
1,167 additions
and
1,283 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,18 +1,18 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Copyright>Copyright © 2015-2024 Petabridge</Copyright> | ||
<Authors>Petabridge</Authors> | ||
<VersionPrefix>0.2.2</VersionPrefix> | ||
<PackageReleaseNotes>Added footer that displays assembly version on Pricing UI</PackageReleaseNotes> | ||
<PackageIconUrl> | ||
</PackageIconUrl> | ||
<PackageProjectUrl> | ||
</PackageProjectUrl> | ||
<PackageLicenseUrl> | ||
</PackageLicenseUrl> | ||
<NoWarn>$(NoWarn);CS1591</NoWarn> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<NetVersion>net8.0</NetVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Copyright>Copyright © 2015-2024 Petabridge</Copyright> | ||
<Authors>Petabridge</Authors> | ||
<VersionPrefix>0.2.2</VersionPrefix> | ||
<PackageReleaseNotes>Added footer that displays assembly version on Pricing UI</PackageReleaseNotes> | ||
<PackageIconUrl> | ||
</PackageIconUrl> | ||
<PackageProjectUrl> | ||
</PackageProjectUrl> | ||
<PackageLicenseUrl> | ||
</PackageLicenseUrl> | ||
<NoWarn>$(NoWarn);CS1591</NoWarn> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<NetVersion>net8.0</NetVersion> | ||
</PropertyGroup> | ||
</Project> |
167 changes: 81 additions & 86 deletions
167
src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs
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,115 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Actor; | ||
using Akka.Event; | ||
using Akka.Streams; | ||
using Akka.Streams.Dsl; | ||
using Akka.Util.Internal; | ||
using DrawTogether.UI.Server.Hubs; | ||
using DrawTogether.UI.Server.Services; | ||
using DrawTogether.UI.Shared; | ||
using DrawTogether.UI.Shared.Connectivity; | ||
using Microsoft.AspNetCore.SignalR; | ||
using static DrawTogether.UI.Shared.Connectivity.PaintSessionProtocol; | ||
|
||
namespace DrawTogether.UI.Server.Actors | ||
namespace DrawTogether.UI.Server.Actors; | ||
|
||
/// <summary> | ||
/// Holds all stroke data in memory for a single drawing instance. | ||
/// </summary> | ||
public class PaintInstanceActor : UntypedActor | ||
{ | ||
/// <summary> | ||
/// Holds all stroke data in memory for a single drawing instance. | ||
/// </summary> | ||
public class PaintInstanceActor : UntypedActor | ||
{ | ||
// Handle to the Akka.NET asynchronous logging system | ||
private readonly ILoggingAdapter _log = Context.GetLogger(); | ||
private readonly List<ConnectedStroke> _connectedStrokes = new(); | ||
private readonly IDrawHubHandler _hubHandler; | ||
|
||
private readonly List<ConnectedStroke> _connectedStrokes = new(); | ||
private readonly List<string> _users = new(); | ||
private readonly IDrawHubHandler _hubHandler; | ||
private readonly string _sessionId; | ||
private readonly TimeSpan _idleTimeout = TimeSpan.FromMinutes(20); | ||
private IActorRef _streamsDebouncer; | ||
private readonly TimeSpan _idleTimeout = TimeSpan.FromMinutes(20); | ||
|
||
public PaintInstanceActor(string sessionId, IDrawHubHandler hubHandler) | ||
{ | ||
_sessionId = sessionId; | ||
_hubHandler = hubHandler; | ||
} | ||
// Handle to the Akka.NET asynchronous logging system | ||
private readonly ILoggingAdapter _log = Context.GetLogger(); | ||
private readonly string _sessionId; | ||
private readonly List<string> _users = new(); | ||
private IActorRef _streamsDebouncer; | ||
|
||
protected override void OnReceive(object message) | ||
public PaintInstanceActor(string sessionId, IDrawHubHandler hubHandler) | ||
Check warning on line 28 in src/DrawTogether.UI/Server/Actors/PaintInstanceActor.cs GitHub Actions / Test-ubuntu-latest
|
||
{ | ||
_sessionId = sessionId; | ||
_hubHandler = hubHandler; | ||
} | ||
|
||
protected override void OnReceive(object message) | ||
{ | ||
switch (message) | ||
{ | ||
switch (message) | ||
case JoinPaintSession join: | ||
{ | ||
case JoinPaintSession join: | ||
{ | ||
_log.Debug("User [{0}] joined [{1}]", join.ConnectionId, join.InstanceId); | ||
// need to make immutable copy of stroke data and pass it along | ||
var strokeCopy = _connectedStrokes.ToArray(); | ||
|
||
// sync a single user. | ||
_hubHandler.PushConnectedStrokes(join.ConnectionId, _sessionId, strokeCopy); | ||
_hubHandler.AddUsers(join.ConnectionId, _users.ToArray()); | ||
|
||
// let all users know about the new user | ||
_users.Add(join.UserId); | ||
_hubHandler.AddUser(_sessionId, join.UserId); | ||
break; | ||
} | ||
case AddPointToConnectedStroke or CreateConnectedStroke: | ||
{ | ||
_streamsDebouncer.Tell(message); | ||
break; | ||
} | ||
case ReceiveTimeout _: | ||
{ | ||
_log.Info("Terminated Painting Session [{0}] after [{1}]", _sessionId, _idleTimeout); | ||
Context.Stop(Self); | ||
break; | ||
} | ||
default: | ||
Unhandled(message); | ||
break; | ||
_log.Debug("User [{0}] joined [{1}]", join.ConnectionId, join.InstanceId); | ||
// need to make immutable copy of stroke data and pass it along | ||
var strokeCopy = _connectedStrokes.ToArray(); | ||
|
||
// sync a single user. | ||
_hubHandler.PushConnectedStrokes(join.ConnectionId, _sessionId, strokeCopy); | ||
_hubHandler.AddUsers(join.ConnectionId, _users.ToArray()); | ||
|
||
// let all users know about the new user | ||
_users.Add(join.UserId); | ||
_hubHandler.AddUser(_sessionId, join.UserId); | ||
break; | ||
} | ||
case AddPointToConnectedStroke or CreateConnectedStroke: | ||
{ | ||
_streamsDebouncer.Tell(message); | ||
break; | ||
} | ||
case ReceiveTimeout _: | ||
{ | ||
_log.Info("Terminated Painting Session [{0}] after [{1}]", _sessionId, _idleTimeout); | ||
Context.Stop(Self); | ||
break; | ||
} | ||
default: | ||
Unhandled(message); | ||
break; | ||
} | ||
} | ||
|
||
protected override void PreStart() | ||
{ | ||
_log.Info("Started drawing session [{0}]", _sessionId); | ||
protected override void PreStart() | ||
{ | ||
_log.Info("Started drawing session [{0}]", _sessionId); | ||
|
||
var materializer = Context.Materializer(); | ||
var (sourceRef, source) = Source.ActorRef<IPaintSessionMessage>(1000, OverflowStrategy.DropHead) | ||
.PreMaterialize(materializer); | ||
var materializer = Context.Materializer(); | ||
var (sourceRef, source) = Source.ActorRef<IPaintSessionMessage>(1000, OverflowStrategy.DropHead) | ||
.PreMaterialize(materializer); | ||
|
||
_streamsDebouncer = sourceRef; | ||
source.GroupedWithin(10, TimeSpan.FromMilliseconds(75)).RunForeach(TransmitActions, materializer); | ||
_streamsDebouncer = sourceRef; | ||
source.GroupedWithin(10, TimeSpan.FromMilliseconds(75)).RunForeach(TransmitActions, materializer); | ||
|
||
// idle timeout all drawings after 20 minutes | ||
Context.SetReceiveTimeout(_idleTimeout); | ||
} | ||
// idle timeout all drawings after 20 minutes | ||
Context.SetReceiveTimeout(_idleTimeout); | ||
} | ||
|
||
private void TransmitActions(IEnumerable<IPaintSessionMessage> actions) | ||
{ | ||
var createActions = actions.Where(a => a is CreateConnectedStroke).Select(a => ((CreateConnectedStroke)a).ConnectedStroke); | ||
private void TransmitActions(IEnumerable<IPaintSessionMessage> actions) | ||
{ | ||
var createActions = actions.Where(a => a is CreateConnectedStroke) | ||
.Select(a => ((CreateConnectedStroke)a).ConnectedStroke); | ||
|
||
var addActions = actions.Where(a => a is AddPointToConnectedStroke).Select(a => (AddPointToConnectedStroke)a); | ||
var addActions = actions.Where(a => a is AddPointToConnectedStroke).Select(a => (AddPointToConnectedStroke)a); | ||
|
||
_log.Info("BATCHED {0} create actions and {1} add actions", createActions.Count(), addActions.Count()); | ||
_log.Info("BATCHED {0} create actions and {1} add actions", createActions.Count(), addActions.Count()); | ||
|
||
createActions.ForEach(c => { c.Points = addActions.Where(a => a.Id == c.Id).Select(a => a.Point).ToList(); }); | ||
createActions.ForEach(c => { c.Points = addActions.Where(a => a.Id == c.Id).Select(a => a.Point).ToList(); }); | ||
|
||
addActions = addActions.Where(a => !createActions.Any(c => a.Id == c.Id)); | ||
addActions = addActions.Where(a => !createActions.Any(c => a.Id == c.Id)); | ||
|
||
_hubHandler.PushConnectedStrokes(_sessionId, createActions.ToArray()); | ||
_connectedStrokes.AddRange(createActions); | ||
_hubHandler.PushConnectedStrokes(_sessionId, createActions.ToArray()); | ||
_connectedStrokes.AddRange(createActions); | ||
|
||
addActions.GroupBy(a => a.Id).ForEach(add => { | ||
_connectedStrokes.Where(c => c.Id == add.Key).First().Points.AddRange(add.Select(a => a.Point)); | ||
addActions.GroupBy(a => a.Id).ForEach(add => | ||
{ | ||
_connectedStrokes.Where(c => c.Id == add.Key).First().Points.AddRange(add.Select(a => a.Point)); | ||
|
||
// sync ALL users | ||
// TODO: look into zero-copy for this | ||
_hubHandler.AddPointsToConnectedStroke(_sessionId, add.Key, add.Select(a => a.Point).ToArray()); | ||
}); | ||
} | ||
// sync ALL users | ||
// TODO: look into zero-copy for this | ||
_hubHandler.AddPointsToConnectedStroke(_sessionId, add.Key, add.Select(a => a.Point).ToArray()); | ||
}); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Actor; | ||
|
||
namespace DrawTogether.UI.Server.Actors | ||
namespace DrawTogether.UI.Server.Actors; | ||
|
||
/// <summary> | ||
/// Gives a user a randomly-assigned name and associates that | ||
/// with their session on DrawTogether | ||
/// </summary> | ||
public class UserInstanceActor : UntypedActor | ||
{ | ||
/// <summary> | ||
/// Gives a user a randomly-assigned name and associates that | ||
/// with their session on DrawTogether | ||
/// </summary> | ||
public class UserInstanceActor : UntypedActor | ||
protected override void OnReceive(object message) | ||
{ | ||
protected override void OnReceive(object 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</Router> |
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,26 +1,20 @@ | ||
<circle cx="@cX" cy="@cY" r="@(radius*0.8)" | ||
stroke="@(borderColor)" stroke-width="@(radius *0.05)" | ||
fill="@(fillColor)" | ||
id="@(cursorId)"/> | ||
<circle cx="@cX" cy="@cY" r="@(radius * 0.8)" | ||
stroke="@(borderColor)" stroke-width="@(radius * 0.05)" | ||
fill="@(fillColor)" | ||
id="@(cursorId)"/> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public int radius { get; set; } = 10; | ||
[Parameter] public int radius { get; set; } = 10; | ||
|
||
[Parameter] | ||
public string borderColor { get; set; } = "#eee"; | ||
[Parameter] public string borderColor { get; set; } = "#eee"; | ||
|
||
[Parameter] | ||
public string fillColor { get; set; } = "#eee"; | ||
[Parameter] public string fillColor { get; set; } = "#eee"; | ||
|
||
[Parameter] | ||
public string cursorId { get; set; } | ||
[Parameter] public string cursorId { get; set; } | ||
Check warning on line 14 in src/DrawTogether.UI/Server/Components/Circle.razor GitHub Actions / Test-ubuntu-latest
|
||
|
||
[Parameter] | ||
public double cX { get; set; } | ||
[Parameter] public double cX { get; set; } | ||
|
||
[Parameter] | ||
public double cY { get; set; } | ||
[Parameter] public double cY { get; set; } | ||
|
||
} |
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.