goblinfactory / konsole

Home of the simple console library consisting of ProgressBar, Window, Form, Draw & MockConsole (C# console progress bar with support for single or multithreaded progress updates) Window is a 100%-ish console compatible window, supporting all normal console writing to a windowed section of the screen, supporting scrolling and clipping of console output.
718 stars 62 forks source link

REMOTE KONSOLE - SignalR/server send events React "Konsole" #67

Open goblinfactory opened 3 years ago

goblinfactory commented 3 years ago

SignalR/server send events React "Konsole"

The idea is to be able to drop in a text console "widget" into a webpage, e.g. a React control, or even in a static CDN website, that loads a console with a unique session ID, app ID and string[] channels. Then be able to treate writing to a remote console as simple as writing to a konsole window, with some extra support for broadcasting to channels, as well as processing user input.

for example, in a game; where the statusbar channel, is defined client side using normal console commands, window.SplitLeft(), splitColumns for example

 // below code would be converted to javascript / react so shown only as pseduo code for converting to react.
  var rows = layout.SplitRows(
                    new Split(3, "headline", LineThickNess.Single, ConsoleColor.Yellow),
                    new Split(0, "content", LineThickNess.Single),
                    new Split(3, "status", LineThickNess.Single, ConsoleColor.Yellow)
            );
  var rc = new remoteConsole(appId, appUrl, authtoken);
 var header = new remoteConsole(rc, rows[0], "header");
var content = new remoteConsole(rc, rows[1],"content");
 var status = new remoteConsole(rc, rows[2], "statusBar"); 
  rc.Render();
  rc.HandleEvents(myCancellationToken);

then server side you can write

var (deadUser, restOfUsers) = GetNextVictim(); // returns sessionIDs used to communicate with remote users.

var rc = new RemoteConsole(appId, appUrl, token);

var contentAll = rc.BroadCast.ToChannel("content").ToAllExcluding(deadUser.SessionId);
contentAll.WriteLine(Yellow, $"{deadUser.Name} was killed by the wearwolf.");

var contentDead = rc.SingleCast(deadUser.SessionId).ToChannel("content"):
contentDead.WriteLine(Red, $"You have been killed by the wearwolf.");

var statusAll = rc.BroadCast.ToChannel("status");
statusAll.WriteLine($"Only {cnt} players left alive!");