As you may know, js13kGames competition has the Server category since 2013, and by “server” we mean “⚡🔥multiplayer💥🌶”. However, we could never implement a STUN server (the basic infrastructure to how WebRTC works) and a great game inside 13k size limit. And since 2014 we have (a necessary) technical restrictions to the implementation of some server features that make it impossible to add STUN functionality to a simple game.
Well, the only good solution is to flexibilize the Rule #3 (No external libraries or services) to allow connection to Google’s STUN servers:
Why is this interesting and why you should consider this in your next game
WebRTC is a technology to allow P2P connections between web browsers…
Hey, and why that talk about server implementation?
Well, in this world where the internet is a huddle of NATs, no end-user application can simply start to talk with another end-user application without someone with a public address to intermediate the connection of those peers.
That said, with WebRTC you can exchange media streams and data without a server between them, receiving and processing all data.
The first obvious opportunity is to merge users’ voice and video interactions as a piece of the game.
The second opportunity is to find a way to allow many player rooms without exploding the small free Heroku server we are using to host all Server category games in the js13kGames competition.
Let me explain: in most multiplayer game implementations the game logic runs on the server. If the game is a MMO or it has rooms for a limited number of players in a session, the server will slow down a bit for each player. And that will become a performance problem fast on a free server.
You must use creativity to solve the MMO problem with WebRTC, however, for room based server games, you can simply make the user who had created the room as the game logic processor, just change the place where you would put that code.
Great! How do I implement WebRTC?
I can give you some nice links providing all you need to know (and some code to copy and paste):
⚠ Remember: the js13kGames competition allows only the public Google’s STUN servers. No others, and no TURN servers allowed.