Skip to content

Commit 606e42d

Browse files
committed
commit network stuff
1 parent 4c68726 commit 606e42d

18 files changed

+666
-72
lines changed

app.js

+6-56
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
var express = require('express');
3+
var connection = require('./connection/connection.js');
24
require('socket.io-client');
35
var app = express();
46

@@ -11,11 +13,9 @@ app.use(express.static(__dirname + '/public'));
1113
var io = require('socket.io').listen(app.listen(3000));
1214

1315

14-
//JUST Some Test Code Following
16+
// Login check
1517
io.use(function (socket, next) {
1618
console.log(socket.request.url);
17-
//console.log(socket.request._query);
18-
//console.log(socket.request);
1919
if (socket.request._query.username && socket.request._query.password) {
2020
console.log("Super");
2121
next();
@@ -26,10 +26,6 @@ io.use(function (socket, next) {
2626
//next(new Error('Authentication error'));
2727
});
2828

29-
var events = {
30-
"mytest": []
31-
};
32-
3329
/*io.on('connection', function (socket) {
3430
socket.emit('news', { hello: 'world' });
3531
socket.on('my other event', function (data) {
@@ -40,57 +36,11 @@ var events = {
4036
var counter = 0;
4137

4238
io.sockets.on('connection', function (socket) {
43-
socket.send("HELLO SOMEONE");
44-
if (!socket.dustin) {
45-
socket.dustin = counter;
46-
counter++;
47-
}
48-
console.log("NewUser: " + socket.dustin);
39+
console.log('Connected '+socket.id);
4940

50-
socket.on('message', function (msg) {
51-
console.log("Hallo Super");
52-
socket.send("Hallo " + msg);
53-
});
54-
socket.on('eventbind', function (msg) {
55-
if (!events[msg.event]) {
56-
events[msg.event] = [];
57-
}
58-
if (events[msg.event].indexOf(socket) < 0) {
59-
events[msg.event].push(socket);
60-
console.log("Add");
61-
}
62-
console.log(events.mytest.length);
63-
//socket.send("Hallo "+msg);
64-
});
65-
socket.on('triggerevent', function (msg) {
66-
if (events[msg.event]) {
67-
for (var i in events[msg.event]) {
68-
events[msg.event][i].send(msg.data);
69-
console.log("Trigger");
70-
}
71-
}
72-
console.log(events.mytest.length);
73-
//events[msg.event].push(socket);
74-
//socket.send("Hallo "+msg);
75-
});
76-
socket.on('ferret', function (name, fn) {
77-
78-
79-
fn('woot');
80-
socket.emit('ferret1', 'tobias', function (data) {
81-
console.log("FERET = > "+data); // data will be 'woot'
82-
});
83-
});
41+
connection.use(socket);
8442

8543
socket.on('disconnect', function () {
86-
console.log("LOG1");
87-
for (var i in events) {
88-
var j = events[i].indexOf(socket);
89-
if (j >= 0) {
90-
events[i].splice(j, 1);
91-
console.log("removed");
92-
}
93-
}
94-
console.log(events.mytest.length);
44+
console.log('Disconnected '+socket.id);
9545
});
9646
});

connection/clientTypes/adminpanel.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var config = require('../config.js');
2+
var configfunctions = require('../configfunctions.js');
3+
var configUpdateService = require('../services/configUpdateService.js');
4+
5+
var m = module.exports = {};
6+
7+
m.use = function (socket) {
8+
// client specific methods
9+
10+
// Add event listeners
11+
socket.on('setnetworkconfig', function (data) {
12+
configfunctions.setConfig(data.config);
13+
});
14+
15+
// required Services
16+
configUpdateService.use(socket);
17+
18+
19+
// Initial Data Push
20+
};

connection/clientTypes/cashpanel.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
3+
var iddService = require('../services/iddService.js');
4+
var configUpdateService = require('../services/configUpdateService.js');
5+
var priceUpdateService = require('../services/priceUpdateService.js');
6+
var config = require('../config.js');
7+
//var buy = require('../config.js');
8+
var m = module.exports = {};
9+
10+
m.use = function (socket) {
11+
// client specific methods
12+
13+
socket.iddscan = function (obj) {
14+
socket.emit('newbuy', {
15+
//'buy': buy.getNewBuy(obj.idk)
16+
'buy': {'test':42}
17+
});
18+
};
19+
20+
// Add event listeners
21+
socket.on('cashpanelbuy', function (data, fn) {
22+
if (config.data.clients[socket.clientid].type === 'cashpanel') {
23+
//buy.executeBuy(data, fn, fn);
24+
}
25+
});
26+
socket.on('cashscreen', function (data) {
27+
if (config.data.clients[socket.clientid].type === 'cashpanel' && config.data.clients[socket.clientid].cashscreen !== '') {
28+
if(config.runtime[config.data.clients[socket.clientid].cashscreen] && config.runtime[config.data.clients[socket.clientid].cashscreen].sockets){
29+
for(k in config.runtime[config.data.clients[socket.clientid].cashscreen].sockets){
30+
if(config.runtime[config.data.clients[socket.clientid].cashscreen].sockets[k].sendCashScreen){
31+
config.runtime[config.data.clients[socket.clientid].cashscreen].sockets[k].sendCashScreen(data);
32+
}
33+
}
34+
}
35+
}
36+
});
37+
38+
// required Services
39+
configUpdateService.use(socket);
40+
iddService.use(socket);
41+
priceUpdateService.use(socket);
42+
43+
// Initial Data Push
44+
};

connection/clientTypes/cashscreen.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var config = require('../config.js');
2+
var configfunctions = require('../configfunctions.js');
3+
4+
var m = module.exports = {};
5+
6+
m.use = function (socket) {
7+
// client specific methods
8+
socket.sendCashScreen = function(data){
9+
socket.emit('cashscreendata', {
10+
'data': data
11+
});
12+
}
13+
14+
// Add event listeners
15+
socket.on('setnetworkconfig', function (data) {
16+
configfunctions.setConfig(data.config);
17+
});
18+
19+
// required Services
20+
configUpdateService.use(socket);
21+
22+
23+
// Initial Data Push
24+
};

connection/clientTypes/connector.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
var iddService = require('../services/iddService.js');
3+
var configUpdateService = require('../services/configUpdateService.js');
4+
var config = require('../config.js');
5+
var m = module.exports = {};
6+
7+
m.use = function (socket) {
8+
// client specific methods
9+
10+
// Add event listeners
11+
12+
// required Services
13+
iddService.use(socket);
14+
configUpdateService.use(socket);
15+
16+
// Initial Data Push
17+
};

connection/clientTypes/monitor.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
var priceUpdateService = require('../services/priceUpdateService.js');
3+
var configUpdateService = require('../services/configUpdateService.js');
4+
5+
var config = require('../config.js');
6+
var m = module.exports = {};
7+
8+
m.use = function (socket) {
9+
// client specific methods
10+
11+
// Add event listeners
12+
13+
// required Services
14+
priceUpdateService.use(socket);
15+
configUpdateService.use(socket);
16+
17+
// Initial Data Push
18+
};

connection/config.js

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
var utils = require('../utils.js');
2+
3+
var m = module.exports = {};
4+
5+
m.device = function (_id, type, name, hid, client) {
6+
this._id = _id;
7+
this.type = type;
8+
this.name = name;
9+
this.hid = hid;
10+
this.client = client;
11+
};
12+
13+
m.client = function (_id, type, name, devices) {
14+
var devices = (devices && true) || false;
15+
this._id = _id;
16+
this.name = name;
17+
this.type = type;
18+
switch (type) {
19+
case 'adminpanel':
20+
this.maxsockets = 9999999;
21+
this.view = 'adminpanel';
22+
this.devices = false;
23+
break;
24+
case 'cashpanel':
25+
this.maxsockets = 1;
26+
this.idd = '';
27+
this.cashscreen = '';
28+
this.view = 'cashpanel';
29+
this.devices = devices;
30+
break;
31+
case 'cashscreen':
32+
this.maxsockets = 1;
33+
this.view = 'cashscreen';
34+
this.devices = devices;
35+
break;
36+
case 'monitor':
37+
this.maxsockets = 1;
38+
this.view = 'monitor';
39+
this.devices = devices;
40+
break;
41+
case 'connector':
42+
this.maxsockets = 9999999;
43+
this.view = 'adminpanel';
44+
this.devices = devices;
45+
break;
46+
}
47+
};
48+
49+
m.data = {
50+
'global': {
51+
'configmode': false,
52+
'devicenameprefix': 'device',
53+
'clientnameprefix': 'client'
54+
},
55+
'clients': {
56+
'client00': {
57+
'_id': 'client00',
58+
'name': 'ADMIN',
59+
'type': 'adminpanel',
60+
'maxsockets': 99999,
61+
'view': 'adminpanel',
62+
'devices': false
63+
},
64+
'client01': {
65+
'_id': 'client01',
66+
'name': 'Kasse 1',
67+
'type': 'cashpanel',
68+
'maxsockets': 1,
69+
'idd': 'device01',
70+
'view': 'cashpanel',
71+
'devices': true
72+
},
73+
'client02': {
74+
'_id': 'client02',
75+
'name': 'Kasse 2',
76+
'type': 'cashpanel',
77+
'maxsockets': 1,
78+
'idd': 'device02',
79+
'view': 'cashpanel',
80+
'devices': false
81+
},
82+
},
83+
'devices': {
84+
'device01': {
85+
'_id': 'device01',
86+
'type': 'idd',
87+
'name': 'RFID Device1',
88+
'hid': 'USB_02xd82jf'
89+
},
90+
'device02': {
91+
'_id': 'device02',
92+
'type': 'idd',
93+
'name': 'RFID Device2',
94+
'hid': 'USB_02xd82jh'
95+
},
96+
}
97+
}
98+
m.runtime = {
99+
'client00': {
100+
'sockets': [] //Socket
101+
102+
},
103+
'client01': {
104+
'sockets': [] //Socket
105+
106+
},
107+
'client02': {
108+
'sockets': [] //Socket
109+
110+
},
111+
'device01': {
112+
'client': 'client01'
113+
},
114+
'device02': {
115+
'client': 'client02'
116+
}
117+
}

0 commit comments

Comments
 (0)