add socket connection
This commit is contained in:
parent
1de440cedb
commit
9787a9d468
9 changed files with 7302 additions and 9 deletions
|
@ -4,9 +4,13 @@
|
|||
<meta charset="UTF-8">
|
||||
<link rel="icon" type="image/png" href="img/favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="css/styles.css">
|
||||
|
||||
<title>
|
||||
Starbugs
|
||||
</title>
|
||||
|
||||
<script src="js/lib/socket.io.js"></script>
|
||||
|
||||
<script src="starbugs.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
7252
public/js/lib/socket.io.js
Normal file
7252
public/js/lib/socket.io.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,6 +2,8 @@
|
|||
|
||||
window.addEventListener('load', init);
|
||||
|
||||
function init() {
|
||||
var socket;
|
||||
|
||||
function init() {
|
||||
socket = io.connect('http://localhost:8080');
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
const socketio = require('socket.io');
|
||||
const GameNet = require('./net');
|
||||
|
||||
class GameServer {
|
||||
constructor() {
|
||||
|
||||
constructor(webServer) {
|
||||
this.net = new GameNet();
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
this.net.listen();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
server/game/net/connection.js
Normal file
9
server/game/net/connection.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
class Connection {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Connection;
|
0
server/game/net/events.js
Normal file
0
server/game/net/events.js
Normal file
25
server/game/net/index.js
Normal file
25
server/game/net/index.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
const socketio = require('socket.io');
|
||||
|
||||
const Connection = require('./connection.js');
|
||||
|
||||
class GameNet {
|
||||
constructor() {
|
||||
this.io = socketio(starbugs.webServer.appServer);
|
||||
}
|
||||
|
||||
listen() {
|
||||
let io = this.io;
|
||||
|
||||
this.io.on('connection', socket => {
|
||||
console.log('connection');
|
||||
|
||||
socket.on('other event', data => {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GameNet;
|
0
server/game/room/index.js
Normal file
0
server/game/room/index.js
Normal file
|
@ -1,16 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const http = require('http');
|
||||
|
||||
const minify = require('./minify.js');
|
||||
|
||||
class WebServer {
|
||||
constructor() {
|
||||
|
||||
this.app = express();
|
||||
this.appServer = http.Server(this.app);
|
||||
}
|
||||
|
||||
start() {
|
||||
this.app = express();
|
||||
this.appServer.listen(8080);
|
||||
|
||||
let app = this.app;
|
||||
|
||||
app.get('/starbugs.min.js', (req, res) => {
|
||||
|
@ -21,8 +24,6 @@ class WebServer {
|
|||
});
|
||||
|
||||
app.use(express.static('public'));
|
||||
|
||||
app.listen(8080);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue