socketio fixed

This commit is contained in:
Lukas Bachschwell 2017-03-13 13:53:22 +01:00
parent 961ab22a78
commit f727401af0
3 changed files with 21 additions and 4 deletions

View File

@ -1,6 +1,4 @@
'use strict';
//import io from('/socket.io/socket.io.js');
let io = require('socket.io-client')
let iosocket = io.connect();
// setup all my handlers
@ -8,6 +6,11 @@ iosocket.on('clientrefresh', () => {
location.reload();
});
iosocket.on('stateChange', () => {
location.reload();
});
// get my state
let context = 'main';
iosocket.emit('loadState',context);

View File

@ -1,5 +1,5 @@
var express = require('express');
var router = express.Router();
let express = require('express');
let router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
@ -12,3 +12,15 @@ router.get('/admin', function(req, res, next) {
});
module.exports = router;
//Nice trick to get io into my routes, not really needed right now
// http://stackoverflow.com/questions/24609991/using-socket-io-in-express-4-and-express-generators-bin-www
/*
module.exports = (io) => {
var app = require('express');
var router = app.Router();
io.on('connection', function(socket) {
});
return router;
};
*/

View File

@ -7,6 +7,8 @@
<link rel='stylesheet' href='/css/bootstrap.min.css' />
<script type='text/javascript' src='/js/jquery-3.1.1.min.js'></script>
<script type='text/javascript' src='/js/bootstrap.min.js'></script>
<script type='text/javascript' src='/socket.io/socket.io.js'></script>
<script type='text/javascript' src='/js/front_client.js'></script>
</head>
<body>