-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.js
More file actions
29 lines (26 loc) · 778 Bytes
/
node_helper.js
File metadata and controls
29 lines (26 loc) · 778 Bytes
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
/* eslint-disable */
const NodeHelper = require("node_helper");
const axios = require("axios");
module.exports = NodeHelper.create({
async socketNotificationReceived(notification, payload) {
if (notification === "GetTrains") {
let data = {};
try {
let headers = {
Authorization: `Basic ${Buffer.from(
`${payload.username}:${payload.password}`
).toString("base64")}`
};
data.trainData = (
await axios.get(
`https://api.rtt.io/api/v1/json/search/${payload.origin}`,
{ headers }
)
).data;
} catch (error) {
data.error = error;
}
this.sendSocketNotification("GetTrainsResult", data);
}
}
});