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:
parent
eeee26e720
commit
fcfc330b28
2 changed files with 30 additions and 4 deletions
|
@ -419,11 +419,11 @@ class BoardWindow extends EventEmitter
|
||||||
for (let otherClient of message.ClientStates) {
|
for (let otherClient of message.ClientStates) {
|
||||||
// If this client is new, emit an event about it
|
// If this client is new, emit an event about it
|
||||||
if(!this.otherClients.has(otherClient.Id)) {
|
if(!this.otherClients.has(otherClient.Id)) {
|
||||||
this.emit("OtherClientConnect", otherClient);
|
|
||||||
|
|
||||||
// Convert the raw object into a class instance
|
// Convert the raw object into a class instance
|
||||||
let otherClientObj = new OtherClient();
|
let otherClientObj = OtherClient.FromRaw(otherClient);
|
||||||
otherClientObj.Id = otherClient.Id;
|
this.otherClients.set(otherClientObj.Id, otherClientObj);
|
||||||
|
|
||||||
|
this.emit("OtherClientConnect", otherClient);
|
||||||
}
|
}
|
||||||
else { // If not, emit a normal update message about it
|
else { // If not, emit a normal update message about it
|
||||||
this.emit("OtherClientUpdate", otherClient);
|
this.emit("OtherClientUpdate", otherClient);
|
||||||
|
|
|
@ -17,6 +17,8 @@ class OtherClient
|
||||||
this.CursorPosition = new Vector(0, 0);
|
this.CursorPosition = new Vector(0, 0);
|
||||||
// The position and dimensions of this client's viewport.
|
// The position and dimensions of this client's viewport.
|
||||||
this.Viewport = Rectangle.Zero.clone();
|
this.Viewport = Rectangle.Zero.clone();
|
||||||
|
// The time this other client's information was last updated.
|
||||||
|
this.LastUpdated = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
update(data) {
|
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;
|
export default OtherClient;
|
||||||
|
|
Loading…
Reference in a new issue