简体   繁体   English

node.js白板应用程序的客户端或服务器端HTML5画布渲染?

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

I was thinking a little whiteboard web app would be a nice way to improve my node.js and JavaScript skills. 我在想一个小的白板web应用程序将是一个很好的方法来提高我的node.js和JavaScript技能。 I've seen a few on the web, which makes sense as it seems ideal for 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. 然而,花点时间思考,我想知道客户端和服务器在这种Web应用程序中的角色。 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 ? 如果服务器能够呈现到画布,它是否应该接受并验证来自客户端的输入,然后通过socket.io将其广播给所有其他连接的用户? This way, the server keeps a master -canvas element of sorts. 这样,服务器就会保留一个master -canvas元素。 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. 我写了http://draw.2x.io ,它使用了node-canvas(我之前自己编写的node-cairo)和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. 如果此图层接受绘制模块生成的任何输入,则它们也通过socket.io发送到服务器。

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. 我工作的公司使用node.js(但没有使用node-canvas)和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. 只要通过socket.io绘制白板(JSON数据w /(x,y)坐标),客户端就会连接到我们的服务器并更新服务器。 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. 然后,服务器更新其余的客户端并保留所有(x,y)坐标的副本,以便加入的新客户端可以看到已经绘制的内容。

Good luck with your app. 祝你的应用好运。 I've been programming with node.js a lot lately and boy do I love it. 我最近一直在用node.js编程,男孩我喜欢它。

here's a multiuser whiteboard tutorial written in javascript/html5, all source available: http://www.unionplatform.com/?page_id=2762 这是一个用javascript / html5编写的多用户白板教程,所有来源都可用: 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. 它不是服务器端的节点,但如果要将其调整到节点后端,则客户端代码仍然有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM