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

[client] Finish client cursor synchronisation

This commit is contained in:
Starbeamrainbowlabs 2017-06-27 12:02:45 +01:00
parent eeee26e720
commit fcfc330b28
2 changed files with 30 additions and 4 deletions

View file

@ -419,11 +419,11 @@ class BoardWindow extends EventEmitter
for (let otherClient of message.ClientStates) {
// If this client is new, emit an event about it
if(!this.otherClients.has(otherClient.Id)) {
this.emit("OtherClientConnect", otherClient);
// Convert the raw object into a class instance
let otherClientObj = new OtherClient();
otherClientObj.Id = otherClient.Id;
let otherClientObj = OtherClient.FromRaw(otherClient);
this.otherClients.set(otherClientObj.Id, otherClientObj);
this.emit("OtherClientConnect", otherClient);
}
else { // If not, emit a normal update message about it
this.emit("OtherClientUpdate", otherClient);

View file

@ -17,6 +17,8 @@ class OtherClient
this.CursorPosition = new Vector(0, 0);
// The position and dimensions of this client's viewport.
this.Viewport = Rectangle.Zero.clone();
// The time this other client's information was last updated.
this.LastUpdated = new Date();
}
update(data) {
@ -34,4 +36,28 @@ class OtherClient
}
}
/**
* Converts raw NibriClient data sent from the server into an instance of OtherClient.
* @param {object} raw The raw data to convert.
* @return {OtherClient} The converted data.
*/
OtherClient.FromRaw = function(raw) {
let newOtherClient = new OtherClient();
newOtherClient.Id = raw.Id;
newOtherClient.CursorPosition = new Vector(
raw.CursorPosition.X,
raw.CursorPosition.Y
);
newOtherClient.Viewport = new Rectangle(
raw.Viewport.X,
raw.Viewport.Y,
raw.Viewport.Width,
raw.Viewport.Height
);
newOtherClient.Colour = raw.Colour;
newOtherClient.LastUpdated = new Date();
return newOtherClient;
}
export default OtherClient;