forked from thorpelawrence/alexa-spotify-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device-helper.js
32 lines (27 loc) · 850 Bytes
/
device-helper.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
function getDevices(req, cache) {
// Check if session is new
if (req.getSession().isNew()) {
// If new session try to use cache
return cache.get(req.getSession().details.user.userId + ":devices") || [];
}
else {
// If existing session use session data
return req.getSession().get("devices") || [];
}
}
function findDeviceByNumber(req, cache, deviceNumber) {
var devices = getDevices(req, cache);
var deviceId, deviceName;
// Iterate through devices to find ID and name by number
for (var i = 0; i < devices.length; i++) {
if (devices[i].number == deviceNumber) {
deviceId = devices[i].id;
deviceName = devices[i].name;
}
}
return { id: deviceId, name: deviceName };
}
module.exports = {
getDevices,
findDeviceByNumber
};