-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (51 loc) · 1.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
require('dotenv/config')
const { Neurosity } = require('@neurosity/sdk')
const { checkSignalQuality, checkDeviceStatus } = require('./crown/index.js')
let neurosity = null
async function main () {
try {
await checkEnvironmentVariables()
neurosity = new Neurosity({
timesync: true,
deviceId: process.env.DEVICE_ID
})
startProcessTerminationListeners()
// await signInNeurosity()
// await checkDeviceStatus(neurosity)
// await checkSignalQuality(neurosity)
} catch (error) {
console.log(error)
}
}
async function signInNeurosity () {
console.log('login into Neurosity Developer Console...\n')
const { user } = await neurosity.login({
email: process.env.EMAIL,
password: process.env.PASSWORD
})
if (user && user.refreshToken) {
console.log('login success...\n')
return true
}
}
async function checkEnvironmentVariables () {
return new Promise((resolve, reject) => {
const values = [
process.env.EMAIL,
process.env.PASSWORD,
process.env.DEVICE_ID
]
const isEnvOk = values.every((value) => value)
if (isEnvOk) resolve(true)
else reject(new Error('isEnvOk(): check environment values'))
})
}
function startProcessTerminationListeners () {
['SIGINT', 'exit'].map((eventName) =>
process.on(eventName, () => {
neurosity && neurosity.disconnect()
process.exit()
})
)
}
main()