-
Notifications
You must be signed in to change notification settings - Fork 1
/
Telemetry.js
44 lines (39 loc) · 1.48 KB
/
Telemetry.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
var Telemetry = {
live: true,
// Ensures that the payload has a valid type
validate: function(type) {
return ['tutorial_phase_started',
'tutorial_phase_completed',
'tutorial_action_taken', // Unimplemented
'tutorial_action_attempted', // Unimplemented
'citizen_added_to_building',
'citizen_removed_from_building',
'building_added',
'building_demolished',
'building_destroyed',
'private_money_added',
'minister_hired',
'minister_fired',
'turn_completed',
'game_lost',
'game_won', // Unimplemented
'game_restarted'
].includes(type);
},
// If telemetry is live and the payload type is valid, sends the payload to the server
send: function(payload) {
if (!Telemetry.live) return;
if (!Telemetry.validate(payload.type)) {
throw "Attempting to send telemetry with invalid type: " + payload.type;
return;
}
// Stamp payload with session ID
payload.sessionID = Global.sessionID;
// Send payload back to server
//console.log(payload.type, payload);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'Telemetry.php', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(payload));
},
};