-
Notifications
You must be signed in to change notification settings - Fork 8
/
events.js
55 lines (46 loc) · 1.45 KB
/
events.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
var meiligao = require('../index.js');
// Set up server
var server = new meiligao.Server().listen(20180, function(error) {
if (error) {
throw error;
}
console.log('gps server is listening');
});
// Handle server connections
server.on('connect', function(tracker) {
console.log('tracker has connected');
/**
* Tracker events
*/
// Tracker requested login (and it was confirmed)
tracker.on('login', function(tracker) {
console.log('tracker has logged in');
});
// Heartbeat packets
tracker.on('heartbeat', function(tracker) {
console.log('tracker sent heartbeat');
});
// Most useful thing: alarms & reports
tracker.on('message', function(message, tracker) {
console.log('tracker sent message: [' + meiligao.Message.getMessageTypeByCode(message.type) + ']', message);
});
// Useful for debugging
tracker.on('packet.in', function(packet, tracker) {
console.log('incoming packet:', packet.toString());
});
tracker.on('packet.out', function(packet, tracker) {
console.log('outgoing packet:', packet.toString());
});
// Handle errors
tracker.on('error', function(error, buffer) {
console.log('error parsing message:', error, buffer);
});
// Handle disconnects
tracker.on('disconnect', function() {
console.log('tracker disconnected (tracker.disconnect)');
});
});
// Handle disconnects
server.on('disconnect', function(tracker) {
console.log('tracker disconnected (server.disconnect)');
});