Cube Slam is a Chrome Experiment built with
WebRTC, an open web technology that lets you communicate in real-time in the browser (and in this case, play an old-school arcade game with your friends) without downloading and installing any plug-ins. In this post, we wanted to explain a bit about how Cube Slam works.
Cube Slam uses
getUserMedia
to access your webcam and microphone (with your permission, of course),
RTCPeerConnection
to stream your video to a friend, and
RTCDataChannel
to transfer the bits that keep the gameplay in sync. If you and your friend are behind firewalls,
RTCPeerConnection
uses a
TURN relay server (hosted on Google Compute Engine) to make the connection. However, when there are no firewalls in the way, the entire game happens directly peer-to-peer, reducing latency for players and server costs for developers.
Cube Slam is the first large-scale application to use
RTCDataChannel
, which provides an API similar to
WebSocket, but sends the data over the
RTCPeerConnection
peer-to-peer link.
RTCDataChannel
sends data securely, and supports an "unreliable" mode for cases where you want high performance but don't care about every single packet making it across the network. In cases like games where low delay often matters more than perfect delivery, this ensures that a single stray packet doesn't slow down the whole app.
RTCDataChannel
supports unreliable mode in desktop Chrome today. We're working on implementing the latest
WebRTC spec, where we'll use the standard
SCTP protocol to support reliable mode as well. WebRTC will also be available on Chrome for Android later this year, and you can
try it now by flipping “Enable WebRTC Android” in chrome://flags. Several browsers are currently working on implementing WebRTC, and we’re looking forward to the day when you can have a Cube Slam face-off against your friends on any browser and any device.
To learn more about the tech in Cube Slam, you can check out our
technology page and
source code. Disable the shields! Destroy the screen! Have fun!
Posted by Justin Uberti, Software Engineer and Channeler of Data