-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (41 loc) · 1.14 KB
/
index.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
const {Device} = require('ps4-waker');
// var ps4 = new Device();
// // ps4.turnOn().then(() => ps4.close());
// console.log(ps4);
const express = require('express')
const app = express()
const {NODE_PORT: port = 3300} = process.env;
app.get('/api/status', express.json(), async (req, res) => {
const ps4 = new Device();
const status = await ps4.getDeviceStatus();
console.log({status});
res.send(status);
});
app.post('/api/startTitle', express.json(), async (req, res, next) => {
try {
const { appId } = req.body;
if (!appId) {
throw new Error('appId is missing');
}
const ps4 = new Device();
const response = await ps4.startTitle(appId)
res.send(response)
} catch(e) {
next(e);
}
});
app.post('/api/sendKeys', express.json(), async (req, res, next) => {
try {
const { keys } = req.body;
if (!keys) {
throw new Error('keys is missing');
}
const ps4 = new Device();
const response = await ps4.sendKeys(keys)
res.send(response)
} catch(e) {
next(e);
}
});
app.use(express.static('web_client'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`))