From 1023a104f936510075017c91e092073f6d1942b7 Mon Sep 17 00:00:00 2001 From: Buster Neece Date: Mon, 26 Dec 2022 03:49:26 -0600 Subject: [PATCH] JS type fixes. --- frontend/vue/components/Public/Requests.vue | 5 - .../components/Public/WebDJ/PlaylistPanel.vue | 2 +- .../vue/components/Public/WebDJ/Stream.js | 146 +++--- frontend/vue/components/Public/WebDJ/Track.js | 428 +++++++++--------- .../components/Stations/Reports/Listeners.vue | 2 +- .../colorschemes.tableau.js | 166 +++---- 6 files changed, 374 insertions(+), 375 deletions(-) diff --git a/frontend/vue/components/Public/Requests.vue b/frontend/vue/components/Public/Requests.vue index da30c2bdc..eec4c32b8 100644 --- a/frontend/vue/components/Public/Requests.vue +++ b/frontend/vue/components/Public/Requests.vue @@ -109,11 +109,6 @@ export default { ] }; }, - computed: { - langAlbumArt () { - return this.$gettext('Album Art'); - } - }, methods: { doSubmitRequest (url) { this.axios.post(url).then((resp) => { diff --git a/frontend/vue/components/Public/WebDJ/PlaylistPanel.vue b/frontend/vue/components/Public/WebDJ/PlaylistPanel.vue index ae17c8af5..c0fa902d5 100644 --- a/frontend/vue/components/Public/WebDJ/PlaylistPanel.vue +++ b/frontend/vue/components/Public/WebDJ/PlaylistPanel.vue @@ -87,7 +87,7 @@
{{ diff --git a/frontend/vue/components/Public/WebDJ/Stream.js b/frontend/vue/components/Public/WebDJ/Stream.js index 1605ff18d..b14097baa 100644 --- a/frontend/vue/components/Public/WebDJ/Stream.js +++ b/frontend/vue/components/Public/WebDJ/Stream.js @@ -1,103 +1,105 @@ +// noinspection all + var stream = {}; var defaultChannels = 2; // Function to be called upon the first user interaction. stream.init = function () { - // Define the streaming radio context. - if (!this.context) { - if (typeof webkitAudioContext !== 'undefined') { - this.context = new webkitAudioContext; - } else { - this.context = new AudioContext; - } + // Define the streaming radio context. + if (!this.context) { + if (typeof webkitAudioContext !== 'undefined') { + this.context = new webkitAudioContext; + } else { + this.context = new AudioContext; + } - this.webcast = this.context.createWebcastSource(4096, defaultChannels); - this.webcast.connect(this.context.destination); - } + this.webcast = this.context.createWebcastSource(4096, defaultChannels); + this.webcast.connect(this.context.destination); + } }; stream.resumeContext = function () { - if (this.context.state !== 'running') { - this.context.resume(); - } + if (this.context.state !== 'running') { + this.context.resume(); + } }; stream.createAudioSource = function ({ - file, - audio + file, + audio }, model, cb) { - var el, - source; + var el, + source; - el = new Audio(URL.createObjectURL(file)); - el.controls = false; - el.autoplay = false; - el.loop = false; + el = new Audio(URL.createObjectURL(file)); + el.controls = false; + el.autoplay = false; + el.loop = false; - el.addEventListener('ended', function () { - return model.onEnd(); - }); + el.addEventListener('ended', function () { + return model.onEnd(); + }); - source = null; - return el.addEventListener('canplay', function () { - if (source != null) { - return; - } + source = null; + return el.addEventListener('canplay', function () { + if (source != null) { + return; + } - source = stream.context.createMediaElementSource(el); - source.play = function () { - return el.play(); - }; - source.position = function () { - return el.currentTime; - }; - source.duration = function () { - return el.duration; - }; - source.paused = function () { - return el.paused; - }; - source.stop = function () { - el.pause(); - return el.remove(); - }; - source.pause = function () { - return el.pause(); - }; - source.seek = function (percent) { - var time; - time = percent * parseFloat(audio.length); - el.currentTime = time; - return time; - }; + source = stream.context.createMediaElementSource(el); + source.play = function () { + return el.play(); + }; + source.position = function () { + return el.currentTime; + }; + source.duration = function () { + return el.duration; + }; + source.paused = function () { + return el.paused; + }; + source.stop = function () { + el.pause(); + return el.remove(); + }; + source.pause = function () { + return el.pause(); + }; + source.seek = function (percent) { + var time; + time = percent * parseFloat(audio.length); + el.currentTime = time; + return time; + }; - return cb(source); - }); + return cb(source); + }); }; stream.createFileSource = function (file, model, cb) { - var ref; - if ((ref = this.source) != null) { - ref.disconnect(); - } - return this.createAudioSource(file, model, cb); + var ref; + if ((ref = this.source) != null) { + ref.disconnect(); + } + return this.createAudioSource(file, model, cb); }; stream.createMicrophoneSource = function (constraints, cb) { - return navigator.mediaDevices.getUserMedia(constraints).then(function (bit_stream) { - var source; + return navigator.mediaDevices.getUserMedia(constraints).then(function (bit_stream) { + var source; - source = stream.context.createMediaStreamSource(bit_stream); - source.stop = function () { - var ref; - return (ref = bit_stream.getAudioTracks()) != null ? ref[0].stop() : void 0; - }; - return cb(source); - }); + source = stream.context.createMediaStreamSource(bit_stream); + source.stop = function () { + var ref; + return (ref = bit_stream.getAudioTracks()) != null ? ref[0].stop() : void 0; + }; + return cb(source); + }); }; stream.close = function (cb) { - return this.webcast.close(cb); + return this.webcast.close(cb); }; export default stream; diff --git a/frontend/vue/components/Public/WebDJ/Track.js b/frontend/vue/components/Public/WebDJ/Track.js index 99510c5ae..b78c8b7bf 100644 --- a/frontend/vue/components/Public/WebDJ/Track.js +++ b/frontend/vue/components/Public/WebDJ/Track.js @@ -1,220 +1,222 @@ +// noinspection all + export default { - inject: ['getStream', 'resumeStream'], - data: function () { - return { - 'controlsNode': null, + inject: ['getStream', 'resumeStream'], + data: function () { + return { + 'controlsNode': null, - 'trackGain': 0, - 'trackGainObj': null, + 'trackGain': 0, + 'trackGainObj': null, - 'destination': null, - 'sink': null, + 'destination': null, + 'sink': null, - 'passThrough': false, - 'passThroughObj': null, + 'passThrough': false, + 'passThroughObj': null, - 'source': null, - 'playing': false, - 'paused': false, - 'position': 0.0, - 'volume': 100, - 'volumeLeft': 0, - 'volumeRight': 0 - }; - }, - mounted: function () { - this.sink = this.getStream().webcast; - }, - watch: { - volume: function (val, oldVal) { - this.setTrackGain(val); + 'source': null, + 'playing': false, + 'paused': false, + 'position': 0.0, + 'volume': 100, + 'volumeLeft': 0, + 'volumeRight': 0 + }; + }, + mounted: function () { + this.sink = this.getStream().webcast; + }, + watch: { + volume: function (val, oldVal) { + this.setTrackGain(val); + } + }, + methods: { + createControlsNode: function () { + var bufferLength, + bufferLog, + bufferSize, + log10, + source; + + bufferSize = 4096; + bufferLength = parseFloat(bufferSize) / parseFloat(this.getStream().context.sampleRate); + bufferLog = Math.log(parseFloat(bufferSize)); + log10 = 2.0 * Math.log(10); + + source = this.getStream().context.createScriptProcessor(bufferSize, 2, 2); + + source.onaudioprocess = (buf) => { + var channel, + channelData, + i, + j, + k, + ref1, + ref2, + ref3, + results, + ret, + rms, + volume; + ret = {}; + + if (((ref1 = this.source) != null ? ref1.position : void 0) != null) { + this.position = this.source.position(); + } else { + if (this.source != null) { + this.position = parseFloat(this.position) + bufferLength; + } + } + results = []; + for (channel = j = 0, ref2 = buf.inputBuffer.numberOfChannels - 1; (0 <= ref2 ? j <= ref2 : j >= ref2); channel = 0 <= ref2 ? ++j : --j) { + channelData = buf.inputBuffer.getChannelData(channel); + rms = 0.0; + for (i = k = 0, ref3 = channelData.length - 1; (0 <= ref3 ? k <= ref3 : k >= ref3); i = 0 <= ref3 ? ++k : --k) { + rms += Math.pow(channelData[i], 2); + } + volume = 100 * Math.exp((Math.log(rms) - bufferLog) / log10); + if (channel === 0) { + this.volumeLeft = volume; + } else { + this.volumeRight = volume; + } + + results.push(buf.outputBuffer.getChannelData(channel).set(channelData)); + } + return results; + }; + return source; + }, + + createPassThrough: function () { + var source; + source = this.getStream().context.createScriptProcessor(256, 2, 2); + source.onaudioprocess = (buf) => { + var channel, + channelData, + j, + ref1, + results; + channelData = buf.inputBuffer.getChannelData(channel); + results = []; + for (channel = j = 0, ref1 = buf.inputBuffer.numberOfChannels - 1; (0 <= ref1 ? j <= ref1 : j >= ref1); channel = 0 <= ref1 ? ++j : --j) { + if (this.passThrough) { + results.push(buf.outputBuffer.getChannelData(channel).set(channelData)); + } else { + results.push(buf.outputBuffer.getChannelData(channel).set(new Float32Array(channelData.length))); + } + } + return results; + }; + return source; + }, + + setTrackGain: function (new_gain) { + return (this.trackGainObj) && (this.trackGainObj.gain.value = parseFloat(new_gain) / 100.0); + }, + + togglePause: function () { + var ref1, + ref2; + if (((ref1 = this.source) != null ? ref1.pause : void 0) == null) { + return; + } + if ((ref2 = this.source) != null ? typeof ref2.paused === 'function' ? ref2.paused() : void 0 : void 0) { + this.source.play(); + this.playing = true; + this.paused = false; + } else { + this.source.pause(); + this.playing = false; + this.paused = true; + } + }, + + prepare: function () { + this.controlsNode = this.createControlsNode(); + this.controlsNode.connect(this.sink); + + this.trackGainObj = this.getStream().context.createGain(); + this.trackGainObj.connect(this.controlsNode); + this.trackGainObj.gain.value = 1.0; + + this.destination = this.trackGainObj; + + this.passThroughObj = this.createPassThrough(); + this.passThroughObj.connect(this.getStream().context.destination); + + return this.trackGainObj.connect(this.passThroughObj); + }, + + stop: function () { + var ref1, + ref2, + ref3, + ref4, + ref5; + if ((ref1 = this.source) != null) { + if (typeof ref1.stop === 'function') { + ref1.stop(); + } + } + if ((ref2 = this.source) != null) { + ref2.disconnect(); + } + if ((ref3 = this.trackGainObj) != null) { + ref3.disconnect(); + } + if ((ref4 = this.controlsNode) != null) { + ref4.disconnect(); + } + if ((ref5 = this.passThroughObj) != null) { + ref5.disconnect(); + } + this.source = this.trackGainObj = this.controlsNode = this.passThroughObj = null; + + this.position = 0.0; + this.volumeLeft = 0; + this.volumeRight = 0; + + this.playing = false; + this.paused = false; + }, + + seek: function (percent) { + var position, + ref1; + if (!(position = (ref1 = this.source) != null ? typeof ref1.seek === 'function' ? ref1.seek(percent) : void 0 : void 0)) { + return; + } + + this.position = position; + }, + + prettifyTime: function (time) { + var hours, + minutes, + result, + seconds; + hours = parseInt(time / 3600); + time %= 3600; + minutes = parseInt(time / 60); + seconds = parseInt(time % 60); + if (minutes < 10) { + minutes = `0${minutes}`; + } + if (seconds < 10) { + seconds = `0${seconds}`; + } + result = `${minutes}:${seconds}`; + if (hours > 0) { + result = `${hours}:${result}`; + } + return result; + }, + + sendMetadata: function (file) { + this.getStream().webcast.sendMetadata(file.metadata); + } } - }, - methods: { - createControlsNode: function () { - var bufferLength, - bufferLog, - bufferSize, - log10, - source; - - bufferSize = 4096; - bufferLength = parseFloat(bufferSize) / parseFloat(this.getStream().context.sampleRate); - bufferLog = Math.log(parseFloat(bufferSize)); - log10 = 2.0 * Math.log(10); - - source = this.getStream().context.createScriptProcessor(bufferSize, 2, 2); - - source.onaudioprocess = (buf) => { - var channel, - channelData, - i, - j, - k, - ref1, - ref2, - ref3, - results, - ret, - rms, - volume; - ret = {}; - - if (((ref1 = this.source) != null ? ref1.position : void 0) != null) { - this.position = this.source.position(); - } else { - if (this.source != null) { - this.position = parseFloat(this.position) + bufferLength; - } - } - results = []; - for (channel = j = 0, ref2 = buf.inputBuffer.numberOfChannels - 1; (0 <= ref2 ? j <= ref2 : j >= ref2); channel = 0 <= ref2 ? ++j : --j) { - channelData = buf.inputBuffer.getChannelData(channel); - rms = 0.0; - for (i = k = 0, ref3 = channelData.length - 1; (0 <= ref3 ? k <= ref3 : k >= ref3); i = 0 <= ref3 ? ++k : --k) { - rms += Math.pow(channelData[i], 2); - } - volume = 100 * Math.exp((Math.log(rms) - bufferLog) / log10); - if (channel === 0) { - this.volumeLeft = volume; - } else { - this.volumeRight = volume; - } - - results.push(buf.outputBuffer.getChannelData(channel).set(channelData)); - } - return results; - }; - return source; - }, - - createPassThrough: function () { - var source; - source = this.getStream().context.createScriptProcessor(256, 2, 2); - source.onaudioprocess = (buf) => { - var channel, - channelData, - j, - ref1, - results; - channelData = buf.inputBuffer.getChannelData(channel); - results = []; - for (channel = j = 0, ref1 = buf.inputBuffer.numberOfChannels - 1; (0 <= ref1 ? j <= ref1 : j >= ref1); channel = 0 <= ref1 ? ++j : --j) { - if (this.passThrough) { - results.push(buf.outputBuffer.getChannelData(channel).set(channelData)); - } else { - results.push(buf.outputBuffer.getChannelData(channel).set(new Float32Array(channelData.length))); - } - } - return results; - }; - return source; - }, - - setTrackGain: function (new_gain) { - return (this.trackGainObj) && (this.trackGainObj.gain.value = parseFloat(new_gain) / 100.0); - }, - - togglePause: function () { - var ref1, - ref2; - if (((ref1 = this.source) != null ? ref1.pause : void 0) == null) { - return; - } - if ((ref2 = this.source) != null ? typeof ref2.paused === 'function' ? ref2.paused() : void 0 : void 0) { - this.source.play(); - this.playing = true; - this.paused = false; - } else { - this.source.pause(); - this.playing = false; - this.paused = true; - } - }, - - prepare: function () { - this.controlsNode = this.createControlsNode(); - this.controlsNode.connect(this.sink); - - this.trackGainObj = this.getStream().context.createGain(); - this.trackGainObj.connect(this.controlsNode); - this.trackGainObj.gain.value = 1.0; - - this.destination = this.trackGainObj; - - this.passThroughObj = this.createPassThrough(); - this.passThroughObj.connect(this.getStream().context.destination); - - return this.trackGainObj.connect(this.passThroughObj); - }, - - stop: function () { - var ref1, - ref2, - ref3, - ref4, - ref5; - if ((ref1 = this.source) != null) { - if (typeof ref1.stop === 'function') { - ref1.stop(); - } - } - if ((ref2 = this.source) != null) { - ref2.disconnect(); - } - if ((ref3 = this.trackGainObj) != null) { - ref3.disconnect(); - } - if ((ref4 = this.controlsNode) != null) { - ref4.disconnect(); - } - if ((ref5 = this.passThroughObj) != null) { - ref5.disconnect(); - } - this.source = this.trackGainObj = this.controlsNode = this.passThroughObj = null; - - this.position = 0.0; - this.volumeLeft = 0; - this.volumeRight = 0; - - this.playing = false; - this.paused = false; - }, - - seek: function (percent) { - var position, - ref1; - if (!(position = (ref1 = this.source) != null ? typeof ref1.seek === 'function' ? ref1.seek(percent) : void 0 : void 0)) { - return; - } - - this.position = position; - }, - - prettifyTime: function (time) { - var hours, - minutes, - result, - seconds; - hours = parseInt(time / 3600); - time %= 3600; - minutes = parseInt(time / 60); - seconds = parseInt(time % 60); - if (minutes < 10) { - minutes = `0${minutes}`; - } - if (seconds < 10) { - seconds = `0${seconds}`; - } - result = `${minutes}:${seconds}`; - if (hours > 0) { - result = `${hours}:${result}`; - } - return result; - }, - - sendMetadata: function (file) { - this.getStream().webcast.sendMetadata(file.metadata); - } - } }; diff --git a/frontend/vue/components/Stations/Reports/Listeners.vue b/frontend/vue/components/Stations/Reports/Listeners.vue index 8e6025745..c4468b203 100644 --- a/frontend/vue/components/Stations/Reports/Listeners.vue +++ b/frontend/vue/components/Stations/Reports/Listeners.vue @@ -88,7 +88,7 @@