GameCast.dev logoGAMECAST.dev

Multiplayer
Browser Games
Made Easy

Chrome Browser Firefox Browser Safari Browser Edge Browser Opera Browser Apple Operating System Windows Operating System iOS Operating System Android Operating System Linux Operating System

GameCast.dev makes high performance browser-to-browser communication easy, even when transmitting across the globe. GameCast.dev works on desktops and laptops, phones, tablets & smart TVs running iOS, Android, MacOS, Windows and more.


API v1 - Massively Multiplayer

API v1 is the quickest way to get your multiplayer game up and running. It enables broadcasting of messages to all players in your game. This is good for Massively Multiplayer Online Games (MMO) style games or simply getting your game working inside a single room. Once you have mastered this API you can move on to API v2 if your game needs multiple rooms.

To use the API in your own game, simply add this JavaScript to your game's code:

<script type="module">
import { gcOpen, gcSendFast, gcOnReceive } from 'https://gamecast.dev/gamecast-dev-v1.js'

gcOpen(() => {
  gcOnReceive(msg => alert('Message received from another player!'))

  document.querySelector('button.v1').onclick = () => {
    gcSendFast('Hello! Test button pressed by another player.')
    alert('Sent a message to all other players viewing this page!')
  }
})
</script>
  

The above code is already running in this webpage. Click here to open another browser window to test the code:

Function Descriptions

gcOpen(()=>{})
Sending and receiving messages to other players only starts once this callback is called.
gcSendFast(message)
Your game must join a room before any messages can be sent or received. Once a room is joined, this function call will send the message to all players in that room.

Note that messages are sent as fast as possible and with minimal latency so you can code the best possible browser based realtime action games. As a consequence, messages may be occasionally dropped, be received out of order, or be received as a duplicate. You need to design your netcode logic to accomodate for these conditions.

gcOnReceive(message=>{})
This function's callback will allow your player to receive messages sent by any other player in the game.

API v2 - Rooms

This version introduces rooms. Rooms are needed when your game plays best with a limited numbers of players in each game. You can create a room and players will be able to join the room until it is full. When all available rooms are full, a new room is spawned. Group of players will now be playing together in their own rooms.

Players inside a room can send messages to each other. Players outside of the room cannot listen to those messages. No messages can be sent or received until your player has joined a room.

To use the API on your own webpage, add this JavaScript:

<script type="module">
import { gcOpen, gcSendFast, gcOnReceive, gcRoomPublicJoin } from 'https://gamecast.dev/gamecast-dev-v2.js'

gcOpen(() => gcRoomPublicJoin(2))

gcOnReceive(msg => alert('Message received from another player!'))

document.querySelector('button#v2').onclick = () => {
  gcSendFast('Hello! Test button pressed by another player.')
  alert('Sent a message to all other players in this room!')
}
</script>

The above code is already running in this webpage. Click here to open another browser window to test the code:

Function Descriptions

gcOpen(()=>{})
Joining rooms and sending and receiving messages can only happen inside this function's callback.
gcSendFast(message)
Your game must join a room before any messages can be sent or received. Once a room is joined, this function call will send the message to all players in that room.

Note that messages are sent as fast as possible and with minimal latency so you can code the best possible browser based realtime action games. As a consequence, messages may be occasionally dropped, be received out of order, or be received as a duplicate. You need to design your netcode logic to accomodate for these conditions.

gcOnReceive(message=>{})
Your game must join a room before any messages can be sent or received. Once a room is joined, this function's callback will allow your game to receive messages from any players in this room.
gcRoomPublicJoin(maxPlayers, ()=>{})
Calling gcRoomPublicJoin(4), for example, will join the first available public room that has a maximum player limit of 4 players, or create a new public room with a maximum player limit of 4 players if there is not one with space currently available.
gcRoomLeave()
Leave the room. Your player will no longer be able to send or receive messages.

API v3 - Reliable Messaging

This version introduces ultra fast, game optimised reliable messaging. GameCast.dev's reliable messaging provides the fastest possible message delivery by not imposing ordering constraints and by trading off extra bandwitdh for faster reliable messages than non game oriented reliable messaging protocols like TCP.

Reliable messaging is useful in a gaming context when you want to know, for instance, when a player has been shot by another player, or when a player has picked a certain in-game object up.

To use the API on your own webpage, add this JavaScript:

<script type="module">
import { gcOpen, gcSendReliably, gcOnReceive, gcRoomPublicJoin } from 'https://gamecast.dev/gamecast-dev-v3.js'

gcOpen(() => gcRoomPublicJoin(2))

gcOnReceive(msg => document.querySelector('span.v3').textContent = `Message ${++r} received from another player!`)

document.querySelector('button.v3').onclick = () => {
  gcSendReliably('Hello! Test button pressed by another player.')
  document.querySelector('span.v3').textContent = `Sent message ${++s} to all other players in this room!`
}
</script>

The above code is already running in this webpage. Click here to open another browser window to test the code:

Function Descriptions

gcOpen(()=>{})
Joining rooms and sending and receiving messages can only happen inside this function's callback.
gcSendFast(message)
Your game must join a room before any messages can be sent or received. Once a room is joined, this function call will send the message to all players in that room.

Note that messages are sent as fast as possible and with minimal latency so you can code the best possible browser based realtime action games. As a consequence, messages may be occasionally dropped, be received out of order, or be received as a duplicate. You need to design your netcode logic to accomodate for these conditions.

gcSendReliably(message)
Your game must join a room before any messages can be sent or received. Once a room is joined, this function call will send the message to all players in that room.

Messages are sent reliably and with minimal latency so you can code the best possible browser based realtime action games. Messages may be occasionally received out of order.

gcOnReceive(message=>{})
Your game must join a room before any messages can be sent or received. Once a room is joined, this function's callback will allow your game to receive messages from any players in this room.
gcRoomPublicJoin(maxPlayers, ()=>{})
Calling gcRoomPublicJoin(4), for example, will join the first available public room that has a maximum player limit of 4 players, or create a new public room with a maximum player limit of 4 players if there is not one with space currently available.
gcRoomLeave()
Leave the room. Your player will no longer be able to send or receive messages.