How to use the colyseus.Server 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-monitor / example / Server.ts View on Github external
const app = express();
app.use(cors());

//
// DO NOT COPY THIS BLOCK ON YOUR ENVIRONMENT
// development only
//
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackConfig = require("../webpack.config");
app.use(webpackDevMiddleware(webpack(webpackConfig({ })), { }));

// Create HTTP & WebSocket servers
const server = http.createServer(app);
const gameServer = new Server({
    server,
    // presence: new RedisPresence()
});

// Register ChatRoom as "chat"
gameServer.register("chat", ChatRoom);

app.use("/colyseus", monitor(gameServer));

gameServer.listen(port);

console.log(`Listening on ws://${ endpoint }:${ port }`)
github colyseus / colyseus-unity3d / Server / index.ts View on Github external
import { DemoRoom } from "./DemoRoom";

import socialRoutes from "@colyseus/social/express";
import { FossilDeltaTestRoom } from "./FossilDeltaTestRoom";

const PORT = Number(process.env.PORT || 2567);

const app = express();

/**
 * CORS should be used during development only.
 * Please remove CORS on production, unless you're hosting the server and client on different domains.
 */
app.use(cors());

const gameServer = new Server({
  server: http.createServer(app),
  pingInterval: 0,
});

// Register DemoRoom as "demo"
gameServer.define("demo", DemoRoom);
gameServer.define("fossildelta", FossilDeltaTestRoom);

app.use("/", socialRoutes);

app.get("/something", function (req, res) {
  console.log("something!", process.pid);
  res.send("Hey!");
});

// Listen on specified PORT number
github colyseus / colyseus-unity3d / Server / index.js View on Github external
const http = require("http");
const express = require("express");

const colyseus = require("colyseus");
const DemoRoom = require('./demo_room');

const PORT = process.env.PORT || 2567;

const app = new express();
const gameServer = new colyseus.Server({
  server: http.createServer(app)
});

// Register DemoRoom as "chat"
gameServer.register("demo", DemoRoom);

app.get("/something", function (req, res) {
  console.log("something!", process.pid);
  res.send("Hey!");
});

// Listen on specified PORT number
gameServer.listen(PORT);

console.log("Running on ws://localhost:" + PORT);
github cyclegtx / colyseus-iog-state-sync / index.ts View on Github external
import * as serveIndex from 'serve-index';
import { createServer } from 'http';
import { Server } from 'colyseus';
import { monitor } from '@colyseus/monitor';

// Import demo room handlers
import { GameRoom as ExampleRoom } from "./Games/Example/GameRoom";
import { GameRoom as ExampleBodiesRoom } from './Games/ExampleBodies/GameRoom';
import { GameRoom as BattleGroundRoom } from './Games/BattleGround/GameRoom';


const port = Number(process.env.PORT || 2567);
const app = express();

// Attach WebSocket Server on HTTP Server.
const gameServer = new Server({
  server: createServer(app)
});

gameServer.register("ExampleRoom", ExampleRoom);

gameServer.register("ExampleBodiesRoom", ExampleBodiesRoom);
gameServer.register("BattleGroundRoom", BattleGroundRoom);

app.use('/', express.static(path.join(__dirname, "static")));
app.use('/', serveIndex(path.join(__dirname, "static"), {'icons': true}))

// (optional) attach web monitoring panel
app.use('/colyseus', monitor(gameServer));

gameServer.onShutdown(function(){
  console.log(`game server is going down.`);
github halftheopposite / tosios / packages / server / src / index.ts View on Github external
import { Server } from 'colyseus';
import * as cors from 'cors';
import * as express from 'express';
import { createServer } from 'http';

import { join } from 'path';
import { GameRoom } from './rooms/GameRoom';

const PORT = Number(process.env.PORT || Constants.WS_PORT);

const app = express();
app.use(cors());
app.use(express.json());

// Game server
const server = new Server({
  server: createServer(app),
  express: app,
});

// Game Rooms
server.define(Constants.ROOM_NAME, GameRoom);

// Serve static resources from the "public" folder
app.use(express.static(join(__dirname, 'public')));

// If you don't want people accessing your server stats, comment this line.
app.use('/colyseus', monitor(server));

// Serve the frontend client
app.get('*', (req: any, res: any) => {
  res.sendFile(join(__dirname, 'public', 'index.html'));
github colyseus / colyseus.js / examples / server.js View on Github external
var colyseus = require('colyseus')
  , ChatRoom = require('./rooms/chat_room')
  , BattleRoom = require('./rooms/battle_room')
  , http = require('http')
  , express = require('express')
  , port = process.env.PORT || 2657
  , app = express();

var server = http.createServer(app)
  , gameServer = new colyseus.Server({server: server})

gameServer.register('chat', ChatRoom)
gameServer.register('battle', BattleRoom)

app.use(express.static(__dirname));
server.listen(port);

console.log(`Listening on http://localhost:${ port }`)
github endel / colyseus-tic-tac-toe / server / index.js View on Github external
const colyseus = require('colyseus');
const http = require('http');

const express = require('express');
const app = express();
const port = process.env.PORT || 3553;

const server = http.createServer(app);
const gameServer = new colyseus.Server({server: server});

gameServer.register('tictactoe', require('./rooms/tictactoe'));
server.listen(port);

app.use(express.static(__dirname + "/../frontend/public"));
console.log(`Listening on ws://localhost:${ port }`);
github doorbash / agar.io-clone / server / src / index.ts View on Github external
import * as express from 'express';
import { Server } from "colyseus";
import { createServer } from "http";
import FreeForAll from './rooms/FreeForAll';

const port = 2560

const app = express();
app.use(express.json());

const gameServer = new Server({
  server: createServer(app),
  express: app,
});

gameServer.define("ffa", FreeForAll);

gameServer.listen(port);