Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
tray.startCastingVisibility = false;
tray.setStatusMessage('Starting internal things...');
let Client = browser.createClient(name);
let contentType;
let audioConfig;
if(quality === 'flac') {
audioConfig = { deviceName: audioDevice, bps: 16, samplerate: 44100 };
enc = new flac.StreamEncoder();
contentType = 'audio/flac';
logger.info('Using FLAC encoder');
} else if(quality === 'flac-hd') {
audioConfig = { deviceName: audioDevice, bps: 24, samplerate: 96000 };
enc = new flac.StreamEncoder({ bitsPerSample: 24, samplerate: 96000 });
contentType = 'audio/flac';
logger.info('Using FLAC encoder with 96KHz and 24bit');
} else if(quality === 'wav') {
audioConfig = { deviceName: audioDevice, bps: 16, samplerate: 44100 };
enc = new wav.Writer();
contentType = 'audio/wav';
logger.info('Using WAV container, no encoding done');
} else if(quality === 'wav-hd') {
audioConfig = { deviceName: audioDevice, bps: 24, samplerate: 96000 };
enc = new wav.Writer({ sampleRate: 96000, bitDepth: 24 });
contentType = 'audio/wav';
logger.info('Using WAV container, no encoding done');
} else {
audioConfig = { deviceName: audioDevice, bps: 16, samplerate: 44100 };
contentType = 'audio/mpeg';
logger.info('Using lame encoder');
module.exports.Player = function () {
function writeSamples(leftSamples, rightSamples) {
let out = new Int16Array(leftSamples.length * 2);
for (var i = 0; i < leftSamples.length; ++i) {
out[i * 2] =
Math.floor(Math.max(-1, Math.min(1, leftSamples[i])) * 32767);
out[i * 2 + 1] =
Math.floor(Math.max(-1, Math.min(1, rightSamples[i])) * 32767);
}
return Buffer.from(out.buffer);
}
let writer = new flac.StreamEncoder({ samplerate: 48000, bitsPerSample: 16, compressionLevel: 0 });
let fileWriter;
let audioElement;
let recording = false;
let muted = false;
let server = httpServer.Server(1337, writer);
const pause = () => {
server.stop();
if (userSettings.get('localPlayer') && audioElement) {
audioElement.pause();
}
};
const start = () => {
server.start();
}
if(app.isPackaged) {
logger.info('Starting updater...');
require('./updater.js');
template.splice(template.length - 2, 1);
} else {
logger.info('Opening dev tools...');
mainWindow.webContents.openDevTools();
}
menu = electron.Menu.buildFromTemplate(template);
electron.Menu.setApplicationMenu(menu);
tray = new CATray(mainWindow, tt);
const path = require('path');
if('function' === typeof flac.bindings.load) {
logger.info('Loading libFLAC from resources');
if(process.platform === 'darwin') {
flac.bindings.load(__dirname + '/../lib/mac/libFLAC.dylib');
} else if(process.platform === 'linux') {
flac.bindings.load(__dirname + '/../lib/linux/libFLAC.so');
} else if(process.platform === 'windows' || process.platform === 'win32') {
flac.bindings.load(path.dirname(__dirname) + '\\lib\\win\\libFLAC');
}
}
if(!c.AudioInput.isNativeLibraryLoaded()) {
logger.info('Loading libportaudio from resources');
if(process.platform === 'darwin') {
c.AudioInput.loadNativeLibrary(__dirname + '/../lib/mac/libportaudio.dylib');
} else if(process.platform === 'linux') {
c.AudioInput.loadNativeLibrary(__dirname + '/../lib/linux/libportaudio.so');
mainWindow.webContents.openDevTools();
}
menu = electron.Menu.buildFromTemplate(template);
electron.Menu.setApplicationMenu(menu);
tray = new CATray(mainWindow, tt);
const path = require('path');
if('function' === typeof flac.bindings.load) {
logger.info('Loading libFLAC from resources');
if(process.platform === 'darwin') {
flac.bindings.load(__dirname + '/../lib/mac/libFLAC.dylib');
} else if(process.platform === 'linux') {
flac.bindings.load(__dirname + '/../lib/linux/libFLAC.so');
} else if(process.platform === 'windows' || process.platform === 'win32') {
flac.bindings.load(path.dirname(__dirname) + '\\lib\\win\\libFLAC');
}
}
if(!c.AudioInput.isNativeLibraryLoaded()) {
logger.info('Loading libportaudio from resources');
if(process.platform === 'darwin') {
c.AudioInput.loadNativeLibrary(__dirname + '/../lib/mac/libportaudio.dylib');
} else if(process.platform === 'linux') {
c.AudioInput.loadNativeLibrary(__dirname + '/../lib/linux/libportaudio.so');
} else if(process.platform === 'windows' || process.platform === 'win32') {
c.AudioInput.loadNativeLibrary(path.dirname(__dirname)+'\\lib\\win\\portaudio_x64');
}
}
electron.ipcMain.once('windowLoaded', () => {
config.get('showWindow').then(value => value && mainWindow.show());
const record = () => {
let recordingsPath = userSettings.get('recordingsPath');
if (!recording) {
let freqText = require('../fmRadio.js').getFreqText();
fileWriter = new flac.FileEncoder({
samplerate: 48000, bitsPerSample: 16, compressionLevel: 6, file: path.join(recordingsPath, freqText.replace(' ', '') + '_' + getDateStr() + '_recording.flac')
});
recording = true;
} else {
stopRecording();
}
};