From 582046510cc6d2ea94cbe4f1b58ec1876c1725b5 Mon Sep 17 00:00:00 2001 From: cesine Date: Fri, 19 Dec 2014 22:29:45 +0530 Subject: [PATCH] jshint --- js/recordmp3.js | 92 ++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/js/recordmp3.js b/js/recordmp3.js index 8b5ae95..4340a0a 100644 --- a/js/recordmp3.js +++ b/js/recordmp3.js @@ -1,4 +1,4 @@ -(function(window){ +(function(global){ var WORKER_PATH = 'js/recorderWorker.js'; var encoderWorker = new Worker('js/mp3Worker.js'); @@ -6,7 +6,7 @@ var __log = function(e, data) { log.innerHTML += "\n" + e + " " + (data || ''); - } + }; var Recorder = function(cfg){ var config = cfg || {}; @@ -65,7 +65,7 @@ var average = values / length; self.vumeter.style.width = Math.min(parseInt(average*2),100)+'%'; - } + }; this.configure = function(cfg){ for (var prop in cfg){ @@ -73,7 +73,7 @@ config[prop] = cfg[prop]; } } - } + }; this.toggleRecording = function() { if (recording) { @@ -85,11 +85,11 @@ config.element.className += ' recording'; self.audio = null; __log('Recording...'); - } + }; this.record = function(){ recording = true; - } + }; this.stop = function() { if (self.playing) { @@ -111,11 +111,11 @@ btnStop.disabled = true; btnRecord.disabled = false; btnSave.disabled = false; - } + }; this.stopRecording = function(){ recording = false; - } + }; this.play = function() { if (self.playing) { @@ -142,7 +142,7 @@ btnPlay.innerHTML = ''; } } - } + }; this.save = function(){ btnPlay.disabled = true; @@ -154,21 +154,21 @@ self.convertToMP3(); } else { // Assume WAV. - window[self.callback](self, self.audioData); + global[self.callback](self, self.audioData); } - } + }; this.clear = function(){ worker.postMessage({ command: 'clear' }); initButtons(); removeClass(config.element, 'recording'); removeClass(config.element, 'processing'); - } + }; this.getBuffer = function(cb) { currCallback = cb || config.callback; - worker.postMessage({ command: 'getBuffer' }) - } + worker.postMessage({ command: 'getBuffer' }); + }; this.exportWAV = function(type){ type = type || config.type || 'audio/wav'; @@ -176,13 +176,13 @@ command: 'exportWAV', type: type }); - } + }; worker.onmessage = function(e){ var blob = e.data; self.audioData = blob; btnPlay.disabled = false; - } + }; this.convertToMP3 = function() { var arrayBuffer; @@ -210,17 +210,17 @@ __log("Done converting to Mp3"); var mp3Blob = new Blob([new Uint8Array(e.data.buf)], {type: 'audio/mp3'}); - window[self.callback](self, mp3Blob); + global[self.callback](self, mp3Blob); } }; }; fileReader.readAsArrayBuffer(this.audioData); - } + }; - function encode64(buffer) { + var encode64 = function(buffer) { var binary = '', bytes = new Uint8Array( buffer ), len = bytes.byteLength; @@ -228,11 +228,11 @@ for (var i = 0; i < len; i++) { binary += String.fromCharCode( bytes[ i ] ); } - return window.btoa( binary ); - } + return global.btoa( binary ); + }; - function parseWav(wav) { - function readInt(i, bytes) { + var parseWav = function(wav) { + var readInt= function(i, bytes) { var ret = 0, shft = 0; @@ -243,7 +243,7 @@ bytes--; } return ret; - } + }; if (readInt(20, 2) != 1) throw 'Invalid compression code, not PCM'; if (readInt(22, 2) != 1) throw 'Invalid number of channels, not 1'; return { @@ -251,9 +251,9 @@ bitsPerSample: readInt(34, 2), samples: wav.subarray(44) }; - } + }; - function Uint8ArrayToFloat32Array(u8a){ + var Uint8ArrayToFloat32Array= function(u8a){ var f32Buffer = new Float32Array(u8a.length); for (var i = 0; i < u8a.length; i++) { var value = u8a[i<<1] + (u8a[(i<<1)+1]<<8); @@ -261,13 +261,13 @@ f32Buffer[i] = value / 0x8000; } return f32Buffer; - } + }; - function removeClass(el, name) { + var removeClass= function(el, name) { el.className = el.className.replace(' '+name, ''); - } + }; - function buildInterface() { + var buildInterface = function() { __log('Building interface...'); initButtons(); config.element.appendChild(btnPlay); @@ -276,10 +276,10 @@ config.element.appendChild(btnSave); self.vumeter = config.element.querySelector('.btn-record .vumeter'); __log('Interface built.'); - } - function initButtons() { + }; + var initButtons =function() { btnRecord.onclick = self.toggleRecording; - btnRecord.className = 'btn-record' + btnRecord.className = 'btn-record'; btnRecord.innerHTML = ''; btnRecord.disabled = false; btnStop.onclick = self.stop; @@ -294,7 +294,7 @@ btnSave.className = 'btn-save'; btnSave.innerHTML = ''; btnSave.disabled = true; - } + }; source.connect(this.analyser); this.analyser.connect(this.node); @@ -303,22 +303,22 @@ buildInterface(); return this; - __log('Recorder initialised.'); + // __log('Recorder initialised.'); }; - window.Recorder = Recorder; + global.Recorder = Recorder; var initRecorder = function() { try { // webkit shim - window.AudioContext = window.AudioContext || window.webkitAudioContext; + global.AudioContext = global.AudioContext || global.webkitAudioContext; navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); - window.URL = window.URL || window.webkitURL; + global.URL = global.URL || global.webkitURL; - audio_context = new AudioContext; + audio_context = new AudioContext(); __log('Audio context set up.'); __log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!')); } catch (e) { @@ -328,7 +328,7 @@ navigator.getUserMedia({audio: true}, startUserMedia, function(e) { __log('No live audio input: ' + e); }); - } + }; var startUserMedia = function(stream) { var recorders = document.querySelectorAll('.RecordMP3js-recorder'); @@ -339,12 +339,12 @@ for(var i=0; i