Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 57 58 59 60 61 62 63 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x | import {io} from 'socket.io-client';
/**
*
*/
class PythonServerInterface {
static PYTHON_SERVER_URL = 'https://easyeyes-python-server.herokuapp.com';
/**
*
* @param {string} url
*/
constructor(url = PythonServerInterface.PYTHON_SERVER_URL) {
// 'http://localhost:3001/'
this.socket = io(url, {
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: 99999,
});
}
getImpulseResponse = async data => {
this.asyncEmit('data', {
task: 'impulse-response',
data,
});
};
getVolumeCalibration = async data => {
let serverRep;
let res;
try {
serverRep = await this.asyncEmit('data', {
task: 'volume-calibration',
data,
});
const [soundGainDbSPL, P, L, vectorDb] = serverRep.data
.trim()
.split(',')
.map(resp => parseFloat(resp.split(':')[1]));
res = soundGainDbSPL;
} catch (e) {
throw new Error(e);
}
return res;
};
asyncEmit = (eventName, data) =>
new Promise((resolve, reject) => {
this.socket.emit(eventName, data);
this.socket.on(eventName, result => {
resolve(result);
});
this.socket.on('error', error => {
reject(error);
});
setTimeout(reject, 20000);
});
}
export default PythonServerInterface;
|