开发者

Client or server-side HTML5 canvas rendering for a node.js whiteboard application?

开发者 https://www.devze.com 2023-04-01 22:01 出处:网络
I was thinking a little whiteboard web app would be a nice way to improve my node.js and JavaScript skills.I\'ve seen a few on the web, which makes sense as it seems ideal for开发者_C百科 this kind of

I was thinking a little whiteboard web app would be a nice way to improve my node.js and JavaScript skills. I've seen a few on the web, which makes sense as it seems ideal for开发者_C百科 this kind of stack.

Just taking a moment to think, however, I was wondering about the roles of both client and server in this kind of web application. Stumbling upon node-canvas, I became even more confused. What, specifically, should the client and server be responsible for?

If the server is capable of rendering to a canvas, should it accept and validate input from the clients and then broadcast it to all other connected users via socket.io? This way, the server keeps a master-canvas element of sorts. Once a new user connects, the server just has to push out its canvas that client - bringing it up to pace with whatever has been drawn.

Any guidance on implementation - specific or philosophical - is appreciated.

Thanks!


I wrote http://draw.2x.io, which uses node-canvas (previously node-cairo, which I wrote myself) along with socket.io.

The way I've designed my application, the client essentially does all the stroke generation from user input. These are in turn processed by a canvas abstraction, which supports a subset of operations and parameters which I've defined myself. If this layer accepts whatever input the painting modules produce, they are also shipped, via socket.io, to the server.

On the server I've got the same kind of canvas layer wrapping node-canvas. This will thus replicate the input from the user in memory there, eventually making it possible to send a state image to new clients. Following this, the strokes will -- pending parameter / context validation by the server application -- be published to other connected clients, which will repeat the same procedure as above.


A company I work for implemented a whiteboard app with node.js (but did not use node-canvas) and socket.io. Unfortunately, I cannot give you code or even a website since it has not been released.

Your implementation seems very similar. Clients connect to our server and update the server whenever the whiteboard is drawn to (JSON data w/(x,y) coordinates) through socket.io. The server then updates the rest of the clients and keeps a copy of all the (x,y) coordinates so that new clients who join can see what has already been drawn.

Good luck with your app. I've been programming with node.js a lot lately and boy do I love it.


here's a multiuser whiteboard tutorial written in javascript/html5, all source available: http://www.unionplatform.com/?page_id=2762

it's not node on the server-side, but the client-side code should still be useful if you want to adapt it to a node backend.

0

精彩评论

暂无评论...
验证码 换一张
取 消