How to use the colyseus.js.Client function in colyseus

To help you get started, we’ve selected a few colyseus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github colyseus / colyseus-loadtest / src / index.ts View on Github external
(async () => {
    for (let i = 0; i < numClients; i++) {
        const client = new Client(endpoint);

        const options = (typeof(scripting.requestJoinOptions) === "function")
            ? await scripting.requestJoinOptions.call(client, i)
            : {};

        client.joinOrCreate(roomName, options).then(room => {
            connections.push(room);

            // display serialization method in the UI
            const serializerIdText = (headerBox.children[2] as blessed.Widgets.TextElement);
            serializerIdText.content = `{yellow-fg}serialization method:{/yellow-fg} ${room.serializerId}`;

            room.connection.ws.addEventListener('message', (event) => {
                bytesReceived += new Uint8Array(event.data).length;
            });
github halftheopposite / tosios / packages / client / src / scenes / Game.tsx View on Github external
roomMaxPlayers: Number(parsedSearch.roomMaxPlayers),
      };
    } else {
      // The only thing to pass when joining an existing room is a player's name
      options = {
        playerName: localStorage.getItem('playerName'),
      };
    }

    // Connect
    try {
      const host = window.document.location.host.replace(/:.*/, '');
      const port = process.env.NODE_ENV !== 'production' ? Constants.WS_PORT : window.location.port;
      const url = window.location.protocol.replace('http', 'ws') + "//" + host + (port ? ':' + port : '');

      this.client = new Client(url);
      if (isNewRoom) {
        this.room = await this.client.create(Constants.ROOM_NAME, options);

        // We replace the "new" in the URL with the room's id
        window.history.replaceState(null, '', `/${this.room.id}`);
      } else {
        this.room = await this.client.joinById(roomId, options);
      }
    } catch (error) {
      navigate('/');
      return;
    }

    this.setState({
      playerId: this.room.sessionId,
    });
github endel / colyseus-tic-tac-toe / javascript-pixi / src / Application.js View on Github external
import SceneManager from './core/SceneManager'

import Clock from '@gamestdio/timer'
window.clock = new Clock();

import Tweener from 'tweener'
window.Tweener = Tweener
window.tweener = new Tweener();

// define endpoint based on environment
const endpoint = (window.location.hostname.indexOf("herokuapp") === -1)
  ? "ws://localhost:3553" // development (local)
  : `${window.location.protocol.replace("http", "ws")}//${window.location.hostname}` // production (remote)

import { Client } from 'colyseus.js'
window.colyseus = new Client(endpoint);

export default class Application {

  constructor () {
    this.background = new PIXI.Sprite.fromImage('images/background.jpg')
    this.background.pivot.x = this.background.width / 2
    this.background.pivot.y = this.background.height / 2

    this.width = 640;
    this.height = 640;

    this.scale = this.getMaxScale();

    // canvas size
    this.screenWidth = window.innerWidth
    this.screenHeight = window.innerHeight
github halftheopposite / tosios / packages / client / src / scenes / Home.tsx View on Github external
componentDidMount() {
    try {
      const host = window.document.location.host.replace(/:.*/, '');
      const port = process.env.NODE_ENV !== 'production' ? Constants.WS_PORT : window.location.port;
      const url = window.location.protocol.replace('http', 'ws') + "//" + host + (port ? ':' + port : '');

      this.client = new Client(url);
      this.setState({
        timer: setInterval(this.updateRooms, Constants.ROOM_REFRESH),
      }, this.updateRooms);
    } catch (error) {
      console.error(error);
    }
  }
github legendofmountainsea / LegendOfMountainSea / src / network / networkClient.js View on Github external
connect(){
		this._client = new Client(`ws://${this._ip}:${this._port}`);
		this._chatRoom = new ChatRoom({instance: this._client.join('chat')});
		this._isChatConnected = true;
	}
}