-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver-spectator.js
55 lines (45 loc) · 1 KB
/
driver-spectator.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
/*
* Sends a log to the /log API
*/
function sendLog(log) {
const data = JSON.stringify({
log: log,
});
const request = new XMLHttpRequest();
request.open('POST', 'http://localhost:8080/log', true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(data);
}
/*
* Updates spectator cam to target driver
*/
function updateCamera() {
const targetDriver = {
id: 5931666,
name: "Bruno Brito"
};
r3e.getDriversInfo(function (data) {
const driver = data.driversInfo
.find(each => each.portalId === targetDriver.id || each.name === targetDriver.name);
if (driver) {
sendLog({
event: 'setCamera.trackside',
data: {
driver: {
name: driver.name,
slotId: driver.slotId,
portalId: driver.portalId
}
}
});
r3e.setCamera.trackside(driver.slotId);
}
});
}
(function tick() {
setTimeout(tick, 10000);
sendLog({
event: 'tick'
});
updateCamera();
})();