diff --git a/client/garageserver.io.js b/client/garageserver.io.js index e69de29..c7b2a46 100644 --- a/client/garageserver.io.js +++ b/client/garageserver.io.js @@ -0,0 +1,13 @@ +window.GarageServerIO = (function (socketio) { + + this.io = socketio; + + var connectGarageServer = function (path) { + this.io.connect(path + '/garageserver'); + }; + + return { + connectGarageServer: connectGarageServer + }; + +}) (io); \ No newline at end of file diff --git a/example/app.js b/example/app.js index b775291..7dc098f 100644 --- a/example/app.js +++ b/example/app.js @@ -7,7 +7,9 @@ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') - , path = require('path'); + , path = require('path') + , io = require('socket.io') + , garageServer = require('../lib/server/garageserver.io'); var app = express(); @@ -30,6 +32,10 @@ app.configure('development', function(){ app.get('/', routes.index); app.get('/users', user.list); -http.createServer(app).listen(app.get('port'), function(){ +var server = http.createServer(app); + +server.listen(app.get('port'), function(){ console.log("Express server listening on port " + app.get('port')); }); + +garageServer.createGarageServer(io.listen(server), {}); diff --git a/example/views/layout.jade b/example/views/layout.jade index 1b7b305..20da798 100644 --- a/example/views/layout.jade +++ b/example/views/layout.jade @@ -3,5 +3,7 @@ html head title= title link(rel='stylesheet', href='/stylesheets/style.css') + script(src='/socket.io/socket.io.js') + script(src='/client/garageserver.io.js') body block content \ No newline at end of file diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index 7c8d902..448d462 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -1,19 +1,35 @@ -function GarageServer (io) { - this.io = io; +var garageServerGame = require('./garageservergame'); + +function GarageServer (socketio, options) { + this.io = socketio; + this.registerSocketEvents(this.io); + this.game = new garageServerGame.createGame(options); } -GarageServer.prototype.PlayerConnect = function (callback) { - this.io.sockets.on('connection', function (socket) { - callback(socket); - }); +GarageServer.prototype.registerSocketEvents = function () { + this.io.of('/garageserver.io').on('connection', function (socket) { + this.onPlayerConnect(socket); + }.bind(this)); + + this.io.of('/garageserver.io').on('disconnect', function (socket) { + this.onPlayerDisconnect(socket); + }.bind(this)); + + this.io.of('/garageserver.io').on('input', function (socket) { + this.onPlayerInput(socket); + }.bind(this)); }; -GarageServer.prototype.PlayerDisconnect = function (callback) { - this.io.sockets.on('connection', function (socket) { - callback(socket); - }); +GarageServer.prototype.onPlayerConnect = function (socket, callback) { + }; -exports.createGameServer = function (io, options){ - return new GarageServer(io); +GarageServer.prototype.onPlayerDisconnect = function (socket, callback) { +}; + +GarageServer.prototype.onPlayerInput = function (socket, callback) { +}; + +exports.createGarageServer = function (io, options){ + return new GarageServer(io, options); }; \ No newline at end of file diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js new file mode 100644 index 0000000..8af72fc --- /dev/null +++ b/lib/server/garageservergame.js @@ -0,0 +1,11 @@ +function GarageServerGame (options) { + +} + +GarageServerGame.prototype.update = function () { + +}; + +exports.createGame = function (options){ + return new GarageServerGame(options); +}; \ No newline at end of file