1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Wire up more of the Handshake Response

This commit is contained in:
Starbeamrainbowlabs 2017-02-19 13:22:35 +00:00
parent 1db1788626
commit 8c04cfb9e9
7 changed files with 48 additions and 5 deletions

View file

@ -4,10 +4,12 @@ namespace Nibriboard.Client.Messages
{
public class Message
{
public readonly string Event = string.Empty;
public readonly DateTime TimeSent = DateTime.Now;
public Message()
{
Event = this.GetType().Name.Replace("Message", "");
}
}
}

View file

@ -105,7 +105,7 @@ namespace Nibriboard.Client
private async Task handleMessage(string frame)
{
string eventName = JsonUtilities.DeserializeProperty<string>(frame, "event");
string eventName = JsonUtilities.DeserializeProperty<string>(frame, "Event");
if(eventName == null) {
Log.WriteLine("[NibriClient#{0}] Received message that didn't have an event.", Id);

View file

@ -25,10 +25,22 @@ class BoardWindow extends EventEmitter
this.renderTimeIndicator.innerHTML = "0ms";
document.querySelector(".fps").appendChild(this.renderTimeIndicator);
// --~~~--
// Our unique id
this.Id = -1;
// Our colour
this.Colour = "rgba(255, 255, 255, 0.3)";
// --~~~--
// Setup the canvas
this.canvas = canvas;
this.context = canvas.getContext("2d");
// Grab a reference to the sidebar
this.sidebar = document.getElementById("sidebar");
// --~~~--
// Setup the favicon thingy
@ -71,7 +83,7 @@ class BoardWindow extends EventEmitter
this.rippleLink.on("connect", (function(event) {
// Send the handshake request
this.rippleLink.send({
event: "HandshakeRequest",
Event: "HandshakeRequest",
InitialViewport: { // TODO: Add support for persisting this between sessions
X: 0,
Y: 0,
@ -89,6 +101,9 @@ class BoardWindow extends EventEmitter
// RippleLink message bindings
// Handle the HandshakeResponse when it comes in
this.rippleLink.on("HandshakeResponse", this.handleHandshakeResponse.bind(this));
// Handle other clients' state updates
this.rippleLink.on("ClientStates", this.handlePeerUpdates.bind(this));
}
@ -163,6 +178,16 @@ class BoardWindow extends EventEmitter
this.viewportState = event; // Store the viewport information for later
}
handleHandshakeResponse(message) {
console.log("Received handshake response");
// Store the information send by the server
this.Id = message.Id;
this.Colour = message.Colour;
this.sidebar.style.borderTopColor = this.Colour;
}
handlePeerUpdates(message) {
// Update our knowledge about other clients
for (let otherClient of message.ClientStates) {

View file

@ -8,10 +8,22 @@ body
{
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: 1000;
cursor: crosshair;
}
#sidebar
{
position: absolute;
top: 0; left: 0; bottom: 0;
z-index: 2000;
display: flex;
background: rgba(255, 255, 255, 0.3);
border-top: 0.2em solid rgba(255, 255, 255 0.3);
}
.fps
{
top: 0.2em !important; right: 0.2em !important;

View file

@ -40,10 +40,10 @@ class RippleLink extends EventEmitter
handleMessage(event) {
// Decode the message form the server
var message = JSON.parse(event.data);
console.debug(message);
console.debug(message.Event, message);
// Pass it on to the board manager by triggering the appropriate event
this.emit(message.event, message);
this.emit(message.Event, message);
}
/**

View file

@ -5,6 +5,10 @@
<title>Nibriboard</title>
</head>
<body>
<aside id="sidebar">
<div class="Name">Your name here</div>
</aside>
<canvas id="canvas-main"></canvas>
<!---------------->

View file

@ -6,7 +6,7 @@ namespace Nibriboard
public static int WriteLine(string text, params object[] args)
{
string outputText = $"[{Env.SecondsSinceStart}] " + string.Format(text, args);
string outputText = $"[{Env.SecondsSinceStart.ToString("N3")}] " + string.Format(text, args);
Console.WriteLine(outputText);
return outputText.Length;
}