Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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;
});
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,
});
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
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);
}
}
connect(){
this._client = new Client(`ws://${this._ip}:${this._port}`);
this._chatRoom = new ChatRoom({instance: this._client.join('chat')});
this._isChatConnected = true;
}
}