This commit is contained in:
frtk 2016-02-12 20:05:23 +01:00
parent d27f957f82
commit 316f15db48
5 changed files with 41 additions and 69 deletions

View File

@ -21,34 +21,6 @@
</html> </html>
<!--
<script type="text/javascript">
//console.log(io);
var socket = {};
if (typeof io !== 'object') {
console.log('Client: io object is unknown');
}
if ((typeof self.socket.socket === 'undefined')) {
console.log('[#SocketClient] attempting server connection...');
socket = io.connect(); // socket connection
console.log('[#SocketClient] attempting server connection...');
//socket.socket.connect();
}
socket.emit('data', 'yo');
</script>
-->
<!--
<script type="text/javascript">
console.log(io);
// NPGClient.io = io;
// NPGClient.SocketClient.setIO(io);
NPGClient.SocketClient.connect();
NPGClient.SocketClient.socket.emit('data','yo');
</script>
-->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
NPGClient.SocketIO.startConnectLoop();; NPGClient.SocketIO.startConnectLoop();;

View File

@ -13,39 +13,33 @@ var express = require('express');
var http = require('http'); var http = require('http');
//--- server app libs & params //--- server app libs & params
//var servP = require('./server/server_config.js'); //var servP = require('./server/server_config.js');
var nPong = require('./server/server_core.js'); var npg = require('./server/server_core.js');
//--- nodePong config //--- nodePong config
var config = require('./server/server_config.js'); var cfg = require('./server/server_config.js');
// //
nPong.Server.setVersion(config.VERSION); npg.NPGServer.init(cfg.Config);
nPong.Server.log("$ ##### nodePong - v" + nPong.Server.version);
/* /*
* starting HTTP and socket.io services * starting HTTP and socket.io services
*/ */
//--- HTTP server //--- HTTP server
nPong.Server.log("$ # starting http service on port " + config.HTTP.port); npg.NPGServer.log("$ # starting http service on port " + npg.NPGServer.port);
var app = express(); var app = express();
var httpserv = http.createServer(app); var httpserv = http.createServer(app);
httpserv.listen(config.HTTP.port); httpserv.listen(npg.NPGServer.port);
//--- allow access to static files from "/client" directory //--- allow access to static files from "/client" directory
app.use(express.static(__dirname + '/client/')); app.use(express.static(__dirname + '/client/'));
//--- socket.io //--- socket.io
nPong.Server.log('$ # registering socket.io service on port ' + config.HTTP.port); npg.NPGServer.log('$ # registering socket.io service on port ' + npg.NPGServer.port);
var io = require('socket.io').listen(httpserv, { log: true } ); var io = require('socket.io').listen(httpserv, { log: true } );
//-- setup server socket handling features //-- setup server socket handling features
nPong.Server.socketHandling(io); npg.NPGServer.socketHandling(io);
// //
nPong.Server.log('$ #####'); npg.NPGServer.log('$ #####');

View File

@ -3,13 +3,12 @@
* @author frtk * @author frtk
*/ */
var VERSION = '0.0.5'; var Config = {
VERSION : '0.0.6',
/** HTTP: {
* HTTP Service host: '127.0.0.1',
*/ port: 8042
var HTTP = { },
port: 8042,
} }
@ -20,6 +19,5 @@ var HTTP = {
* *
*/ */
if (typeof exports !== "undefined") { if (typeof exports !== "undefined") {
exports.HTTP = HTTP; exports.Config = Config;
exports.VERSION = VERSION;
} }

View File

@ -10,13 +10,16 @@
* nodePong Server Object * nodePong Server Object
* *
*/ */
var Server = { var NPGServer = {
/* /*
* Data * Data
*/ */
// version // app
version: '', version: '',
host: '',
port: 0,
// Users and Games // Users and Games
users: [], users: [],
games: [], games: [],
@ -26,9 +29,12 @@ var Server = {
* *
*/ */
//--- init() //--- init()
init: function() { init: function(o) {
var self = this; var self = this;
self.version = o.VERSION || '';
self.host = o.HTTP.host || '';
self.port = o.HTTP.port || 8042;
self.log('$ ##### nodePong - v'+self.version);
}, },
@ -37,10 +43,6 @@ var Server = {
this.version = s; this.version = s;
}, },
//--- setIO(io)
setIO: function(io) {
},
/* /*
* Server Messages * Server Messages
@ -90,16 +92,14 @@ var Server = {
socketHandling: function(io) { socketHandling: function(io) {
var self = this; var self = this;
io.sockets.on('connection', function (socket) { io.sockets.on('connection', function (socket) {
// //
self.log('$ User connected : id=' + socket.id); self.log('$ User connected : id=' + socket.id);
// 'disconnect' // 'disconnect'
socket.on('disconnect', function () { socket.on('disconnect', function () { self.log('$ User disconnected : id=' + socket.id);
self.log('$ User disconnected : id=' + socket.id);
connected = false;
}); });
//
}); });
}, },
@ -135,7 +135,7 @@ var Game = function() {
* *
*/ */
if (typeof exports !== "undefined") { if (typeof exports !== "undefined") {
exports.Server = Server; exports.NPGServer = NPGServer;
exports.User = User; exports.User = User;
exports.Game = Game; exports.Game = Game;
} }

View File

@ -1,7 +1,15 @@
### **v0.0.7:**
--- focus on server object
- Renamed server object in server_core.js (Server -> NPGServer)
- Removed setIO(io) function in NPGServer object
- added init() function to NPGClient
- Changed server_config.js structure
- updated nodePong.js
### **v0.0.6:** ### **v0.0.6:**
- focus on socket.io client & server) --- focus on socket.io client & server)
- Renamed SocketClient.js to SocketIO.js (files and objects) - Renamed SocketClient.js to SocketIO.js (files and objects)
- Added SocketIO object (NGPClient lib in /client/js/) - Added SocketIO object (NGPClient lib in /client/js/)
- Implemented socket.io client connection (with loop) => working - Implemented socket.io client connection (with loop) => working