-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbeaconScanner.js
81 lines (62 loc) · 1.6 KB
/
beaconScanner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var _blueooth = require('./lib/transports/bluetooth');
var _mHub = require('./lib/transports/mHub');
var router = function(){
var bluetooth = new _blueooth();
var mHub = new _mHub();
var client = new EventEmitter();
client.on('input', function(msg){
console.log(msg.target + " // " + JSON.stringify(msg.data))
})
var route1 = route_beaconRegistry(bluetooth, beacon, client);
if(null) {
route1.remove()
}
}
var route_beaconScanner = function(bluetooth, beacon, clientSess) {
var blueDef = [];
var beacDef = [];
var blueF = function(msg) {
var ret = false;
if(blueDef.length){
blueDef.forEach(function(v, i, a) {
if(v[0] === msg.target[0]){
ret = true;
v.forEach(function(vv, ii, aa){
if(ii > 0) { v[i]() }
})
}
})
}
if(!ret){
switch(msg.target[0]) {
case "scanResult":
//beacDef.push(['ack', 10000, function(){}])
beacon.emit('input', {
target: ["scanResult", "metaSchema"],
data: data
})
default:
client.emit('output', {
target: ["log"],
data: msg
})
}
}
}
var beacF = function(msg) {
if(blueDef.length){
// loop through deferrals, and if found, exectute and return
} else {
switch(msg.target[0]) {
case "scanResult":
default:
}
}
}
bluetooth.on('output', blueF)
beacon.on('output', beacF)
this.remove = function(){
beaconSess.removeListener('output', beacF)
registrySess.removeListener('output', regF)
}
}