prettier formatting

This commit is contained in:
Egor 2017-12-09 19:32:12 -08:00
parent ea6eb4f968
commit b64e19c3fe
13 changed files with 279 additions and 214 deletions

4
.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"singleQuote": true,
"printWidth": 140
}

View file

@ -9,6 +9,7 @@ module.exports = {
browser: true browser: true
}, },
rules: { rules: {
'no-debugger': 'off'
}, },
globals: { globals: {
chrome: false, chrome: false,

View file

@ -1,15 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Component, observer, computed, on, isNone, run: { later }, $, String: { htmlSafe } } = Ember;
Component,
observer,
computed,
on,
isNone,
run: { later },
$,
String: { htmlSafe }
} = Ember;
export default Component.extend({ export default Component.extend({
elementId: 'bridge-finder', elementId: 'bridge-finder',
@ -31,17 +22,20 @@ export default Component.extend({
isAuthenticating: computed.notEmpty('bridgePingIntervalHandle'), isAuthenticating: computed.notEmpty('bridgePingIntervalHandle'),
// try to authenticate against the bridge here // try to authenticate against the bridge here
onBridgeIpChange: on('init', observer('bridgeIp', function () { onBridgeIpChange: on(
'init',
observer('bridgeIp', function() {
if (!this.get('trial') && !this.get('isAuthenticating')) { if (!this.get('trial') && !this.get('isAuthenticating')) {
this.setProperties({ this.setProperties({
bridgePingIntervalHandle: setInterval(this.pingBridgeUser.bind(this), this.get('bridgeUsernamePingIntervalTime')), bridgePingIntervalHandle: setInterval(this.pingBridgeUser.bind(this), this.get('bridgeUsernamePingIntervalTime')),
bridgeUserNamePingIntervalProgress: 0 bridgeUserNamePingIntervalProgress: 0
}); });
} }
})), })
),
didInsertElement() { didInsertElement() {
$(document).keypress((event) => { $(document).keypress(event => {
if (!isNone(this.get('manualBridgeIp')) && event.which === 13) { if (!isNone(this.get('manualBridgeIp')) && event.which === 13) {
this.send('findBridgeByIp'); this.send('findBridgeByIp');
} }
@ -90,10 +84,11 @@ export default Component.extend({
if (bridgeIp !== null && bridgeUserNamePingIntervalProgress < 100) { if (bridgeIp !== null && bridgeUserNamePingIntervalProgress < 100) {
$.ajax('http://' + bridgeIp + '/api', { $.ajax('http://' + bridgeIp + '/api', {
data: JSON.stringify({ "devicetype": "huegasm" }), data: JSON.stringify({ devicetype: 'huegasm' }),
contentType: 'application/json', contentType: 'application/json',
type: 'POST' type: 'POST'
}).done((result, status) => { })
.done((result, status) => {
if (!this.isDestroyed) { if (!this.isDestroyed) {
if (status === 'success' && !result[0].error) { if (status === 'success' && !result[0].error) {
this.clearBridgePingIntervalHandle(); this.clearBridgePingIntervalHandle();
@ -101,16 +96,22 @@ export default Component.extend({
this.set('bridgeUsername', result[0].success.username); this.set('bridgeUsername', result[0].success.username);
} }
} }
}).fail(() => { })
.fail(() => {
this.clearBridgePingIntervalHandle(); this.clearBridgePingIntervalHandle();
this.setProperties({ this.setProperties({
bridgeConnectError: true, bridgeConnectError: true,
bridgeConnectMessage: htmlSafe('Your network and/or computer security settings are preventing Huegasm from connecting to your Hue bridge.' + bridgeConnectMessage: htmlSafe(
'<br><span>Feel free to contact us at <a href="mailto:huegasm.app@gmail.com">huegasm.app@gmail.com</a> if this is unexpected and you need help debugging the problem.</span>') 'Your network and/or computer security settings are preventing Huegasm from connecting to your Hue bridge.' +
}) '<br><span>Feel free to contact us at <a href="mailto:huegasm.app@gmail.com">huegasm.app@gmail.com</a> if this is unexpected and you need help debugging the problem.</span>'
)
});
}); });
this.incrementProperty('bridgeUserNamePingIntervalProgress', this.get('bridgeUsernamePingIntervalTime') / bridgeUsernamePingMaxTime * 100); this.incrementProperty(
'bridgeUserNamePingIntervalProgress',
this.get('bridgeUsernamePingIntervalTime') / bridgeUsernamePingMaxTime * 100
);
} else { } else {
this.clearBridgePingIntervalHandle(); this.clearBridgePingIntervalHandle();
} }
@ -140,18 +141,24 @@ export default Component.extend({
}); });
} else { } else {
$.ajax('http://' + manualBridgeIp + '/api', { $.ajax('http://' + manualBridgeIp + '/api', {
data: JSON.stringify({ "devicetype": "huegasm" }), data: JSON.stringify({ devicetype: 'huegasm' }),
contentType: 'application/json', contentType: 'application/json',
type: 'POST' type: 'POST'
}).fail(() => { })
.fail(() => {
this.set('manualBridgeIpNotFound', true); this.set('manualBridgeIpNotFound', true);
later(this, function () { later(
this,
function() {
this.set('manualBridgeIpNotFound', false); this.set('manualBridgeIpNotFound', false);
}, 5000); },
}).then(() => { 5000
);
})
.then(() => {
this.send('chooseBridge', manualBridgeIp); this.send('chooseBridge', manualBridgeIp);
}); });
} }
} }
}, }
}); });

View file

@ -50,7 +50,7 @@
{{/unless}} {{/unless}}
{{#if bridgeFindMultiple}} {{#if bridgeFindMultiple}}
<p>Huegasm found multiple hue bridges. <br> Please select the one you want to use for Huegasm.</p> <p>Multiple Hue bridge were found on your network. <br> Please select the one you want to use for Huegasm.</p>
<div id="bridge-button-group"> <div id="bridge-button-group">
{{#each multipleBridgeIps as |bridge|}} {{#each multipleBridgeIps as |bridge|}}

View file

@ -51,7 +51,9 @@ export default Component.extend({
// here's a weird way to automatically initialize bootstrap tooltips // here's a weird way to automatically initialize bootstrap tooltips
let observer = new MutationObserver(function(mutations) { let observer = new MutationObserver(function(mutations) {
let haveTooltip = !mutations.every(function(mutation) { let haveTooltip = !mutations.every(function(mutation) {
return isEmpty(mutation.addedNodes) || isNone(mutation.addedNodes[0].classList) || mutation.addedNodes[0].classList.contains('tooltip'); return (
isEmpty(mutation.addedNodes) || isNone(mutation.addedNodes[0].classList) || mutation.addedNodes[0].classList.contains('tooltip')
);
}); });
if (haveTooltip) { if (haveTooltip) {
@ -92,7 +94,9 @@ export default Component.extend({
if (isNone(this.get('lightsData'))) { if (isNone(this.get('lightsData'))) {
this.send('clearBridge'); this.send('clearBridge');
} else if (this.get('displayNextFailure')) { } else if (this.get('displayNextFailure')) {
this.get('notify').warning({ html: '<div class="alert alert-warning" role="alert">Error retrieving data from your lights. Yikes.</div>' }); this.get('notify').warning({
html: '<div class="alert alert-warning" role="alert">Error retrieving data from your lights. Yikes.</div>'
});
this.set('displayNextFailure', false); this.set('displayNextFailure', false);
later( later(
@ -174,7 +178,8 @@ export default Component.extend({
}, },
{ {
element: $('#playlist md-menu')[0], element: $('#playlist md-menu')[0],
intro: '<img src="/assets/images/soundcloudUrl.png" id="soundcloud-tutorial">You can add songs from SoundCloud by copy and pasting the URL shown here' intro:
'<img src="/assets/images/soundcloudUrl.png" id="soundcloud-tutorial">You can add songs from SoundCloud by copy and pasting the URL shown here'
}, },
{ {
element: '#player-area', element: '#player-area',
@ -196,7 +201,9 @@ export default Component.extend({
}, },
{ {
element: '#beat-container', element: '#beat-container',
intro: 'An interactive speaker that will bump when a beat is registered. <br><br>' + '<i><b>TIP</b>: Click on the center of the speaker to simulate a beat.</i>', intro:
'An interactive speaker that will bump when a beat is registered. <br><br>' +
'<i><b>TIP</b>: Click on the center of the speaker to simulate a beat.</i>',
position: 'top' position: 'top'
}, },
{ {

View file

@ -1,10 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Component, isEmpty, $ } = Ember;
Component,
isEmpty,
$
} = Ember;
export default Component.extend({ export default Component.extend({
bridgeIp: null, bridgeIp: null,

View file

@ -1,9 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Component, computed } = Ember;
Component,
computed
} = Ember;
export default Component.extend({ export default Component.extend({
tagName: 'footer', tagName: 'footer',

View file

@ -1,14 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { A, Component, computed, isEmpty, isNone, observer, $ } = Ember;
A,
Component,
computed,
isEmpty,
isNone,
observer,
$
} = Ember;
export default Component.extend({ export default Component.extend({
elementId: 'active-lights', elementId: 'active-lights',
@ -211,7 +203,7 @@ export default Component.extend({
} }
}, },
lightStartHover(id) { lightStartHover(id) {
if (!window.matchMedia || (window.matchMedia("(min-width: 768px)").matches)) { if (!window.matchMedia || window.matchMedia('(min-width: 768px)').matches) {
let activeLights = this.get('activeLights'), let activeLights = this.get('activeLights'),
hoveredLight = this.get('lightsList').filter(function(light) { hoveredLight = this.get('lightsList').filter(function(light) {
return light.activeClass !== 'unreachable' && light.id === id[0] && activeLights.indexOf(id) !== -1; return light.activeClass !== 'unreachable' && light.id === id[0] && activeLights.indexOf(id) !== -1;
@ -219,7 +211,7 @@ export default Component.extend({
if (!isEmpty(hoveredLight) && this.get('noHover') !== true) { if (!isEmpty(hoveredLight) && this.get('noHover') !== true) {
$.ajax(this.get('apiURL') + '/lights/' + id + '/state', { $.ajax(this.get('apiURL') + '/lights/' + id + '/state', {
data: JSON.stringify({ "alert": "lselect" }), data: JSON.stringify({ alert: 'lselect' }),
contentType: 'application/json', contentType: 'application/json',
type: 'PUT' type: 'PUT'
}); });
@ -232,14 +224,14 @@ export default Component.extend({
} }
}, },
lightStopHover(id) { lightStopHover(id) {
if (!window.matchMedia || (window.matchMedia("(min-width: 768px)").matches)) { if (!window.matchMedia || window.matchMedia('(min-width: 768px)').matches) {
let hoveredLight = this.get('lightsList').filter(function(light) { let hoveredLight = this.get('lightsList').filter(function(light) {
return light.activeClass !== 'unreachable' && light.id === id[0]; return light.activeClass !== 'unreachable' && light.id === id[0];
}); });
if (!isEmpty(hoveredLight) && this.get('noHover') !== true) { if (!isEmpty(hoveredLight) && this.get('noHover') !== true) {
$.ajax(this.get('apiURL') + '/lights/' + id + '/state', { $.ajax(this.get('apiURL') + '/lights/' + id + '/state', {
data: JSON.stringify({ "alert": "none" }), data: JSON.stringify({ alert: 'none' }),
contentType: 'application/json', contentType: 'application/json',
type: 'PUT' type: 'PUT'
}); });

View file

@ -1,9 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Component, $ } = Ember;
Component,
$
} = Ember;
export default Component.extend({ export default Component.extend({
elementId: 'color-picker', elementId: 'color-picker',

View file

@ -1,14 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Component, observer, computed, isEmpty, isNone, run: { later }, $ } = Ember;
Component,
observer,
computed,
isEmpty,
isNone,
run: { later },
$
} = Ember;
export default Component.extend({ export default Component.extend({
url: null, url: null,
@ -27,7 +19,7 @@ export default Component.extend({
}), }),
didInsertElement: function() { didInsertElement: function() {
$(document).keypress((event) => { $(document).keypress(event => {
if (!this.get('saveDisabled') && event.which === 13) { if (!this.get('saveDisabled') && event.which === 13) {
this.send('add'); this.send('add');
} }

View file

@ -17,7 +17,7 @@ export default Component.extend(helperMixin, visualizerMixin, {
title = song.title; title = song.title;
if (song.artist) { if (song.artist) {
title += (' - ' + song.artist); title += ' - ' + song.artist;
} }
} else { } else {
title = song.fileName; title = song.fileName;
@ -64,12 +64,14 @@ export default Component.extend(helperMixin, visualizerMixin, {
oldBeatPrefCache = this.get('oldBeatPrefCache'), oldBeatPrefCache = this.get('oldBeatPrefCache'),
newOldBeatPrefCache = null; newOldBeatPrefCache = null;
if (!isNone(preference)) { // load existing beat prefs if (!isNone(preference)) {
// load existing beat prefs
newOldBeatPrefCache = { threshold: this.get('threshold') }; newOldBeatPrefCache = { threshold: this.get('threshold') };
this.changePlayerControl('threshold', preference.threshold); this.changePlayerControl('threshold', preference.threshold);
this.set('usingBeatPreferences', true); this.set('usingBeatPreferences', true);
} else if (!isNone(oldBeatPrefCache)) { // revert to using beat prefs before the remembered song } else if (!isNone(oldBeatPrefCache)) {
// revert to using beat prefs before the remembered song
this.changePlayerControl('threshold', oldBeatPrefCache.threshold); this.changePlayerControl('threshold', oldBeatPrefCache.threshold);
this.set('usingBeatPreferences', false); this.set('usingBeatPreferences', false);
} }
@ -106,7 +108,12 @@ export default Component.extend(helperMixin, visualizerMixin, {
dragLeave() { dragLeave() {
// need to delay the dragLeave notification to avoid flickering (hovering over some page elements causes this event to be sent) // need to delay the dragLeave notification to avoid flickering (hovering over some page elements causes this event to be sent)
this.set('dragLeaveTimeoutHandle', setTimeout(() => { this.set('dragging', false); }, 500)); this.set(
'dragLeaveTimeoutHandle',
setTimeout(() => {
this.set('dragging', false);
}, 500)
);
}, },
simulateKick() { simulateKick() {
@ -168,20 +175,32 @@ export default Component.extend(helperMixin, visualizerMixin, {
timeToBriOff = 80; timeToBriOff = 80;
} }
later(this, () => { later(
this,
() => {
stimulateLight(light, brightnessRange[1], true); stimulateLight(light, brightnessRange[1], true);
later(this, stimulateLight, light, brightnessRange[0], false, color, timeToBriOff); later(this, stimulateLight, light, brightnessRange[0], false, color, timeToBriOff);
}, this.get('beatDelay')); },
this.get('beatDelay')
);
} }
this.set('paused', true); this.set('paused', true);
later(this, function () { later(
this,
function() {
this.set('paused', false); this.set('paused', false);
}, 200); },
200
);
//work the music beat area - simulate the speaker vibration by running a CSS animation on it //work the music beat area - simulate the speaker vibration by running a CSS animation on it
$('#beat-speaker-center-outer').velocity({ blur: 3 }, 100).velocity({ blur: 0 }, 100); $('#beat-speaker-center-outer')
$('#beat-speaker-center-inner').velocity({ scale: 1.05 }, 100).velocity({ scale: 1 }, 100); .velocity({ blur: 3 }, 100)
.velocity({ blur: 0 }, 100);
$('#beat-speaker-center-inner')
.velocity({ scale: 1.05 }, 100)
.velocity({ scale: 1 }, 100);
}, },
doAmbience(mag) { doAmbience(mag) {
@ -194,7 +213,8 @@ export default Component.extend(helperMixin, visualizerMixin, {
contentType: 'application/json', contentType: 'application/json',
type: 'PUT' type: 'PUT'
}); });
}, lightIndex = Math.floor(Math.random() * activeLights.length); },
lightIndex = Math.floor(Math.random() * activeLights.length);
// let's try not to select the same light twice in a row // let's try not to select the same light twice in a row
if (activeLights.length > 1) { if (activeLights.length > 1) {
@ -217,7 +237,7 @@ export default Component.extend(helperMixin, visualizerMixin, {
}, 1000); }, 1000);
this.pauseAmbience = true; this.pauseAmbience = true;
let pauseTime = Math.floor(1000 + (2000 / activeLights.length)); let pauseTime = Math.floor(1000 + 2000 / activeLights.length);
setTimeout(() => { setTimeout(() => {
this.pauseAmbience = false; this.pauseAmbience = false;
@ -228,9 +248,15 @@ export default Component.extend(helperMixin, visualizerMixin, {
init() { init() {
this._super(...arguments); this._super(...arguments);
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame; window.requestAnimationFrame =
window.cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.msCancelAnimationFrame; window.requestAnimationFrame ||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame;
window.cancelAnimationFrame =
window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.msCancelAnimationFrame;
navigator.getUserMedia =
navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
let dancer = new Dancer(), let dancer = new Dancer(),
storage = this.get('storage'), storage = this.get('storage'),
@ -241,7 +267,7 @@ export default Component.extend(helperMixin, visualizerMixin, {
this.simulateKick(mag, ratioKickMag); this.simulateKick(mag, ratioKickMag);
} }
}, },
offKick: (mag) => { offKick: mag => {
if (this.get('ambienceMode')) { if (this.get('ambienceMode')) {
this.doAmbience(mag); this.doAmbience(mag);
} }
@ -255,7 +281,25 @@ export default Component.extend(helperMixin, visualizerMixin, {
kick: kick kick: kick
}); });
['volume', 'shuffle', 'repeat', 'volumeMuted', 'threshold', 'ambienceMode', 'blackoutMode', 'playerBottomDisplayed', 'songBeatPreferences', 'firstVisit', 'currentVisName', 'playQueue', 'playQueuePointer', 'flashingTransitions', 'hueRange', 'brightnessRange', 'beatDelay'].forEach((item) => { [
'volume',
'shuffle',
'repeat',
'volumeMuted',
'threshold',
'ambienceMode',
'blackoutMode',
'playerBottomDisplayed',
'songBeatPreferences',
'firstVisit',
'currentVisName',
'playQueue',
'playQueuePointer',
'flashingTransitions',
'hueRange',
'brightnessRange',
'beatDelay'
].forEach(item => {
if (!isNone(storage.get('huegasm.' + item))) { if (!isNone(storage.get('huegasm.' + item))) {
let itemVal = storage.get('huegasm.' + item); let itemVal = storage.get('huegasm.' + item);
@ -286,7 +330,7 @@ export default Component.extend(helperMixin, visualizerMixin, {
this.value = null; // reset in case upload the second file again this.value = null; // reset in case upload the second file again
}); });
$(document).on('click', '.alert', (event) => { $(document).on('click', '.alert', event => {
$(event.target).addClass('removed'); $(event.target).addClass('removed');
}); });
@ -295,18 +339,18 @@ export default Component.extend(helperMixin, visualizerMixin, {
event.preventDefault(); event.preventDefault();
}); });
$(document).keypress((event) => { $(document).keypress(event => {
if (event.which === 32 && event.target.type !== 'text') { if (event.which === 32 && event.target.type !== 'text') {
this.send('play'); this.send('play');
} }
}); });
this.$().on('drop', '#play-list-area', (event) => { this.$().on('drop', '#play-list-area', event => {
this.send('dropFiles', event.dataTransfer.files); this.send('dropFiles', event.dataTransfer.files);
}); });
// control the volume by scrolling up/down // control the volume by scrolling up/down
$('#player-area').on('mousewheel', (event) => { $('#player-area').on('mousewheel', event => {
if (this.get('playQueueNotEmpty')) { if (this.get('playQueueNotEmpty')) {
let scrollSize = 5; let scrollSize = 5;
@ -368,8 +412,9 @@ export default Component.extend(helperMixin, visualizerMixin, {
}, },
handleNewSoundCloudURL(URL) { handleNewSoundCloudURL(URL) {
if (URL) { if (URL) {
SC.resolve(URL).then((resultObj) => { SC.resolve(URL).then(
let processResult = (result) => { resultObj => {
let processResult = result => {
if (result.kind === 'user') { if (result.kind === 'user') {
this.get('notify').alert({ html: this.get('scUserNotSupportedHtml') }); this.get('notify').alert({ html: this.get('scUserNotSupportedHtml') });
} else if (result.kind === 'track') { } else if (result.kind === 'track') {
@ -384,9 +429,24 @@ export default Component.extend(helperMixin, visualizerMixin, {
$.get(picture) $.get(picture)
.done(() => { .done(() => {
this.get('playQueue').pushObject({ url: result.stream_url + '?client_id=' + this.get('SC_CLIENT_ID'), fileName: result.title + ' - ' + result.user.username, artist: result.user.username, scUrl: result.permalink_url, title: result.title, picture: picture }); this.get('playQueue').pushObject({
}).fail(() => { // no picture url: result.stream_url + '?client_id=' + this.get('SC_CLIENT_ID'),
this.get('playQueue').pushObject({ url: result.stream_url + '?client_id=' + this.get('SC_CLIENT_ID'), fileName: result.title + ' - ' + result.user.username, artist: result.user.username, scUrl: result.permalink_url, title: result.title }); fileName: result.title + ' - ' + result.user.username,
artist: result.user.username,
scUrl: result.permalink_url,
title: result.title,
picture: picture
});
})
.fail(() => {
// no picture
this.get('playQueue').pushObject({
url: result.stream_url + '?client_id=' + this.get('SC_CLIENT_ID'),
fileName: result.title + ' - ' + result.user.username,
artist: result.user.username,
scUrl: result.permalink_url,
title: result.title
});
}); });
} else { } else {
failedSongs.push(result.title); failedSongs.push(result.title);
@ -418,9 +478,11 @@ export default Component.extend(helperMixin, visualizerMixin, {
this.send('next'); this.send('next');
} }
} }
}, () => { },
() => {
this.get('notify').alert({ html: this.get('urlNotFoundHtml')(URL) }); this.get('notify').alert({ html: this.get('urlNotFoundHtml')(URL) });
}); }
);
} }
this.set('isShowingAddSoundCloudModal', false); this.set('isShowingAddSoundCloudModal', false);
@ -435,7 +497,8 @@ export default Component.extend(helperMixin, visualizerMixin, {
this.changePlayerControl('playerBottomDisplayed', !this.get('playerBottomDisplayed')); this.changePlayerControl('playerBottomDisplayed', !this.get('playerBottomDisplayed'));
}, },
goToSong(index, playSong, scrollToSong) { goToSong(index, playSong, scrollToSong) {
let dancer = this.get('dancer'), playQueue = this.get('playQueue'); let dancer = this.get('dancer'),
playQueue = this.get('playQueue');
if (dancer.audio) { if (dancer.audio) {
this.clearCurrentAudio(true); this.clearCurrentAudio(true);
@ -445,12 +508,12 @@ export default Component.extend(helperMixin, visualizerMixin, {
let audio = new Audio(); let audio = new Audio();
audio.src = this.get('playQueue')[index].url; audio.src = this.get('playQueue')[index].url;
audio.crossOrigin = "anonymous"; audio.crossOrigin = 'anonymous';
audio.oncanplay = () => { audio.oncanplay = () => {
this.set('timeTotal', Math.floor(audio.duration)); this.set('timeTotal', Math.floor(audio.duration));
this.set('soundCloudFuckUps', 0); this.set('soundCloudFuckUps', 0);
}; };
audio.onerror = (event) => { audio.onerror = event => {
let playQueuePointer = this.get('playQueuePointer'), let playQueuePointer = this.get('playQueuePointer'),
song = this.get('playQueue')[playQueuePointer]; song = this.get('playQueue')[playQueuePointer];
@ -514,7 +577,9 @@ export default Component.extend(helperMixin, visualizerMixin, {
if (isEmpty($('#player-controls:hover')) && this.get('playQueuePointer') !== -1) { if (isEmpty($('#player-controls:hover')) && this.get('playQueuePointer') !== -1) {
this.send('play'); this.send('play');
$('#play-notification').velocity({ opacity: 0.8, scale: 1 }, 0).velocity({ opacity: 0, scale: 3 }, 500); $('#play-notification')
.velocity({ opacity: 0.8, scale: 1 }, 0)
.velocity({ opacity: 0, scale: 3 }, 500);
} }
}, },
play(replayPause) { play(replayPause) {
@ -528,12 +593,12 @@ export default Component.extend(helperMixin, visualizerMixin, {
dancer.pause(); dancer.pause();
let preMusicLightsDataCache = this.get('preMusicLightsDataCache'), let preMusicLightsDataCache = this.get('preMusicLightsDataCache'),
updateLight = (lightIndex) => { updateLight = lightIndex => {
$.ajax(this.get('apiURL') + '/lights/' + lightIndex + '/state', { $.ajax(this.get('apiURL') + '/lights/' + lightIndex + '/state', {
data: JSON.stringify({ data: JSON.stringify({
'on': preMusicLightsDataCache[lightIndex].state.on, on: preMusicLightsDataCache[lightIndex].state.on,
'hue': preMusicLightsDataCache[lightIndex].state.hue, hue: preMusicLightsDataCache[lightIndex].state.hue,
'bri': preMusicLightsDataCache[lightIndex].state.bri bri: preMusicLightsDataCache[lightIndex].state.bri
}), }),
contentType: 'application/json', contentType: 'application/json',
type: 'PUT' type: 'PUT'
@ -587,17 +652,19 @@ export default Component.extend(helperMixin, visualizerMixin, {
next(repeatAll) { next(repeatAll) {
let playQueuePointer = this.get('playQueuePointer'), let playQueuePointer = this.get('playQueuePointer'),
playQueue = this.get('playQueue'), playQueue = this.get('playQueue'),
nextSong = (playQueuePointer + 1), nextSong = playQueuePointer + 1,
repeat = this.get('repeat'), repeat = this.get('repeat'),
shuffle = this.get('shuffle'); shuffle = this.get('shuffle');
if (repeat === 2) { // repeating one song takes precedence over shuffling if (repeat === 2) {
// repeating one song takes precedence over shuffling
if (playQueuePointer === -1 && playQueue.length > 0) { if (playQueuePointer === -1 && playQueue.length > 0) {
nextSong = 0; nextSong = 0;
} else { } else {
nextSong = playQueuePointer; nextSong = playQueuePointer;
} }
} else if (shuffle) { // next shuffle song } else if (shuffle) {
// next shuffle song
let shufflePlayed = this.get('shufflePlayed'); let shufflePlayed = this.get('shufflePlayed');
// played all the song in shuffle mode // played all the song in shuffle mode
@ -631,19 +698,22 @@ export default Component.extend(helperMixin, visualizerMixin, {
let nextSong = this.get('playQueuePointer'), let nextSong = this.get('playQueuePointer'),
playQueue = this.get('playQueue'); playQueue = this.get('playQueue');
if (this.get('shuffle') && !isNone(playQueue[nextSong])) { // go to the previously shuffled song if (this.get('shuffle') && !isNone(playQueue[nextSong])) {
// go to the previously shuffled song
let shufflePlayed = this.get('shufflePlayed'), let shufflePlayed = this.get('shufflePlayed'),
shuffledSongIndx = this.get('shufflePlayed').indexOf(playQueue[nextSong].url), shuffledSongIndx = this.get('shufflePlayed').indexOf(playQueue[nextSong].url),
i = 0; i = 0;
if (shufflePlayed.length > 0 && shuffledSongIndx !== -1) { // only if there was one if (shufflePlayed.length > 0 && shuffledSongIndx !== -1) {
// only if there was one
nextSong = shuffledSongIndx - 1; nextSong = shuffledSongIndx - 1;
if (nextSong < 0) { if (nextSong < 0) {
nextSong = shufflePlayed.length - 1; nextSong = shufflePlayed.length - 1;
} }
playQueue.some(function (item) { // try to find the previous song id playQueue.some(function(item) {
// try to find the previous song id
if (item.url === shufflePlayed[nextSong]) { if (item.url === shufflePlayed[nextSong]) {
nextSong = i; nextSong = i;
return true; return true;
@ -729,20 +799,20 @@ export default Component.extend(helperMixin, visualizerMixin, {
let self = this, let self = this,
playQueue = this.get('playQueue'), playQueue = this.get('playQueue'),
updatePlayQueue = function() { updatePlayQueue = function() {
let tags = ID3.getAllTags("local"), let tags = ID3.getAllTags('local'),
picture = null; picture = null;
if (tags.picture) { if (tags.picture) {
let base64String = ""; let base64String = '';
for (let i = 0; i < tags.picture.data.length; i++) { for (let i = 0; i < tags.picture.data.length; i++) {
base64String += String.fromCharCode(tags.picture.data[i]); base64String += String.fromCharCode(tags.picture.data[i]);
} }
picture = "data:" + tags.picture.format + ";base64," + window.btoa(base64String); picture = 'data:' + tags.picture.format + ';base64,' + window.btoa(base64String);
} }
playQueue.pushObject({ playQueue.pushObject({
fileName: this.name.replace(/\.[^/.]+$/, ""), fileName: this.name.replace(/\.[^/.]+$/, ''),
url: URL.createObjectURL(this), url: URL.createObjectURL(this),
artist: tags.artist, artist: tags.artist,
title: tags.title, title: tags.title,
@ -762,7 +832,7 @@ export default Component.extend(helperMixin, visualizerMixin, {
let file = files[key]; let file = files[key];
if (file.type.startsWith('audio') || file.type.startsWith('video')) { if (file.type.startsWith('audio') || file.type.startsWith('video')) {
ID3.loadTags("local", updatePlayQueue.bind(file), { ID3.loadTags('local', updatePlayQueue.bind(file), {
dataReader: new FileAPIReader(file), dataReader: new FileAPIReader(file),
tags: ['title', 'artist', 'album', 'track', 'picture'] tags: ['title', 'artist', 'album', 'track', 'picture']
}); });

View file

@ -147,7 +147,9 @@ export default Mixin.create({
'<div class="alert alert-danger" role="alert">The SoundCloud API is not seving the audio properly. More details <a href="https://www.soundcloudcommunity.com/soundcloud/topics/some-soundcloud-cdn-hosted-tracks-dont-have-access-control-allow-origin-header" target="_blank" rel="noopener noreferrer">HERE</a>.</div>', '<div class="alert alert-danger" role="alert">The SoundCloud API is not seving the audio properly. More details <a href="https://www.soundcloudcommunity.com/soundcloud/topics/some-soundcloud-cdn-hosted-tracks-dont-have-access-control-allow-origin-header" target="_blank" rel="noopener noreferrer">HERE</a>.</div>',
notStreamableHtml(fileNames) { notStreamableHtml(fileNames) {
let html = let html =
'<div class="alert alert-danger" role="alert">The following file(s) could not be added because they are not allowed to be streamed:<br>' + fileNames.toString().replace(/,/g, '<br>') + '</div>'; '<div class="alert alert-danger" role="alert">The following file(s) could not be added because they are not allowed to be streamed:<br>' +
fileNames.toString().replace(/,/g, '<br>') +
'</div>';
return html; return html;
}, },
@ -319,7 +321,10 @@ export default Mixin.create({
} }
}), }),
onOptionChange: observer('flashingTransitions', 'playQueue.[]', 'playQueuePointer', 'ambienceMode', 'blackoutMode', function(self, option) { onOptionChange: observer('flashingTransitions', 'playQueue.[]', 'playQueuePointer', 'ambienceMode', 'blackoutMode', function(
self,
option
) {
option = option.replace('.[]', ''); option = option.replace('.[]', '');
let value = this.get(option); let value = this.get(option);

View file

@ -1,10 +1,6 @@
import Ember from 'ember'; import Ember from 'ember';
const { const { Mixin, observer, $ } = Ember;
Mixin,
observer,
$
} = Ember;
export default Mixin.create({ export default Mixin.create({
currentVisName: 'None', currentVisName: 'None',
@ -30,7 +26,8 @@ export default Mixin.create({
playerArea = $('#player-area'), playerArea = $('#player-area'),
ctx = canvas.getContext('2d'), ctx = canvas.getContext('2d'),
spacing = 2, spacing = 2,
h = playerArea.height(), w; h = playerArea.height(),
w;
canvas.height = h; canvas.height = h;
@ -71,7 +68,7 @@ export default Mixin.create({
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(0, h / 2); ctx.moveTo(0, h / 2);
for (let i = 0, l = waveform.length; i < l && i < count; i++) { for (let i = 0, l = waveform.length; i < l && i < count; i++) {
ctx.lineTo(i * ( spacing + width ), ( h / 2 ) + waveform[i] * ( h / 2 )); ctx.lineTo(i * (spacing + width), h / 2 + waveform[i] * (h / 2));
} }
ctx.stroke(); ctx.stroke();
ctx.closePath(); ctx.closePath();