Skip to content

Commit

Permalink
update example to use v0.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Dec 17, 2016
1 parent 6f3a6a3 commit 34c0fed
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions dist/colyseus.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions examples/colyseus.js

This file was deleted.

18 changes: 10 additions & 8 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ <h1><img src="https://github.com/gamestdio/colyseus/raw/master/examples/logo.png
console.log(client.id, "left", chatRoom.name)
})

chatRoom.onUpdate.add(function(state, patches) {
console.log("Patches:", patches)

var messages = (!patches)
? state.messages
: patches.map(function(patch) { return patch.value })
chatRoom.onUpdate.addOnce(function(state, patches) {
var messages = state.messages;

for (var i=0; i<messages.length; i++) {
var node = document.createElement("p");
node.innerHTML = messages[i]
document.getElementById('messages').appendChild(node)
node.innerHTML = messages[i];
document.getElementById('messages').appendChild(node);
}
})

chatRoom.state.listen("messages/:number", "add", function(i, message) {
var node = document.createElement("p");
node.innerHTML = message;
document.getElementById('messages').appendChild(node);
});

chatRoom.onData.add(function(data) {
console.log(client.id, "received on", chatRoom.name, data)
})
Expand Down
4 changes: 0 additions & 4 deletions examples/rooms/chat_room.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class ChatRoom extends Room {
constructor (options) {
super(options)

// this.useTimeline()

this.setPatchRate(1000 / 192);

this.setState({ messages: [] })
Expand All @@ -28,8 +26,6 @@ class ChatRoom extends Room {
}

onMessage (client, data) {
// TODO
// - When sending messages, it would be good to flag which handler is interested in them.
if (data.message == "kick") {
this.clients.filter(c => c.id !== client.id).forEach(other => other.close())

Expand Down
29 changes: 17 additions & 12 deletions examples/server.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
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();
const path = require('path');
const colyseus = require('colyseus');
const http = require('http');
const express = require('express');

var server = http.createServer(app)
, gameServer = new colyseus.Server({server: server})
const port = process.env.PORT || 2657;
const app = express();

gameServer.register('chat', ChatRoom)
gameServer.register('battle', BattleRoom)
const ChatRoom = require('./rooms/chat_room');
const BattleRoom = require('./rooms/battle_room');

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

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

app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, "..", "dist")));

server.listen(port);

console.log(`Listening on http://localhost:${ port }`)
console.log(`Listening on http://localhost:${ port }`);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"scripts": {
"start": "npm run build && nodemon --harmony ./examples/server.js",
"build-dist": "webpack --env.production",
"build": "tsc -d",
"watch": "tsc -d -w",
"build": "tsc && npm run build-dist",
"watch": "tsc -w",
"prepublish": "npm run build",
"test": "npm run build && mocha test/"
},
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": false,
"declaration": true,
"outDir": "lib"
},
"include": [
Expand Down

0 comments on commit 34c0fed

Please sign in to comment.