Real-time collaborative drawing whiteboard in HTML5/JS and websockets? - javascript

I'm trying to put together a small(ish) summer school project for some of my advanced students and am researching how to do it best and what to use - hopefully somebody here could point me in the right direction.
What we are interested in is researching if HTML5 came far enough to create a real-time collaborative drawing whiteboard in it - purely by using web technologies without plugins (so CSS, HTML5/DOM and Javascript). What we'd ultimatelly strive for is this - for example have an online canvas/page on a central server displayed on a big screen in the classroom. Then our students/users would take out their smartphones, load the page in their mobile browsers (I'm perfectly ok with limiting this to webkit mobile browsers for now) and draw on their screens with touch/fingers (or on PCs with the mouse - guessing this doesn't make a lot of difference) and it would get updated in real time for everybody - both on their screens and on the central big screen in the classroom.
I'm guessing push/get requests would be too slow for this - could it be solved by websockets? Does anybody have any good JS libraries to recommend for this?
Also what would the ideal (but easier for students to understand) architecture look like. Lets say you have 30 simultaneous users in a clasroom - each of them would connect with websockets to the server and the server would pool/combine all of their requests into one and then return the combined file (some sort of minimal JSON or even just coordinates) for every connected user?
Would websockets and (I'm guessing) canvas be able to take this? So that everything still looks snappy? Are there (jQuery-like) JS libraries available to make our lives easier - or do you think its something thats too complex for a 2-week summer school project?

here's a tutorial describing how to create a multiuser whiteboard with javascript/html5/canvas:
http://www.unionplatform.com/?page_id=2762
the example uses a collaboration framework and server named "union platform". even if you decide to roll your own server and client framework, the messaging in the example should give you an idea of how to structure the code.
for an apples-to-apples speed comparison of websocket vs comet, see:
http://www.unionplatform.com/?page_id=2954
in my tests, a basic ping over WebSocket is normally about twice as fast as the ping over http. both websocket and coment are more than fast enough to create a collaborative whiteboard.

Definitely check this out:
http://wesbos.com/html5-canvas-websockets-nodejs/

For the networking side of things, try looking at node.js for the server, along with socket.io for the client.
As for the drawing itself, a few popular choices are processing, raphael and cakejs.
When it comes to the implementation, you may want to look at how networked games deal with similar issues (gamedev.stackexchange.com could be useful).
What you are going to be doing is essentialy the same as a simple top down multiplayer game, with each 'player' in this case being a students fingertip, and the 'level' being the canvas. You need to update the server as to their position and whether or not they are 'shooting' (drawing).

I'm guessing push/get requests would be too slow for this - could it be solved by websockets? Does anybody have any good JS libraries to recommend for this?
If you need real-time infrastructure I've created a list of real-time technologies which might be of use to you. These include hosted service, such as Pusher who I work for, and self-install technologies such as WebSocket and Comet solutions.
WebSocket sounds like the idea choice of technology for you since they have become part of HTML5 and offer the most efficient for of realtime bi-directional communication between a web server and a browser (or other clients).
Also what would the ideal (but easier for students to understand) architecture look like. Lets say you have 30 simultaneous users in a clasroom - each of them would connect with websockets to the server and the server would pool/combine all of their requests into one and then return the combined file (some sort of minimal JSON or even just coordinates) for every connected user?
It sounds like you should probably store the current state somewhere and on the initial load of the application display that state. Then use your real-time infrastructure to send deltas on that state, or if it's a drawing on canvas, just information on the line etc. that has been drawn and information about who drew it.
Would websockets and (I'm guessing) canvas be able to take this? So that everything still looks snappy? Are there (jQuery-like) JS libraries available to make our lives easier - or do you think its something thats too complex for a 2-week summer school project?
Real-time collaborative drawing is most definitely achievable and there have been a number of examples created of this. A google bring up a number of possibilities.
If this technology is completely new to you and you would prefer to concentrate on building the collaborative application then I would consider using a service for your app rather than going through the hassle of learning how to install and configure, or even code, your own infrastructure (I'm not just saying this because I work for such a service. I honestly think it makes the most sense).

Related

Is phaser capable of large multiplayer games?

Newbie here. I am working with phaser, specifically with the isometric plugin.
I would like to know if it is possible to create games in phaser similar to agar.io, in terms of handling real-time multiple connections, generating a enormous map with about 300 players in it and all this without having too much impact in game performance. I seriously don't know how to handle the multiplayer part (probably sockets, node.js) for it to work really well. And as for generating a really big map I am quite blank too.
Is it possible, in phaser, to create a isometric-type game that handles multiples real time multiplayer and HUGE maps that are generated when the user gets to the edges of the visible "map"? How?
If not, what should I opt for (game engine in js and other applications) in order to achieve what I want?
You're not asking the right question, but you're close!
Your first guess is correct. You wouldn't handle multiplayer with Phaser, you'd use web sockets, or nodejs, or some other backend. So Phaser does not really limit you in what you can create with regards to multiplayer, since none of the networking code has anything to do with Phaser.
The idea of handling a huge map also just depends on how you optimize your graphics, regardless of what platform or framework you're using. For example, if you have huge or infinite maps, you can always just only show what's on screen, or around the edges of the screen, and use object pooling to show the rest of the map as the players move.
For multiplayer in Nodejs, check out Socket.io. It's really easy to use. I've set up a barebones example using it here. And in case you might find it helpful, here's an open source game I made for Ludum Dare in Phaser, with networking (this one is only p2p, so it's only made to handled 2 players connected to each other, but like I said, that's only a limitation of the multiplayer framework I used, in this case peerjs.com, and has nothing to do with Phaser itself, which can take care of all your rendering and game logic needs.)
Hopefully this helped answer some of your questions!
Phaser (at least in its 2.0 version) is not a good candidate for implementation of real time game networking as explained here.
If you're looking for a Javascript Multiplayer game engine you should check out Lance, which was written specifically for this purpose. You can then choose a renderer of your choice (Pixi.js, for example, if you're aiming to implement something like Agar.io. It's the same Renderer Phaser uses)
Regarding PhasedEvolution's comment above - Firebase is a nice tool if you're doing turn based games. It's not up to par for real-time game development as it doesn't allow low level access for any game-critical features that mitigate latency like client-size prediction, bending, interpolation and extrapolation.
Proper disclosure: I'm one of the co-creators of Lance :)

web page with multiple users or sessions

I'm working on a project where I want 1-to-n number of people to be able to access the same instance of a web page simultaneously.
An example of this would be something like iscribble.net where a person can create a drawing board, and other users can enter this board and draw simultaneously on the same board and chat etc...
what is this called? I can't find the right search term to look up a tutorial or something
You might try "real-time collaboration," which is often achieved through WebSockets or similar technology.
Socket.IO is a popular JavaScript implementation of WebSockets.
What you're looking for is indeed websockets. However, push notifications, depending on complexity and interaction of your idea may be what you really need. There are different services that offer these things, as well as many open source solutions that come packaged with such capability.
Parse.com is great for a beginner for a small push enabled app with a limited number of requests. (I do not work for Parse).
A websocket app in my opinion is for an advanced developer even when the websockets are handled by a server side game solution with functionality ready to go. I'd check out push on parse.com first in a prototype to get your feet wet and see if it works.

jQuery alternatives for multiplayer games?

First off, I am not asking for any code or anything like that.
all I need is some advise.
I'm creating a roulette game and everything in my roulette game is based on jQuery.
however, as we all know, jQuery is client side so I was thinking about using AJAX to send some details back to server and from the server to the users browser so I can make this roulette game work in "multiplayer" fashion... But the issue is that I don't think its possible to send the roulette's wheel animation to the server and back to users browser so I am a bit confused about this!
In my research I came across some information (old ones) about using node.js and jquery together! I don't know if this is possible or how easy it would be to use my jquery code in node.js as I have never used node.js before..
so the question that i have is:
based on the information i provided above and my requirements, what are my options?
can I use AJAX to achieve what i am trying to do and if so, a bit
information would be great.
if AJAX is out of question, is it possible to use my jquery code in
node.js to achieve what I am trying to do?
ANY ADVISE WOULD BE APPRECIATED.
P.S. I don't want to use HTML5 as 1st I don't know much about HTML5 and also, some devices, browsers do not support it.
Thanks
The best way is to use websockets to ensure real time communication. One of the best alternatives for implementing that could be using a server under node.js. Have a look to this video from Code School node.js tutorials: https://www.youtube.com/watch?v=mtDK4jf4RS0 where is ilustrated how to implement a real time chat. Your problem is based on the same.
There are three parts to a multiplayer game displayed in a browser:
client-side display,
server-side data management,
client-server communication.
If you're already set on your display technology (jQuery), then you're probably going to use $.ajax() for client-server communication. However, technologies used for server-side data management are completely up to you and they don't necessarily have any connection to the technologies used for display and communication (meaning the traditional communication initiated by client).
Basically, use any kind of server technology stack you like. Node.js might do just fine but there are many other viable alternatives. They just need to support communication with the client.
So, to be absolutely clear, your question doesn't really make sense. You might use jQuery in the client and Node.js on the server, but they will never really "work together". They will manage completely separate parts of your application and connect through protocols not specific to either of them.
As for the animation, the animation itself is solely a client-side problem. If you want to "synchronize the animation" across multiple clients, you can let the clients communicate with the server, but they only ever need to send/receive plain data. Then you adjust the client-side animation based on the received data.
As another poster points out, websockets are a better fit for this than regular client-initiated HTTP requests. Not because of "the animation", but because you want all the clients to receive the information about the start of betting at the same time.
I am also developing a MMO game using javascript only. Firstly, there are two different types of javascript here. Usual client side javascript (the one you already know) and the server side javascript (i.e. Node.js).
You will need to develop both client and server before connecting them with jQuery's Ajax. So you need to study Node.js before designing overall architecture of your game.
I read many Node.js tutorials and watched many youtube tutorial videos but I was still confused, before I really sat down and read a good textbook that explained from basics, one like below. Try to get hold of it from your local library.
Express web application development learn how to develop web applications with the Express framework from scratch by Hage Yaapa
Express is the popular framework that runs on Node.js now. So it's worth getting familiar with Express Framework. Once you understand how express app works (not so difficult), you will see how you can frame your game structure like I did :)
In order for many clients to share same animation, there must a server that synchronizes the game state. Ajax can only link between server-client communication in my understanding. There is no mechanism that connects between clients. The clients ask server what number was the result of roulette roll and show the corresponding animations.
Yes, you can use NodeJS and jQuery together.
NodeJS is server-side, meaning that you set up a server (a lot of people use the Express module, which is easy to use), which serves content to clients asking for it. Your server-side code can be in any language supporting sockets, not just NodeJS. But NodeJS is easy to use if you know JS already.
jQuery is client-side, meaning that it's executed by the user's browser, and may or may not have a server-side component (if it doesn't need it), or it might have one where it sends requests to the server-side code. When it requests a page from the server, it can be static content (like when you request index.html) or dynamic via an AJAX request. Client-side browser code must be HTML/CSS/JS (you can't make Firefox or Chrome interpret C, for example).

Starting game development in javascript. Where to draw the line between JS and Server Language

Im fairly proficient in php and am also learning python. I have been wanting to create a basic game for some time now and would like to create it in python. But in order to have a fancy smooth interface I need to use javascript (i dont much care for the flash/silverlight route). So I decided to start looking up game development in JavaScript. And in doing so most of the examples I have seen are games nearly completely done in javascript. And many of these games are quite nice.
But what im wondering, is if i combine python and javascript together for creating games; should I rely more heavily on javascript and let python do some of the background stuff? Or should I only use javascript for the basic UI elements, animation, flashy stuff and whatnot and keep the core game engine in python. Or some kind of mix between the two.
For php/python im mostly used to MVC style frameworks. So if i used JS only for the visuals would I just make heavy use of the in the view files as I would with a normal application? I know I can make a game in either language completely, but to use the best of both worlds im not quite sure where I should draw the line on letting python do work and letting JS do the work.
Also as a reference I would like to use some advanced features like canvas/svg and so on. Not really so much WebGL. And the game I have in mind to practice on is an isometric style RTS. The game will mostly be for learning. Im not really planning on releasing it.
Any input is appreciated.
Clarification:
the game will be web based. My web server is nginx. The games i would like to to would be multiplayer games where multiple people are playing online at the same time. Think world of warcraft. each server could hold up to N players that play against eachother. When that one is say 80% full a new one is spun up. Or something along those lines. I would like for the players to actually be able to interact with eachother live. Which is why in same ways i was also kind of looking into node.js but dont know as much about it yet. but seemed like it could fit.
--
Update: Im also planning on using mongodb as the database, if that matters to anyones answer.
to a certain extent, the problem can be considered in terms of economic forces, where you maximize your own utility and minimize costs. In the case of a game with a client/server aspect, The actual forces acting on you are
consuming server resources costs you actual money, but consuming client resources doesn't
clients could try to cheat, so you have to validate some of the data coming from a client
if you consume too much client resources, clients won't want to play, since their utility is outweighed by their costs.
Each of these points can be subtle enough to merit some additional discussion.
The actual cost of getting your game to clients comes in two parts, the cost of the physical hardware necessary to run the game, and the cost of the network bandwidth to distribute it to clients. Often you might have to trade one for the other; optimizing network usage means you have to be better at anticipating what clients will need or do, increasing processing demands, but offloading more of processing the work to the client means sending more data to the client.
There's only so much work the client can do, though. For instance You can't always trust the client to tell you where they aught to be, because that might mean that they are flying around in the air, or teleporting from place to place; You have to actually make sure that clients actually can do the things that they say they're doing. The particular nature of the game can determine how far you have to go, though. In man MMO games, extreme measures are often taken to limit the activity of bot players, but that often has a negative affect on real players. Strictly cooperative games often suffer less even when abusers are at work.
Not all potential users of your game have the best available hardware, or are willing to upgrade to the latest, fastest browser, So to make a successful game often means toning down the graphics enough so that a majority of users can play it.
Surprisingly, it's often the case that an either client or server approach doesn't actually produce the ideal results. Instead you have to implement key game logic in both places, On the client so that the game feels responsive to the user, but also on the server to mitigate abuse and decide player to player interactions fairly.
python would probably run on the server powering your web server.
If you want to write multiplayer client-server games then a lot of server code/logic would be in python.
If you want to write simpler singleplayer games then all your code is in the client (browser) and would be javascript. Python would just be there for serving your web game.
If you want to write desktop games you can do that in python using the pygame library.
So depends on what you want.
Multiplayer web game : client in JS, server in pythong
Singleplayer web game : client in JS, server only for serving web files
Desktop game : client in python.

options for building a realtime website

I'm going to build an webbased application which is controlling and monitoring tons of realtime data. think about few thousand valves pipes pumps and sensors.
Please list a technology stack you would use to build a realtime website with an educated guess about performance. The environment is 'ideal' all openstandards are available. so no IE6 etc backward compatibility is needed. Current and future proof technologies please.
server side:
database web-server - which one / combination makes it easy to support real-time pushing of data?
client side:
what kind of client environment (javascript Libraries) support showing and updating tons of realtime data?
You can have a look at Goliath
I recommend you have a look into Socket.IO which works best with Node.JS and might be the best fit for handling many long lasting concurrent real time connections. I would say that the choice of the database depends more on where your real time data is coming from and how it is supposed to get in the database.
Me too. So I'm writing a frame work that can do that. It's based on lighttpd front end, and multiple fcgi backend servers. The original Android was also tested with another framework that is based on it. It's open source so you might want to use it as a starting point.
I haven't been able to write a realtime app, but I've dabbled a bit with http://socket.io/ and node.js, and it's a joy to get started with.
App engine has a js channel api which seems nice. You should take a look to see if hosting on app engine is a option.
If you're dealing with "real time" stuff server-side, I recommend clojure for managing concurrent state.

Categories

Resources