Cube Slam uses
getUserMediato access your webcam and microphone (with your permission, of course),
RTCPeerConnectionto stream your video to a friend, and
RTCDataChannelto transfer the bits that keep the gameplay in sync. If you and your friend are behind firewalls,
RTCPeerConnectionuses 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
RTCDataChannelsends 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.
RTCDataChannelsupports 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