Skip to content

Commit

Permalink
Multiplayer - expose the express app to the outside.
Browse files Browse the repository at this point in the history
  • Loading branch information
chr15m committed Mar 22, 2012
1 parent 9021194 commit 1fae9e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion demos/multiplayer/example-server.js
@@ -1,10 +1,16 @@
var s = require("../js/multiplayer/server");
var s = require("../../js/multiplayer/server");
var express = require("express");
// serve the jsGameSoup js folder statically
s.app.use("/js", express.static(__dirname + '/../../js'));

s.start();

// access to all clients:
console.log("Clients: " + s.clients);

// custom method to tell which clients are proximate to eachother
// this one partitions the page into one half and people clicking
// on one half can only see other click/drags on the same half
s.get_friends = function(client) {
// return some subset of s.clients that can be seen by client
// you can access client.state to filter clients
Expand Down
4 changes: 2 additions & 2 deletions demos/multiplayer/index.html
Expand Up @@ -18,8 +18,8 @@
</head>
<body>
<!--[if IE]><script src="../js/explorercanvas/excanvas.js"></script><![endif]-->
<script src="../js/json2.js"></script>
<script src="../js/jsgamesoup.js"></script>
<script src="js/json2.js"></script>
<script src="js/jsgamesoup.js"></script>
<script src="multiplayer.js"></script>
<script>
function startGame(gs) {
Expand Down
6 changes: 4 additions & 2 deletions js/multiplayer/server.js
Expand Up @@ -21,11 +21,10 @@ var app = express.createServer();
var client_dir = process.cwd();

// static serve our files
app.configure(function(){
app.configure(function() {
app.use(express.bodyParser());
app.use(express.logger({ format: ':url :method' }));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.use(express.static(client_dir));
});

/* Statically serve multiplayer.js and test page ****************************************************/
Expand All @@ -40,6 +39,9 @@ app.get('/test', function(req, res) {
res.sendfile(__dirname + '/test.html');
});

// give the user access to the express app itself
this.app = app;

/* dynamic ajaxy stuff for client ****************************************************************/

// unique ID counter for clients
Expand Down

0 comments on commit 1fae9e2

Please sign in to comment.