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

[client] Notify the server when we complete a line.

This commit is contained in:
Starbeamrainbowlabs 2017-04-15 16:20:30 +01:00
parent bb05a16e40
commit b6f50a48ba
2 changed files with 29 additions and 2 deletions

View file

@ -9,6 +9,7 @@ window.panzoom = require("pan-zoom");
import RippleLink from './RippleLink'; import RippleLink from './RippleLink';
import ViewportSyncer from './ViewportSyncer'; import ViewportSyncer from './ViewportSyncer';
import OtherClient from './OtherClient'; import OtherClient from './OtherClient';
import Pencil from './Pencil';
import { get } from './Utilities'; import { get } from './Utilities';
import Keyboard from './Utilities/Keyboard'; import Keyboard from './Utilities/Keyboard';
@ -51,6 +52,11 @@ class BoardWindow extends EventEmitter
// The zoom level of the viewport. 1 = normal. // The zoom level of the viewport. 1 = normal.
zoomLevel: 1 zoomLevel: 1
}; };
/**
* The currents tate of the keyboard.
* @type {Keyboard}
*/
this.keyboard = new Keyboard();
// --~~~-- // --~~~--
@ -64,7 +70,7 @@ class BoardWindow extends EventEmitter
// Create a map to store information about other clients in // Create a map to store information about other clients in
this.otherClients = new Map(); this.otherClients = new Map();
this.keyboard = new Keyboard();
// --~~~-- // --~~~--
@ -172,6 +178,7 @@ class BoardWindow extends EventEmitter
context.clearRect(0, 0, canvas.width, canvas.height); context.clearRect(0, 0, canvas.width, canvas.height);
this.renderOthers(canvas, context); this.renderOthers(canvas, context);
this.pencil.render(canvas, context);
} }
renderOthers(canvas, context) renderOthers(canvas, context)
@ -237,6 +244,10 @@ class BoardWindow extends EventEmitter
this.viewport.zoomLevel += event.dz; this.viewport.zoomLevel += event.dz;
} }
/**
* Handles the server's response to our handshake request
* @param {object} message The server's response to our handshake request.
*/
handleHandshakeResponse(message) { handleHandshakeResponse(message) {
console.log("Received handshake response"); console.log("Received handshake response");
@ -245,6 +256,9 @@ class BoardWindow extends EventEmitter
this.Colour = message.Colour; this.Colour = message.Colour;
this.sidebar.style.borderTopColor = this.Colour; this.sidebar.style.borderTopColor = this.Colour;
// The pencil that draws the lines
this.pencil = new Pencil(this.rippleLink, this);
} }
/** /**

View file

@ -1,8 +1,9 @@
"use strict"; "use strict";
import Mouse from './Utilities/Mouse';
import Vector from './Utilities/Vector'; import Vector from './Utilities/Vector';
import Mouse from './Utilities/Mouse';
var cuid = require("cuid"); var cuid = require("cuid");
class Pencil class Pencil
@ -66,6 +67,13 @@ class Pencil
handleMouseUp(event) { handleMouseUp(event) {
sendUnsent(); sendUnsent();
// Tell the server that the line is complete
this.rippleLink.send({
Event: "LineComplete",
LineId: this.currentLineId,
LineWidth: this.currentLineWidth,
LineColour: this.currentColour
});
// Reset the current line segments // Reset the current line segments
this.currentLineSegments = []; this.currentLineSegments = [];
// Regenerate the line id // Regenerate the line id
@ -87,6 +95,11 @@ class Pencil
this.unsentSegments = []; this.unsentSegments = [];
} }
/**
* Renders the line that is currently being drawn to the screen.
* @param {HTMLCanvasElement} canvas The canvas to draw to.
* @param {CanvasRenderingContext2D} context The rendering context to use to draw to the canvas.
*/
render(canvas, context) { render(canvas, context) {
if(this.currentLineSegments.length == 0) if(this.currentLineSegments.length == 0)
return; return;