Official package · Game engines

Multiplayer rooms for Cocos Creator

A client with no dependencies for Cocos Creator 3.x on web, native and mini-game builds, a HibiraConnection component that keeps the connection across scenes, and rooms with seats, a host, ready flags and chat.

  • Rooms speak the same events as the Lobby package, so Cocos and browser players can share a room.
  • The Lobby package’s matchmaking queue is included: players wait, get matched by rating and criteria, and land in a new room together.
  • Reconnects by itself and subscribes its channels again.
  • An auth endpoint as a Cloudflare Worker that runs on the free plan.

Sign in to see these snippets with your own cluster host. Sign in

  1. Set it up

    git clone https://github.com/hibira-io/cocos && cd cocos/server
    # put your app key in wrangler.toml, then:
    npx wrangler deploy
    npx wrangler secret put HIBIRA_APP_SECRET
  2. Install

    Copy assets/hibira into your project's assets/.
    Add the HibiraConnection component to a root node of the first scene:
      App Key:        YOUR_APP_KEY
      Host:           ws.hibira.io
      Auth Endpoint:  your Worker's URL
  3. Use it

    import { HibiraConnection } from './hibira/HibiraConnection';
    
    const hibira = HibiraConnection.instance!;
    hibira.setName('Ann');
    const room = hibira.joinRoom('ABCD', { capacity: 4 });
    room.on('members', ({ players, host }) => renderSeats(players, host));
    room.on('start', ({ data }) => startGame(data.seed));

Before you start

  • Turn on Allow client events in the app’s settings, so players can send each other moves and taps.
  • Add http://localhost:7456 (the editor’s browser preview) and the site of each web build to the app’s allowed origins. For mini-game builds, also add the WebSocket host and your auth endpoint to the platform’s allowed domains.

Use the app key from your dashboard; the secret stays on your server. Channels, events and authorization endpoints work exactly as they do with Pusher. Create your free account →