-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path8_move_ptz_camera.js
56 lines (41 loc) · 1.38 KB
/
8_move_ptz_camera.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
const RustPlus = require('../rustplus');
const Camera = require('../camera');
var rustplus = new RustPlus('ip', 'port', 'playerId', 'playerToken');
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
rustplus.on('connected', async () => {
console.log("connected");
// get a camera (must support PTZ)
const camera = rustplus.getCamera("PTZ1");
// wait until subscribed to camera
camera.on('subscribed', async () => {
console.log("subscribed to camera");
// move camera up 10 times
for(let i = 0; i < 10; i++){
await camera.move(Camera.Buttons.NONE, 0, 1);
await delay(100);
}
// move camera down 10 times
for(let i = 0; i < 10; i++){
await camera.move(Camera.Buttons.NONE, 0, -1);
await delay(100);
}
// move camera left 10 times
for(let i = 0; i < 10; i++){
await camera.move(Camera.Buttons.NONE, -1, 0);
await delay(100);
}
// move camera right 10 times
for(let i = 0; i < 10; i++){
await camera.move(Camera.Buttons.NONE, 1, 0);
await delay(100);
}
console.log("disconnecting");
await rustplus.disconnect();
});
// subscribe to camera
await camera.subscribe();
});
// connect to rust server
rustplus.connect();