-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
56 lines (45 loc) · 1.34 KB
/
helpers.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
module.exports = {
playSongs: function(playlist, inputPosition) {
if (!!playlist) {
// If we have reached the end of the playlist, start over from the beginning
let position = (inputPosition === playlist.length) ? 0 : inputPosition;
let song = playlist[position];
// app.set('currentlyPlaying', song.name);
audio = new Audio(song.link);
audio.addEventListener('playing')
audio.play();
position++;
audio.addEventListener('ended', () => {
// app.set('currentlyPlaying', 'BeatBox');
playSongs(playlist, position);
});
}
},
reverseString: function(string) {
let output = '';
for (let i = string.length - 1; i >= 0; i--) {
output += string[i];
}
return output;
},
isFolder: function(type) {
/**
* @function isFolder
* @param type {String} - represents file type as returned by Dropbox.
* @return {Boolean}
**/
return type === 'folder';
},
isSong: function(name) {
/**
* @function isSong
* @param name {String} - represents full name of file as returned by Dropbox.
* @return Boolean {True | False}
**/
return name.slice(-4) === '.mp3' || name.slice(-4) === '.m4a';
},
hasValidTempLink(song) {
const FOUR_HOURS = 14400000;
return (Date.now() - song.generatedAt) < FOUR_HOURS;
}
};