Browse Source

experimental sockets code

all-modes
Petr Balashov 8 years ago
parent
commit
08337f4196
  1. 38
      main.js
  2. 3
      package.json
  3. 10
      routes/shepherd.js

38
main.js

@ -33,6 +33,15 @@ if (os.platform() === 'linux') {
var shepherd = require('./routes/shepherd'),
guiapp = express();
guiapp.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://127.0.0.1:17777");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
next();
});
var appConfig = shepherd.loadLocalConfig(); // load app config
// preload.js
@ -71,10 +80,37 @@ guiapp.use('/shepherd', shepherd);
console.log(cluster)
*/
var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
/*var rungui = guiapp.listen(appConfig.iguanaAppPort, function () {
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!');
});*/
var server = require('http').createServer(guiapp);
var io = require('socket.io').listen(server);
server.listen(appConfig.iguanaAppPort, function() {
console.log('guiapp and sockets.io are listening on port ' + appConfig.iguanaAppPort + '!');
});
io.set('origins', 'http://127.0.0.1:17777');
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
client.on('event', function(data) {
console.log(data);
});
client.on('disconnect', function(data) {
console.log('EDEX GUI is disconnected');
});
client.on('join', function(data) {
console.log(data);
client.emit('messages', 'Sockets server is listening');
});
});
shepherd.setIO(io);
//io.emit('an event sent to all connected clients');
module.exports = guiapp;
// END GUI App Settings

3
package.json

@ -33,6 +33,7 @@
"mkdirp": "^0.5.1",
"pm2": "^2.3.0",
"ps-node": "^0.1.4",
"read-last-lines": "^1.1.0"
"read-last-lines": "^1.1.0",
"socket.io": "^1.7.3"
}
}

10
routes/shepherd.js

@ -91,6 +91,16 @@ shepherd.get('/appconf', function(req, res, next) {
res.send(obj);
});
shepherd.get('/socket-test', function(req, res, next) {
res.send('Sockets test');
shepherd.io.emit('messages', { 'message': 'legacy of grewal' });
});
// expose sockets obj
shepherd.setIO = function(io) {
shepherd.io = io;
};
/*
* params: pubkey
*/

Loading…
Cancel
Save