speaker-calibration 2.2.215 → 2.2.216
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/example/i18n.js +1515 -1512
- package/dist/listener.js +2 -2
- package/dist/main.js +2 -2
- package/package.json +1 -1
- package/src/peer-connection/listener.js +9 -6
- package/src/peer-connection/speaker.js +104 -83
package/dist/listener.js
CHANGED
|
@@ -136,7 +136,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core
|
|
|
136
136
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
137
137
|
|
|
138
138
|
"use strict";
|
|
139
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\n\n\n\n\n/**\r\n * @class Handles the listener's side of the connection. Responsible for getting access to user's microphone,\r\n * and initiating a call to the Speaker.\r\n * @augments AudioPeer\r\n */\nclass Listener extends _audioPeer__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n /**\r\n * Takes a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @example\r\n */\n constructor(params) {\n super(params);\n _defineProperty(this, \"onPeerOpen\", id => {\n this.displayUpdate('Listener - onPeerOpen');\n // Workaround for peer.reconnect deleting previous id\n\n if (id === null) {\n this.displayUpdate('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n this.join();\n });\n _defineProperty(this, \"onPeerConnection\", connection => {\n this.displayUpdate('Listener - onPeerConnection');\n // Disallow incoming connections\n connection.on('open', () => {\n connection.send('Sender does not accept incoming connections');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n });\n _defineProperty(this, \"onConnData\", data => {\n this.displayUpdate('Listener - onConnData');\n const hasSpeakerID = Object.prototype.hasOwnProperty.call(data, 'speakerPeerId');\n if (!hasSpeakerID) {\n this.displayUpdate('Error in parsing data received! Must set \"speakerPeerId\" property');\n throw new _peerErrors__WEBPACK_IMPORTED_MODULE_1__.MissingSpeakerIdError('Must set \"speakerPeerId\" property');\n } else {\n // this.conn.close();\n this.displayUpdate(this.speakerPeerId);\n this.speakerPeerId = data.speakerPeerId;\n const newParams = {\n speakerPeerId: this.speakerPeerId\n };\n /*\r\n FUTURE does this limit usable environments?\r\n ie does this work if internet is lost after initial page load?\r\n */\n window.location.search = this.queryStringFromObject(newParams); // Redirect to correctly constructed keypad page\n }\n });\n _defineProperty(this, \"join\", async () => {\n this.displayUpdate('Listener - join');\n /**\r\n * Create the connection between the two Peers.\r\n *\r\n * Sets up callbacks that handle any events related to the\r\n * connection and data received on it.\r\n */\n // Close old connection\n if (this.conn) {\n this.displayUpdate('Closing old connection');\n this.conn.close();\n }\n\n // Create connection to destination peer specified by the query param\n this.displayUpdate(\"Creating connection to: \".concat(this.speakerPeerId));\n this.conn = this.peer.connect(this.speakerPeerId, {\n reliable: true\n });\n this.displayUpdate('Created connection');\n this.conn.on('open', async () => {\n this.displayUpdate('Listener - conn open');\n await this.getDeviceInfo();\n // this.sendSamplingRate();\n await this.openAudioStream();\n });\n\n // Handle incoming data (messages only since this is the signal sender)\n this.conn.on('data', this.onConnData);\n this.conn.on('close', () => {\n console.log('Connection closed');\n });\n });\n _defineProperty(this, \"getMobileOS\", () => {\n var _navigator, _navigator2;\n const ua = navigator.userAgent;\n if (/android/i.test(ua)) {\n return 'Android';\n }\n if (/iPad|iPhone|iPod/.test(ua) || (((_navigator = navigator) === null || _navigator === void 0 || (_navigator = _navigator.userAgentData) === null || _navigator === void 0 ? void 0 : _navigator.platform) || ((_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.platform)) === 'MacIntel' && navigator.maxTouchPoints > 1) {\n return 'iOS';\n }\n return 'Other';\n });\n _defineProperty(this, \"sendSamplingRate\", sampleRate => {\n this.displayUpdate('Listener - sendSamplingRate');\n this.conn.send({\n name: 'samplingRate',\n payload: sampleRate\n });\n });\n _defineProperty(this, \"sendSampleSize\", sampleSize => {\n this.displayUpdate('Listener - sendSampleSize');\n this.conn.send({\n name: 'sampleSize',\n payload: sampleSize\n });\n });\n _defineProperty(this, \"sendFlags\", flags => {\n this.displayUpdate('Listener - sendFlags');\n this.conn.send({\n name: 'flags',\n payload: flags\n });\n });\n _defineProperty(this, \"getDeviceInfo\", async () => {\n const deviceInfo = {};\n try {\n fod.complete(function (data) {\n deviceInfo['IsMobile'] = data.device['ismobile'];\n deviceInfo['HardwareName'] = data.device['hardwarename'];\n deviceInfo['HardwareFamily'] = data.device['hardwarefamily'];\n deviceInfo['HardwareModel'] = data.device['hardwaremodel'];\n deviceInfo['OEM'] = data.device['oem'];\n deviceInfo['HardwareModelVariants'] = data.device['hardwaremodelvariants'];\n deviceInfo['DeviceId'] = data.device['deviceid'];\n deviceInfo['PlatformName'] = data.device['platformname'];\n deviceInfo['PlatformVersion'] = data.device['platformversion'];\n deviceInfo['DeviceType'] = data.device['devicetype'];\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n });\n } catch (error) {\n console.error('Error fetching or executing script:', error.message);\n }\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n deviceInfo['microphoneFromAPI'] = this.microphoneFromAPI;\n deviceInfo['microphoneDeviceId'] = this.microphoneDeviceId;\n deviceInfo['screenWidth'] = window.screen.width;\n deviceInfo['screenHeight'] = window.screen.height;\n console.log('deviceInfo Inside getDeviceInfo: ', deviceInfo);\n this.conn.send({\n name: 'deviceInfo',\n payload: deviceInfo\n });\n return deviceInfo;\n });\n _defineProperty(this, \"applyHQTrackConstraints\", async stream => {\n // Contraint the incoming audio to the sampling rate we want\n stream.getAudioTracks().forEach(track => {\n console.log(track, track.enabled);\n });\n const track = stream.getAudioTracks()[0];\n console.log(track);\n const capabilities = track.getCapabilities();\n this.displayUpdate(\"Listener Track Capabilities - \".concat(JSON.stringify(capabilities, undefined, 2)));\n const constraints = track.getConstraints();\n if (capabilities.echoCancellation) {\n constraints.echoCancellation = false;\n }\n if (capabilities.sampleRate) {\n constraints.sampleRate = this.calibrateSoundHz;\n }\n if (capabilities.sampleSize) {\n constraints.sampleSize = this.calibrateSoundSamplingDesiredBits;\n }\n if (capabilities.channelCount) {\n constraints.channelCount = 1;\n }\n this.displayUpdate(\"Listener Track Constraints - \".concat(JSON.stringify(constraints, undefined, 2)));\n\n // await the promise\n try {\n await track.applyConstraints(constraints);\n } catch (err) {\n console.error(err);\n this.displayUpdate(\"Error applying constraints to track: \".concat(err));\n }\n const settings = track.getSettings();\n this.displayUpdate(\"Listener Track Settings - \".concat(JSON.stringify(settings, undefined, 2)));\n return settings;\n });\n _defineProperty(this, \"getMediaDevicesAudioContraints\", async () => {\n const availableConstraints = navigator.mediaDevices.getSupportedConstraints();\n const contraints = {\n // ...(availableConstraints.echoCancellation && availableConstraints.echoCancellation == true\n // ? {echoCancellation: {exact: false}}\n // : {}),\n // ...(availableConstraints.sampleRate && availableConstraints.sampleRate == true\n // ? {sampleRate: {ideal: this.calibrateSoundHz}}\n // : {}),\n // ...(availableConstraints.sampleSize && availableConstraints.sampleSize == true\n // ? {sampleSize: {ideal: this.calibrateSoundSamplingDesiredBits}}\n // : {}),\n // ...(availableConstraints.channelCount && availableConstraints.channelCount == true\n // ? {channelCount: {exact: 1}}\n // : {}),\n autoGainControl: false,\n noiseSuppression: false,\n echoCancellation: false,\n channelCount: 1\n };\n if (this.microphoneDeviceId !== '') {\n contraints.deviceId = {\n exact: await this.getDeviceIdByLabel(this.microphoneDeviceId)\n };\n }\n console.log(contraints);\n return contraints;\n });\n _defineProperty(this, \"getDeviceIdByLabel\", async targetLabel => {\n try {\n //get permission to use audio first. (Returns empty labels on some computers if not done first)\n await navigator.mediaDevices.getUserMedia({\n audio: true\n });\n // Enumerate available media devices\n const devices = await navigator.mediaDevices.enumerateDevices();\n\n // Find the device with the matching label\n const matchingDevice = devices.find(device => device.kind === 'audioinput' && device.label === targetLabel);\n if (matchingDevice) {\n return matchingDevice.deviceId; // Return the deviceId if found\n } else {\n throw new Error(\"No audio input device found with label: \\\"\".concat(targetLabel, \"\\\"\"));\n }\n } catch (error) {\n console.error('Error finding device ID:', error);\n return null;\n }\n });\n _defineProperty(this, \"openAudioStream\", async () => {\n this.displayUpdate('Listener - openAudioStream');\n const mobileOS = this.getMobileOS();\n if (false) {}\n const constraints = await this.getMediaDevicesAudioContraints();\n console.log('Constraints right before getUserMedia:', constraints);\n navigator.mediaDevices.getUserMedia({\n audio: constraints,\n video: false\n //audio: {echoCancellation: false, noiseSuppression: false, autoGainControl: false, deviceId: {exact: await this.getDeviceIdByLabel(this.microphoneDeviceId) }},\n }).then(stream => {\n this.displayUpdate(\"Listener Track settings before applied constraints - \".concat(JSON.stringify(stream.getAudioTracks()[0].getSettings(), undefined, 2)));\n this.applyHQTrackConstraints(stream).then(settings => {\n console.log(settings);\n this.sendSamplingRate(settings.sampleRate);\n //let sampleSize = settings.sampleSize;\n let sampleSize = this.calibrateSoundSamplingDesiredBits;\n /*\r\n if (!sampleSize) {\r\n sampleSize = this.calibrateSoundSamplingDesiredBits;\r\n }\r\n */\n this.sendSampleSize(sampleSize);\n this.sendFlags({\n autoGainControl: settings.autoGainControl,\n noiseSuppression: settings.noiseSuppression,\n echoCancellation: settings.echoCancellation\n });\n this.peer.call(this.speakerPeerId, stream); // one-way call\n this.displayUpdate('Listener - openAudioStream');\n }).catch(err => {\n console.log(err);\n this.displayUpdate(\"Listener - Error in applyHQTrackConstraints - \".concat(JSON.stringify(err, undefined, 2)));\n });\n }).catch(err => {\n console.error(err);\n if (err.name === 'OverconstrainedError') {\n const constraint = err.constraint;\n const message = \"The constraint \\\"\".concat(constraint, \"\\\" cannot be satisfied by the selected microphone. Please adjust your calibration settings or choose a different microphone.\");\n this.displayUpdate(\"Listener - OverconstrainedError: \".concat(message));\n console.error(message);\n alert(\"Overconstrained Error: \".concat(message));\n }\n this.displayUpdate(\"Listener - Error in getUserMedia - \".concat(JSON.stringify(err, undefined, 2)));\n });\n });\n this.microphoneFromAPI = params.microphoneFromAPI ? params.microphoneFromAPI : '';\n this.microphoneDeviceId = params.microphoneDeviceId ? params.microphoneDeviceId : '';\n // this.deviceInfoFromUser = params.deviceInfoFromUser\n // ? params.deviceInfoFromUser\n // : {modelNumber: '', modelName: ''};\n this.startTime = Date.now();\n this.receiverPeerId = null;\n const urlParameters = this.parseURLSearchParams();\n this.calibrateSoundHz =\n // previous calibrateSoundHz\n urlParameters.hz !== null && urlParameters.hz !== undefined ? urlParameters.hz : 48000;\n this.calibrateSoundSamplingDesiredBits =\n // previous calibrateSoundSamplingDesiredBits\n urlParameters.bits !== null && urlParameters.bits !== undefined ? urlParameters.bits : 24;\n this.speakerPeerId = urlParameters.speakerPeerId;\n this.peer.on('open', this.onPeerOpen);\n this.peer.on('connection', this.onPeerConnection);\n this.peer.on('disconnected', this.onPeerDisconnected);\n this.peer.on('close', this.onPeerClose);\n this.peer.on('error', this.onPeerError);\n }\n}\n/* harmony default export */ __webpack_exports__[\"default\"] = (Listener);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/listener.js?");
|
|
139
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\n\n\n\n\n/**\r\n * @class Handles the listener's side of the connection. Responsible for getting access to user's microphone,\r\n * and initiating a call to the Speaker.\r\n * @augments AudioPeer\r\n */\nclass Listener extends _audioPeer__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n /**\r\n * Takes a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @example\r\n */\n constructor(params) {\n super(params);\n _defineProperty(this, \"onPeerOpen\", id => {\n this.displayUpdate('Listener - onPeerOpen');\n // Workaround for peer.reconnect deleting previous id\n try {\n if (id === null) {\n this.displayUpdate('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n } catch (error) {\n console.error('Error in onPeerOpen: ', error);\n }\n this.join();\n });\n _defineProperty(this, \"onPeerConnection\", connection => {\n this.displayUpdate('Listener - onPeerConnection');\n // Disallow incoming connections\n connection.on('open', () => {\n connection.send('Sender does not accept incoming connections');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n });\n _defineProperty(this, \"onConnData\", data => {\n this.displayUpdate('Listener - onConnData');\n const hasSpeakerID = Object.prototype.hasOwnProperty.call(data, 'speakerPeerId');\n if (!hasSpeakerID) {\n this.displayUpdate('Error in parsing data received! Must set \"speakerPeerId\" property');\n throw new _peerErrors__WEBPACK_IMPORTED_MODULE_1__.MissingSpeakerIdError('Must set \"speakerPeerId\" property');\n } else {\n // this.conn.close();\n this.displayUpdate(this.speakerPeerId);\n this.speakerPeerId = data.speakerPeerId;\n const newParams = {\n speakerPeerId: this.speakerPeerId\n };\n /*\r\n FUTURE does this limit usable environments?\r\n ie does this work if internet is lost after initial page load?\r\n */\n window.location.search = this.queryStringFromObject(newParams); // Redirect to correctly constructed keypad page\n }\n });\n _defineProperty(this, \"join\", async () => {\n this.displayUpdate('Listener - join');\n /**\r\n * Create the connection between the two Peers.\r\n *\r\n * Sets up callbacks that handle any events related to the\r\n * connection and data received on it.\r\n */\n // Close old connection\n if (this.conn) {\n this.displayUpdate('Closing old connection');\n this.conn.close();\n }\n\n // Create connection to destination peer specified by the query param\n this.displayUpdate(\"Creating connection to: \".concat(this.speakerPeerId));\n this.conn = this.peer.connect(this.speakerPeerId, {\n reliable: true\n });\n this.displayUpdate('Created connection');\n this.conn.on('open', async () => {\n this.displayUpdate('Listener - conn open');\n await this.getDeviceInfo();\n // this.sendSamplingRate();\n await this.openAudioStream();\n });\n\n // Handle incoming data (messages only since this is the signal sender)\n this.conn.on('data', this.onConnData);\n this.conn.on('close', () => {\n console.log('Connection closed');\n });\n });\n _defineProperty(this, \"getMobileOS\", () => {\n var _navigator, _navigator2;\n const ua = navigator.userAgent;\n if (/android/i.test(ua)) {\n return 'Android';\n }\n if (/iPad|iPhone|iPod/.test(ua) || (((_navigator = navigator) === null || _navigator === void 0 || (_navigator = _navigator.userAgentData) === null || _navigator === void 0 ? void 0 : _navigator.platform) || ((_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.platform)) === 'MacIntel' && navigator.maxTouchPoints > 1) {\n return 'iOS';\n }\n return 'Other';\n });\n _defineProperty(this, \"sendSamplingRate\", sampleRate => {\n this.displayUpdate('Listener - sendSamplingRate');\n this.conn.send({\n name: 'samplingRate',\n payload: sampleRate\n });\n });\n _defineProperty(this, \"sendSampleSize\", sampleSize => {\n this.displayUpdate('Listener - sendSampleSize');\n this.conn.send({\n name: 'sampleSize',\n payload: sampleSize\n });\n });\n _defineProperty(this, \"sendFlags\", flags => {\n this.displayUpdate('Listener - sendFlags');\n this.conn.send({\n name: 'flags',\n payload: flags\n });\n });\n _defineProperty(this, \"getDeviceInfo\", async () => {\n const deviceInfo = {};\n try {\n fod.complete(function (data) {\n deviceInfo['IsMobile'] = data.device['ismobile'];\n deviceInfo['HardwareName'] = data.device['hardwarename'];\n deviceInfo['HardwareFamily'] = data.device['hardwarefamily'];\n deviceInfo['HardwareModel'] = data.device['hardwaremodel'];\n deviceInfo['OEM'] = data.device['oem'];\n deviceInfo['HardwareModelVariants'] = data.device['hardwaremodelvariants'];\n deviceInfo['DeviceId'] = data.device['deviceid'];\n deviceInfo['PlatformName'] = data.device['platformname'];\n deviceInfo['PlatformVersion'] = data.device['platformversion'];\n deviceInfo['DeviceType'] = data.device['devicetype'];\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n });\n } catch (error) {\n console.error('Error fetching or executing script:', error.message);\n }\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n deviceInfo['microphoneFromAPI'] = this.microphoneFromAPI;\n deviceInfo['microphoneDeviceId'] = this.microphoneDeviceId;\n deviceInfo['screenWidth'] = window.screen.width;\n deviceInfo['screenHeight'] = window.screen.height;\n console.log('deviceInfo Inside getDeviceInfo: ', deviceInfo);\n this.conn.send({\n name: 'deviceInfo',\n payload: deviceInfo\n });\n return deviceInfo;\n });\n _defineProperty(this, \"applyHQTrackConstraints\", async stream => {\n // Contraint the incoming audio to the sampling rate we want\n stream.getAudioTracks().forEach(track => {\n console.log(track, track.enabled);\n });\n const track = stream.getAudioTracks()[0];\n console.log(track);\n const capabilities = track.getCapabilities();\n this.displayUpdate(\"Listener Track Capabilities - \".concat(JSON.stringify(capabilities, undefined, 2)));\n const constraints = track.getConstraints();\n if (capabilities.echoCancellation) {\n constraints.echoCancellation = false;\n }\n if (capabilities.sampleRate) {\n constraints.sampleRate = this.calibrateSoundHz;\n }\n if (capabilities.sampleSize) {\n constraints.sampleSize = this.calibrateSoundSamplingDesiredBits;\n }\n if (capabilities.channelCount) {\n constraints.channelCount = 1;\n }\n this.displayUpdate(\"Listener Track Constraints - \".concat(JSON.stringify(constraints, undefined, 2)));\n\n // await the promise\n try {\n await track.applyConstraints(constraints);\n } catch (err) {\n console.error(err);\n this.displayUpdate(\"Error applying constraints to track: \".concat(err));\n }\n const settings = track.getSettings();\n this.displayUpdate(\"Listener Track Settings - \".concat(JSON.stringify(settings, undefined, 2)));\n return settings;\n });\n _defineProperty(this, \"getMediaDevicesAudioContraints\", async () => {\n const availableConstraints = navigator.mediaDevices.getSupportedConstraints();\n const contraints = {\n // ...(availableConstraints.echoCancellation && availableConstraints.echoCancellation == true\n // ? {echoCancellation: {exact: false}}\n // : {}),\n // ...(availableConstraints.sampleRate && availableConstraints.sampleRate == true\n // ? {sampleRate: {ideal: this.calibrateSoundHz}}\n // : {}),\n // ...(availableConstraints.sampleSize && availableConstraints.sampleSize == true\n // ? {sampleSize: {ideal: this.calibrateSoundSamplingDesiredBits}}\n // : {}),\n // ...(availableConstraints.channelCount && availableConstraints.channelCount == true\n // ? {channelCount: {exact: 1}}\n // : {}),\n autoGainControl: false,\n noiseSuppression: false,\n echoCancellation: false,\n channelCount: 1\n };\n if (this.microphoneDeviceId !== '') {\n contraints.deviceId = {\n exact: await this.getDeviceIdByLabel(this.microphoneDeviceId)\n };\n }\n console.log(contraints);\n return contraints;\n });\n _defineProperty(this, \"getDeviceIdByLabel\", async targetLabel => {\n try {\n //get permission to use audio first. (Returns empty labels on some computers if not done first)\n await navigator.mediaDevices.getUserMedia({\n audio: true\n });\n // Enumerate available media devices\n const devices = await navigator.mediaDevices.enumerateDevices();\n\n // Find the device with the matching label\n const matchingDevice = devices.find(device => device.kind === 'audioinput' && device.label === targetLabel);\n if (matchingDevice) {\n return matchingDevice.deviceId; // Return the deviceId if found\n } else {\n throw new Error(\"No audio input device found with label: \\\"\".concat(targetLabel, \"\\\"\"));\n }\n } catch (error) {\n console.error('Error finding device ID:', error);\n return null;\n }\n });\n _defineProperty(this, \"openAudioStream\", async () => {\n this.displayUpdate('Listener - openAudioStream');\n const mobileOS = this.getMobileOS();\n if (false) {}\n const constraints = await this.getMediaDevicesAudioContraints();\n console.log('Constraints right before getUserMedia:', constraints);\n navigator.mediaDevices.getUserMedia({\n audio: constraints,\n video: false\n //audio: {echoCancellation: false, noiseSuppression: false, autoGainControl: false, deviceId: {exact: await this.getDeviceIdByLabel(this.microphoneDeviceId) }},\n }).then(stream => {\n this.displayUpdate(\"Listener Track settings before applied constraints - \".concat(JSON.stringify(stream.getAudioTracks()[0].getSettings(), undefined, 2)));\n this.applyHQTrackConstraints(stream).then(settings => {\n console.log(settings);\n this.sendSamplingRate(settings.sampleRate);\n //let sampleSize = settings.sampleSize;\n let sampleSize = this.calibrateSoundSamplingDesiredBits;\n /*\r\n if (!sampleSize) {\r\n sampleSize = this.calibrateSoundSamplingDesiredBits;\r\n }\r\n */\n this.sendSampleSize(sampleSize);\n this.sendFlags({\n autoGainControl: settings.autoGainControl,\n noiseSuppression: settings.noiseSuppression,\n echoCancellation: settings.echoCancellation\n });\n this.peer.call(this.speakerPeerId, stream); // one-way call\n this.displayUpdate('Listener - openAudioStream');\n }).catch(err => {\n console.log(err);\n this.displayUpdate(\"Listener - Error in applyHQTrackConstraints - \".concat(JSON.stringify(err, undefined, 2)));\n });\n }).catch(err => {\n console.error(err);\n if (err.name === 'OverconstrainedError') {\n const constraint = err.constraint;\n const message = \"The constraint \\\"\".concat(constraint, \"\\\" cannot be satisfied by the selected microphone. Please adjust your calibration settings or choose a different microphone.\");\n this.displayUpdate(\"Listener - OverconstrainedError: \".concat(message));\n console.error(message);\n alert(\"Overconstrained Error: \".concat(message));\n }\n this.displayUpdate(\"Listener - Error in getUserMedia - \".concat(JSON.stringify(err, undefined, 2)));\n });\n });\n this.microphoneFromAPI = params.microphoneFromAPI ? params.microphoneFromAPI : '';\n this.microphoneDeviceId = params.microphoneDeviceId ? params.microphoneDeviceId : '';\n // this.deviceInfoFromUser = params.deviceInfoFromUser\n // ? params.deviceInfoFromUser\n // : {modelNumber: '', modelName: ''};\n this.startTime = Date.now();\n this.receiverPeerId = null;\n const urlParameters = this.parseURLSearchParams();\n this.calibrateSoundHz =\n // previous calibrateSoundHz\n urlParameters.hz !== null && urlParameters.hz !== undefined ? urlParameters.hz : 48000;\n this.calibrateSoundSamplingDesiredBits =\n // previous calibrateSoundSamplingDesiredBits\n urlParameters.bits !== null && urlParameters.bits !== undefined ? urlParameters.bits : 24;\n this.speakerPeerId = urlParameters.speakerPeerId;\n this.peer.on('open', this.onPeerOpen);\n this.peer.on('connection', this.onPeerConnection);\n this.peer.on('disconnected', this.onPeerDisconnected);\n this.peer.on('close', this.onPeerClose);\n this.peer.on('error', this.onPeerError);\n }\n}\n/* harmony default export */ __webpack_exports__[\"default\"] = (Listener);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/listener.js?");
|
|
140
140
|
|
|
141
141
|
/***/ }),
|
|
142
142
|
|
|
@@ -158,7 +158,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
158
158
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
159
159
|
|
|
160
160
|
"use strict";
|
|
161
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.array-buffer.slice.js */ \"./node_modules/core-js/modules/es.array-buffer.slice.js\");\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ \"./node_modules/core-js/modules/es.string.replace.js\");\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.typed-array.uint8-array.js */ \"./node_modules/core-js/modules/es.typed-array.uint8-array.js\");\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.typed-array.fill.js */ \"./node_modules/core-js/modules/es.typed-array.fill.js\");\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.typed-array.set.js */ \"./node_modules/core-js/modules/es.typed-array.set.js\");\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.typed-array.sort.js */ \"./node_modules/core-js/modules/es.typed-array.sort.js\");\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/web.dom-collections.iterator.js */ \"./node_modules/core-js/modules/web.dom-collections.iterator.js\");\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__);\n/* harmony import */ var qrcode__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! qrcode */ \"./node_modules/qrcode/lib/browser.js\");\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils */ \"./src/utils.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\n/* harmony import */ var peerjs__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! peerjs */ \"./node_modules/peerjs/dist/bundler.mjs\");\nvar _Speaker;\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }\nfunction _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); }\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nfunction _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }\nfunction _assertClassBrand(e, t, n) { if (\"function\" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError(\"Private element is not present on this object\"); }\n\n\n\n\n\n\n//import {phrases} from '../../dist/example/i18n';\n\n/**\r\n * @class Handles the speaker's side of the connection. Responsible for initiating the connection,\r\n * rendering the QRCode, and answering the call.\r\n * @augments AudioPeer\r\n */\nvar _showQRCode = /*#__PURE__*/new WeakMap();\nvar _showSpinner = /*#__PURE__*/new WeakMap();\nvar _removeUIElems = /*#__PURE__*/new WeakMap();\nvar _onPeerOpen = /*#__PURE__*/new WeakMap();\nvar _onPeerConnection = /*#__PURE__*/new WeakMap();\nvar _onPeerDisconnected = /*#__PURE__*/new WeakMap();\nvar _onPeerError = /*#__PURE__*/new WeakMap();\nvar _onIncomingData = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Speaker extends _audioPeer__WEBPACK_IMPORTED_MODULE_8__[\"default\"] {\n /**\r\n * Takes the url of the current site and a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.\r\n * @param CalibratorInstance\r\n * @example\r\n */\n constructor(_params, _CalibratorInstance) {\n var _params$language, _params$debug, _params$isSmartPhone, _params$calibrateSoun, _params$calibrateSoun2, _params$instructionDi, _params$soundSubtitle, _params$timeToCalibra, _params$soundMessageI, _params$titleDisplayI, _params$timeToCalibra2, _params$isParticipant, _params$isLoudspeaker, _params$micrpohoneIdF, _params$buttonsContai, _params$phrases;\n super(_params);\n _defineProperty(this, \"uri\", '');\n _defineProperty(this, \"qrImage\", void 0);\n _defineProperty(this, \"shortURL\", void 0);\n _defineProperty(this, \"initPeer\", async () => {\n const id = await this.generateTimeBasedPeerID();\n this.peer = new peerjs__WEBPACK_IMPORTED_MODULE_11__[\"default\"](id, {\n secure: true,\n host: 'easyeyes-peer-server.herokuapp.com',\n port: 443,\n config: {\n iceServers: [{\n urls: 'stun:stun.relay.metered.ca:80'\n }, {\n urls: 'turn:global.relay.metered.ca:80',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:80?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:443',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turns:global.relay.metered.ca:443?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }]\n }\n });\n this.peer.on('open', _classPrivateFieldGet(_onPeerOpen, this));\n this.peer.on('connection', _classPrivateFieldGet(_onPeerConnection, this));\n this.peer.on('close', this.onPeerClose);\n this.peer.on('disconnected', _classPrivateFieldGet(_onPeerDisconnected, this));\n this.peer.on('error', _classPrivateFieldGet(_onPeerError, this));\n });\n _defineProperty(this, \"generateTimeBasedPeerID\", async () => {\n const now = new Date().getTime();\n const randomBuffer = new Uint8Array(10);\n crypto.getRandomValues(randomBuffer);\n const randomPart = Array.from(randomBuffer).map(b => b.toString(36)).join('');\n const toHash = \"\".concat(now, \"-\").concat(randomPart);\n const encoder = new TextEncoder();\n const data = encoder.encode(toHash);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const hashArray = Array.from(new Uint8Array(hash)); // Convert buffer to byte array\n const hashString = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n const shortHash = hashString.substring(0, 12); // Use more of the hash for a longer ID\n // return shortHash; // Consider converting this to Base62\n return this.encodeBase62(parseInt(shortHash, 16));\n });\n _defineProperty(this, \"encodeBase62\", num => {\n const base = 36;\n const characters = '0123456789abcdefghijklmnopqrstuvwxyz';\n let result = '';\n while (num > 0) {\n result = characters[num % base] + result;\n num = Math.floor(num / base);\n }\n return result;\n });\n /**\r\n * Called after the peer conncection has been opened.\r\n * Generates a QR code for the connection and displays it.\r\n *\r\n * @private\r\n * @example\r\n */\n\n _classPrivateFieldInitSpec(this, _showQRCode, async () => {\n // Get query string, the URL parameters to specify a Listener\n const queryStringParameters = {\n speakerPeerId: this.peer.id,\n sp: this.isSmartPhone,\n hz: this.calibrateSoundHz,\n bits: this.calibrateSoundSamplingDesiredBits,\n lang: this.language,\n deviceId: this.deviceId\n };\n const queryString = this.queryStringFromObject(queryStringParameters);\n this.uri = this.siteUrl + queryString;\n if (this.isSmartPhone) {\n // if (true) { // test smartphone QR\n // Display QR code for the participant to scan\n const qrCanvas = document.createElement('canvas');\n qrCanvas.setAttribute('id', 'qrCanvas');\n qrcode__WEBPACK_IMPORTED_MODULE_7__.toCanvas(qrCanvas, this.uri, error => {\n if (error) console.error(error);\n });\n const explanation = document.createElement('h2');\n explanation.id = 'skipQRExplanation';\n explanation.style = \"\\n user-select: text;\\n margin-top: 9px;\\n font-size: 1.1rem;\\n \";\n // Define the URL and options for the request\n const url = 'https://api.short.io/links/public';\n const options = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: 'pk_fysLKGj3legZz4XZ'\n },\n body: JSON.stringify({\n domain: 'listeners.link',\n // Ensure this domain is valid for your account\n originalURL: this.uri\n })\n };\n\n // Make the request using fetch\n await fetch(url, options).then(response => {\n if (!response.ok) {\n throw new Error(\"HTTP error! Status: \".concat(response.status));\n }\n return response.json(); // Parse the JSON response\n }).then(data => {\n explanation.innerHTML = (0,_utils__WEBPACK_IMPORTED_MODULE_9__.formatLineBreak)(this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language].replace('xxx', \"<b style=\\\"user-select: text\\\">\".concat(data.shortURL, \"</b>\")).replace('XXX', \"<b style=\\\"user-select: text\\\">\".concat(data.shortURL, \"</b>\")), this.phrases.RC_checkInternetConnection[this.language]);\n const checkConnection = document.createElement('a');\n checkConnection.id = 'check-connection';\n checkConnection.href = '#';\n checkConnection.innerHTML = \"check the phone's internet connection\";\n const lang = this.language;\n const phrases = this.phrases;\n checkConnection.addEventListener('click', function (event) {\n console.log('clicked');\n event.preventDefault(); // Prevent the default link action\n (0,_utils__WEBPACK_IMPORTED_MODULE_9__.createAndShowPopup)(lang, phrases);\n });\n explanation.querySelector('a#check-connection').replaceWith(checkConnection);\n }).catch(error => {\n console.error('Error:', error.message); // Handle errors\n });\n const qrImage = new Image(400, 400);\n qrImage.setAttribute('id', 'compatibilityCheckQRImage');\n qrImage.style.zIndex = Infinity;\n qrImage.style.width = 400;\n qrImage.style.height = 400;\n qrImage.style.aspectRatio = 1;\n qrImage.src = qrCanvas.toDataURL();\n qrImage.style.maxHeight = '150px';\n qrImage.style.maxWidth = '150px';\n this.qrImage = qrImage;\n const container = document.createElement('div');\n container.style.display = 'flex';\n container.style.justifyContent = 'space-between';\n container.style.alignItems = 'top';\n container.id = 'skipQRContainer';\n container.appendChild(qrImage);\n container.appendChild(explanation);\n container.appendChild(this.buttonsContainer);\n const qrContainer = document.createElement('div');\n qrContainer.appendChild(container);\n document.getElementById(this.targetElement).appendChild(qrContainer);\n } else {\n // show the link to the user\n // If specified HTML Id is available, show QR code there\n if (document.getElementById(this.targetElement)) {\n // const linkTag = document.createElement('a');\n // linkTag.setAttribute('href', uri);\n // linkTag.innerHTML = 'Click here to start the calibration';\n // linkTag.target = '_blank';\n // document.getElementById(this.targetElement).appendChild(linkTag);\n // document.getElementById(this.targetElement).appendChild(qrCanvas);\n\n const proceedButton = document.createElement('button');\n proceedButton.setAttribute('id', 'calibrationProceedButton');\n proceedButton.setAttribute('class', 'btn btn-success');\n proceedButton.innerHTML = this.phrases.T_proceed[this.language];\n proceedButton.onclick = () => {\n // open the link in a new tab\n window.open(this.uri, '_blank');\n // remove the button\n document.getElementById('calibrationProceedButton').remove();\n };\n document.getElementById(this.targetElement).appendChild(proceedButton);\n }\n }\n // or just print it to console\n console.log('TEST: Peer reachable at: ', this.uri);\n });\n _classPrivateFieldInitSpec(this, _showSpinner, () => {\n const spinner = document.createElement('div');\n spinner.className = 'spinner-border ml-auto';\n spinner.role = 'status';\n spinner.ariaHidden = 'true';\n spinner.style.marginTop = '0.8rem';\n document.getElementById(this.targetElement).appendChild(spinner);\n\n // clear instructionDisplay\n const soundMessage = document.getElementById(this.soundMessageId);\n soundMessage.innerHTML = '';\n soundMessage.style.display = 'none';\n const instructionDisplay = document.getElementById(this.instructionDisplayId);\n const background = document.getElementById('background'); // todo: get background id from params\n const subtitle = document.getElementById(this.soundSubtitleId);\n if (subtitle) {\n subtitle.innerHTML = '';\n }\n if (instructionDisplay) {\n instructionDisplay.innerHTML = '';\n instructionDisplay.style.whiteSpace = 'nowrap';\n instructionDisplay.style.fontWeight = 'bold';\n instructionDisplay.style.width = 'fit-content';\n instructionDisplay.innerHTML = this.phrases.RC_soundRecording[this.language];\n let fontSize = 100;\n instructionDisplay.style.fontSize = fontSize + 'px';\n while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {\n fontSize--;\n instructionDisplay.style.fontSize = fontSize + 'px';\n }\n // const p = document.createElement('p');\n // // font size\n // p.style.fontSize = '1.1rem';\n // p.style.fontWeight = 'normal';\n // p.style.paddingTop = '20px';\n // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];\n // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n // instructionDisplay.appendChild(p);\n }\n const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);\n if (timeToCalibrateDisplay) {\n const timeToCalibrateText = this.phrases.RC_howLongToCalibrate[this.language];\n timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n timeToCalibrateDisplay.style.fontWeight = 'normal';\n timeToCalibrateDisplay.style.fontSize = '1rem';\n // timeToCalibrateDisplay.style.paddingTop = '20px';\n }\n\n // Update title - titleDisplayId\n const titleDisplay = document.getElementById(this.titleDisplayId);\n if (titleDisplay) {\n // if (this.isParticipant) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n // } else if (this.isSmartPhone) {\n // if (this.isLoudspeakerCalibration) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n if (this.isLoudspeakerCalibration) {\n if (this.isParticipant) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n } else if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');\n }\n } else {\n if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n }\n }\n }\n });\n _classPrivateFieldInitSpec(this, _removeUIElems, () => {\n const parent = document.getElementById(this.targetElement);\n while (parent.firstChild) {\n parent.firstChild.remove();\n }\n });\n /**\r\n * Called when the peer connection is opened.\r\n * Saves the peer id and calls the QR code generator.\r\n *\r\n * @param peerId - The peer id of the peer connection.\r\n * @param id\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerOpen, id => {\n // Workaround for peer.reconnect deleting previous id\n if (id === null) {\n console.error('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n if (id !== this.peer.id) {\n console.warn('DEBUG Check you assumption that id === this.peer.id');\n }\n _classPrivateFieldGet(_showQRCode, this).call(this);\n });\n /**\r\n * Called when the peer connection is established.\r\n * Enforces a single connection.\r\n *\r\n * @param connection - The connection object.\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerConnection, connection => {\n // Allow only a single connection\n if (this.conn && this.conn.open) {\n connection.on('open', () => {\n connection.send('Already connected to another client');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n return;\n }\n this.conn = connection;\n console.log('Connected to: ', this.conn.peer);\n _classPrivateFieldGet(_ready, this).call(this);\n });\n /**\r\n * Called when the peer connection is closed.\r\n *\r\n * @private\r\n * @example\r\n */\n _defineProperty(this, \"onPeerClose\", () => {\n this.conn = null;\n console.log('Connection destroyed');\n });\n /**\r\n * Called when the peer connection is disconnected.\r\n * Attempts to reconnect.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerDisconnected, () => {\n console.log('Connection lost. Please reconnect');\n\n // Workaround for peer.reconnect deleting previous id\n this.peer.id = this.lastPeerId;\n // eslint-disable-next-line no-underscore-dangle\n this.peer._lastServerId = this.lastPeerId;\n this.peer.reconnect();\n });\n /**\r\n * Called when the peer connection encounters an error.\r\n *\r\n * @param error\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerError, error => {\n // TODO: check if this function is needed or not\n console.error(error);\n });\n /**\r\n * Called when data is received from the peer connection.\r\n *\r\n * @param data\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onIncomingData, data => {\n // enforce object type\n if (!Object.prototype.hasOwnProperty.call(data, 'name') || !Object.prototype.hasOwnProperty.call(data, 'payload')) {\n console.error('Received malformed data: ', data);\n return;\n }\n switch (data.name) {\n case 'samplingRate':\n this.ac.setSamplingRates(data.payload);\n break;\n case 'sampleSize':\n this.ac.setSampleSize(data.payload);\n break;\n case 'deviceType':\n this.ac.setDeviceType(data.payload);\n break;\n case 'deviceName':\n this.ac.setDeviceName(data.payload);\n break;\n case 'flags':\n //this.ac.setDeviceName(data.payload);\n console.log('FLAGS');\n console.log(data.payload);\n this.ac.setFlags(data.payload);\n break;\n case 'deviceInfo':\n this.ac.setDeviceInfo(data.payload);\n console.log('Received device info from listener: ', data.payload);\n break;\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.UnsupportedDeviceError.name:\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.MissingSpeakerIdError.name:\n throw data.payload;\n break;\n default:\n break;\n }\n });\n /**\r\n * Called when the peer connection is #ready.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _ready, () => {\n // Perform callback with data\n this.conn.on('data', _classPrivateFieldGet(_onIncomingData, this));\n this.conn.on('close', () => {\n console.log('Connection reset<br>Awaiting connection...');\n this.conn = null;\n });\n });\n /** .\r\n * .\r\n * .\r\n * Debug method for downloading the recorded audio\r\n *\r\n * @public\r\n * @example\r\n */\n _defineProperty(this, \"downloadData\", () => {\n this.ac.downloadData();\n });\n _defineProperty(this, \"repeatCalibration\", async (params, stream, CalibratorInstance) => {\n this.ac = CalibratorInstance;\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n _classPrivateFieldGet(_showSpinner, this).call(this);\n console.log('This is a repeat');\n // wrap the calibration process in a promise so we can await it\n return new Promise(async (resolve, reject) => {\n const result = await this.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n resolve(result);\n });\n });\n this.language = (_params$language = _params === null || _params === void 0 ? void 0 : _params.language) !== null && _params$language !== void 0 ? _params$language : 'en-US';\n this.siteUrl += '/listener?';\n this.ac = _CalibratorInstance;\n this.result = null;\n this.debug = (_params$debug = _params === null || _params === void 0 ? void 0 : _params.debug) !== null && _params$debug !== void 0 ? _params$debug : false;\n this.isSmartPhone = (_params$isSmartPhone = _params === null || _params === void 0 ? void 0 : _params.isSmartPhone) !== null && _params$isSmartPhone !== void 0 ? _params$isSmartPhone : false;\n this.calibrateSoundHz = (_params$calibrateSoun = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundHz) !== null && _params$calibrateSoun !== void 0 ? _params$calibrateSoun : 48000;\n this.calibrateSoundSamplingDesiredBits = (_params$calibrateSoun2 = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundSamplingDesiredBits) !== null && _params$calibrateSoun2 !== void 0 ? _params$calibrateSoun2 : 24;\n this.instructionDisplayId = (_params$instructionDi = _params === null || _params === void 0 ? void 0 : _params.instructionDisplayId) !== null && _params$instructionDi !== void 0 ? _params$instructionDi : '';\n this.soundSubtitleId = (_params$soundSubtitle = _params === null || _params === void 0 ? void 0 : _params.soundSubtitleId) !== null && _params$soundSubtitle !== void 0 ? _params$soundSubtitle : '';\n this.timeToCalibrateDisplay = (_params$timeToCalibra = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrateId) !== null && _params$timeToCalibra !== void 0 ? _params$timeToCalibra : '';\n this.soundMessageId = (_params$soundMessageI = _params === null || _params === void 0 ? void 0 : _params.soundMessageId) !== null && _params$soundMessageI !== void 0 ? _params$soundMessageI : '';\n this.titleDisplayId = (_params$titleDisplayI = _params === null || _params === void 0 ? void 0 : _params.titleDisplayId) !== null && _params$titleDisplayI !== void 0 ? _params$titleDisplayI : '';\n this.timeToCalibrate = (_params$timeToCalibra2 = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrate) !== null && _params$timeToCalibra2 !== void 0 ? _params$timeToCalibra2 : 10;\n this.isParticipant = (_params$isParticipant = _params === null || _params === void 0 ? void 0 : _params.isParticipant) !== null && _params$isParticipant !== void 0 ? _params$isParticipant : false;\n this.isLoudspeakerCalibration = (_params$isLoudspeaker = _params === null || _params === void 0 ? void 0 : _params.isLoudspeakerCalibration) !== null && _params$isLoudspeaker !== void 0 ? _params$isLoudspeaker : false;\n this.deviceId = (_params$micrpohoneIdF = _params === null || _params === void 0 ? void 0 : _params.micrpohoneIdFromWebAudioApi) !== null && _params$micrpohoneIdF !== void 0 ? _params$micrpohoneIdF : '';\n this.buttonsContainer = (_params$buttonsContai = _params === null || _params === void 0 ? void 0 : _params.buttonsContainer) !== null && _params$buttonsContai !== void 0 ? _params$buttonsContai : document.createElement('div');\n this.phrases = (_params$phrases = _params === null || _params === void 0 ? void 0 : _params.phrases) !== null && _params$phrases !== void 0 ? _params$phrases : {};\n\n /* Set up callbacks that handle any events related to our peer object. */\n }\n}\n\n/* \r\nReferenced links:\r\nhttps://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676\r\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\r\nhttps://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]\r\n*/\n_Speaker = Speaker;\n/**\r\n * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.\r\n *\r\n * @param params - The parameters to be passed to the peer object.\r\n * @param Calibrator - The class that defines the calibration process.\r\n * @param CalibratorInstance\r\n * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).\r\n * @public\r\n * @example\r\n */\n_defineProperty(Speaker, \"startCalibration\", async function (params, CalibratorInstance) {\n let timeOut = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n await speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n if (params.displayUpdate) {\n params.displayUpdate.style.display = '';\n }\n\n // resolve when we have a result\n speaker.result = await speaker.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"testIIR\", async function (params, CalibratorInstance, IIR) {\n let timeOut = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n // resolve when we have a result\n speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"closeConnection\", () => {\n _Speaker.conn = null;\n console.log('Connection destroyed');\n});\n/* harmony default export */ __webpack_exports__[\"default\"] = (Speaker);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/speaker.js?");
|
|
161
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.array-buffer.slice.js */ \"./node_modules/core-js/modules/es.array-buffer.slice.js\");\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ \"./node_modules/core-js/modules/es.string.replace.js\");\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.typed-array.uint8-array.js */ \"./node_modules/core-js/modules/es.typed-array.uint8-array.js\");\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.typed-array.fill.js */ \"./node_modules/core-js/modules/es.typed-array.fill.js\");\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.typed-array.set.js */ \"./node_modules/core-js/modules/es.typed-array.set.js\");\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.typed-array.sort.js */ \"./node_modules/core-js/modules/es.typed-array.sort.js\");\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/web.dom-collections.iterator.js */ \"./node_modules/core-js/modules/web.dom-collections.iterator.js\");\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__);\n/* harmony import */ var qrcode__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! qrcode */ \"./node_modules/qrcode/lib/browser.js\");\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils */ \"./src/utils.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\n/* harmony import */ var peerjs__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! peerjs */ \"./node_modules/peerjs/dist/bundler.mjs\");\nvar _Speaker;\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }\nfunction _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); }\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nfunction _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }\nfunction _assertClassBrand(e, t, n) { if (\"function\" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError(\"Private element is not present on this object\"); }\n\n\n\n\n\n\n//import {phrases} from '../../dist/example/i18n';\n\n/**\r\n * @class Handles the speaker's side of the connection. Responsible for initiating the connection,\r\n * rendering the QRCode, and answering the call.\r\n * @augments AudioPeer\r\n */\nvar _showQRCode = /*#__PURE__*/new WeakMap();\nvar _showSpinner = /*#__PURE__*/new WeakMap();\nvar _removeUIElems = /*#__PURE__*/new WeakMap();\nvar _onPeerOpen = /*#__PURE__*/new WeakMap();\nvar _onPeerConnection = /*#__PURE__*/new WeakMap();\nvar _onPeerDisconnected = /*#__PURE__*/new WeakMap();\nvar _onPeerError = /*#__PURE__*/new WeakMap();\nvar _onIncomingData = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Speaker extends _audioPeer__WEBPACK_IMPORTED_MODULE_8__[\"default\"] {\n /**\r\n * Takes the url of the current site and a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.\r\n * @param CalibratorInstance\r\n * @example\r\n */\n constructor(_params, _CalibratorInstance) {\n var _params$language, _params$debug, _params$isSmartPhone, _params$calibrateSoun, _params$calibrateSoun2, _params$instructionDi, _params$soundSubtitle, _params$timeToCalibra, _params$soundMessageI, _params$titleDisplayI, _params$timeToCalibra2, _params$isParticipant, _params$isLoudspeaker, _params$micrpohoneIdF, _params$buttonsContai, _params$phrases;\n super(_params);\n _defineProperty(this, \"uri\", '');\n _defineProperty(this, \"qrImage\", void 0);\n _defineProperty(this, \"shortURL\", void 0);\n _defineProperty(this, \"initPeer\", async () => {\n const id = await this.generateTimeBasedPeerID();\n this.peer = new peerjs__WEBPACK_IMPORTED_MODULE_11__[\"default\"](id, {\n secure: true,\n host: 'easyeyes-peer-server.herokuapp.com',\n port: 443,\n config: {\n iceServers: [{\n urls: 'stun:stun.relay.metered.ca:80'\n }, {\n urls: 'turn:global.relay.metered.ca:80',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:80?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:443',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turns:global.relay.metered.ca:443?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }]\n }\n });\n this.peer.on('open', _classPrivateFieldGet(_onPeerOpen, this));\n this.peer.on('connection', _classPrivateFieldGet(_onPeerConnection, this));\n this.peer.on('close', this.onPeerClose);\n this.peer.on('disconnected', _classPrivateFieldGet(_onPeerDisconnected, this));\n this.peer.on('error', _classPrivateFieldGet(_onPeerError, this));\n });\n _defineProperty(this, \"generateTimeBasedPeerID\", async () => {\n const now = new Date().getTime();\n const randomBuffer = new Uint8Array(10);\n crypto.getRandomValues(randomBuffer);\n const randomPart = Array.from(randomBuffer).map(b => b.toString(36)).join('');\n const toHash = \"\".concat(now, \"-\").concat(randomPart);\n const encoder = new TextEncoder();\n const data = encoder.encode(toHash);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const hashArray = Array.from(new Uint8Array(hash)); // Convert buffer to byte array\n const hashString = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n const shortHash = hashString.substring(0, 12); // Use more of the hash for a longer ID\n // return shortHash; // Consider converting this to Base62\n return this.encodeBase62(parseInt(shortHash, 16));\n });\n _defineProperty(this, \"encodeBase62\", num => {\n const base = 36;\n const characters = '0123456789abcdefghijklmnopqrstuvwxyz';\n let result = '';\n while (num > 0) {\n result = characters[num % base] + result;\n num = Math.floor(num / base);\n }\n return result;\n });\n /**\r\n * Called after the peer conncection has been opened.\r\n * Generates a QR code for the connection and displays it.\r\n *\r\n * @private\r\n * @example\r\n */\n\n _classPrivateFieldInitSpec(this, _showQRCode, async () => {\n const queryStringParameters = {\n speakerPeerId: this.peer.id,\n sp: this.isSmartPhone,\n hz: this.calibrateSoundHz,\n bits: this.calibrateSoundSamplingDesiredBits,\n lang: this.language,\n deviceId: this.deviceId\n };\n const queryString = this.queryStringFromObject(queryStringParameters);\n this.uri = this.siteUrl + queryString;\n if (this.isSmartPhone) {\n // Generate QR code\n const qrCanvas = document.createElement('canvas');\n qrCanvas.setAttribute('id', 'qrCanvas');\n qrcode__WEBPACK_IMPORTED_MODULE_7__.toCanvas(qrCanvas, this.uri, error => {\n if (error) console.error(error);\n });\n\n // Create QR image\n const qrImage = new Image();\n qrImage.setAttribute('id', 'compatibilityCheckQRImage');\n qrImage.style.zIndex = Infinity;\n qrImage.style.height = '150px';\n qrImage.style.width = '150px';\n qrImage.style.margin = '-10px';\n qrImage.style.aspectRatio = 1;\n qrImage.src = qrCanvas.toDataURL();\n this.qrImage = qrImage;\n\n // Get shortened URL\n let shortURL = '';\n try {\n const response = await fetch('https://api.short.io/links/public', {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: 'pk_fysLKGj3legZz4XZ'\n },\n body: JSON.stringify({\n domain: 'listeners.link',\n originalURL: this.uri\n })\n });\n if (!response.ok) {\n throw new Error(\"HTTP error! Status: \".concat(response.status));\n }\n const data = await response.json();\n shortURL = data.shortURL;\n } catch (error) {\n console.error('Error:', error.message);\n }\n\n // Main container with 3 columns\n const container = document.createElement('div');\n container.style.display = 'flex';\n container.style.alignItems = 'flex-start';\n container.style.paddingTop = '0';\n container.id = 'skipQRContainer';\n\n // Column 1: QR Code\n const qrColumn = document.createElement('div');\n qrColumn.style.flex = '0 0 auto';\n qrColumn.appendChild(qrImage);\n\n // Column 2: Explanation Text\n const textColumn = document.createElement('div');\n textColumn.style.flex = '1';\n textColumn.style.padding = '0 20px';\n textColumn.style.maxWidth = '560px';\n const explanation = document.createElement('h2');\n explanation.style.fontSize = '1.1rem';\n explanation.id = 'skipQRExplanation';\n explanation.style.margin = '0';\n explanation.style.textAlign = 'left';\n explanation.innerHTML = (0,_utils__WEBPACK_IMPORTED_MODULE_9__.formatLineBreak)(this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language].replace('xxx', \"<b style=\\\"user-select: text\\\">\".concat(shortURL, \"</b>\")).replace('XXX', \"<b style=\\\"user-select: text\\\">\".concat(shortURL, \"</b>\")), this.phrases.RC_checkInternetConnection[this.language]);\n const checkConnection = document.createElement('a');\n checkConnection.id = 'check-connection';\n checkConnection.href = '#';\n checkConnection.innerHTML = \"check the phone's internet connection\";\n checkConnection.addEventListener('click', function (event) {\n event.preventDefault();\n (0,_utils__WEBPACK_IMPORTED_MODULE_9__.createAndShowPopup)(this.language, this.phrases);\n });\n explanation.querySelector('a#check-connection').replaceWith(checkConnection);\n textColumn.appendChild(explanation);\n\n // Column 3: Buttons\n const buttonColumn = document.createElement('div');\n buttonColumn.style.display = 'flex';\n buttonColumn.style.flexDirection = 'column';\n buttonColumn.style.gap = '10px';\n buttonColumn.style.flex = '0 0 auto';\n buttonColumn.style.alignItems = 'flex-end';\n buttonColumn.appendChild(this.buttonsContainer);\n\n // Assemble the columns\n container.appendChild(qrColumn);\n container.appendChild(textColumn);\n container.appendChild(buttonColumn);\n document.getElementById(this.targetElement).appendChild(container);\n } else {\n // show the link to the user\n // If specified HTML Id is available, show QR code there\n if (document.getElementById(this.targetElement)) {\n // const linkTag = document.createElement('a');\n // linkTag.setAttribute('href', uri);\n // linkTag.innerHTML = 'Click here to start the calibration';\n // linkTag.target = '_blank';\n // document.getElementById(this.targetElement).appendChild(linkTag);\n // document.getElementById(this.targetElement).appendChild(qrCanvas);\n\n const proceedButton = document.createElement('button');\n proceedButton.setAttribute('id', 'calibrationProceedButton');\n proceedButton.setAttribute('class', 'btn btn-success');\n proceedButton.innerHTML = this.phrases.T_proceed[this.language];\n proceedButton.onclick = () => {\n // open the link in a new tab\n window.open(this.uri, '_blank');\n // remove the button\n document.getElementById('calibrationProceedButton').remove();\n };\n document.getElementById(this.targetElement).appendChild(proceedButton);\n }\n }\n // or just print it to console\n console.log('TEST: Peer reachable at: ', this.uri);\n });\n _classPrivateFieldInitSpec(this, _showSpinner, () => {\n const spinner = document.createElement('div');\n spinner.className = 'spinner-border ml-auto';\n spinner.role = 'status';\n spinner.ariaHidden = 'true';\n spinner.style.marginTop = '0.8rem';\n document.getElementById(this.targetElement).appendChild(spinner);\n\n // clear instructionDisplay\n const soundMessage = document.getElementById(this.soundMessageId);\n soundMessage.innerHTML = '';\n soundMessage.style.display = 'none';\n const instructionDisplay = document.getElementById(this.instructionDisplayId);\n const background = document.getElementById('background'); // todo: get background id from params\n const subtitle = document.getElementById(this.soundSubtitleId);\n if (subtitle) {\n subtitle.innerHTML = '';\n }\n if (instructionDisplay) {\n instructionDisplay.innerHTML = '';\n instructionDisplay.style.whiteSpace = 'nowrap';\n instructionDisplay.style.fontWeight = 'bold';\n instructionDisplay.style.width = 'fit-content';\n instructionDisplay.innerHTML = this.phrases.RC_soundRecording[this.language];\n let fontSize = 100;\n instructionDisplay.style.fontSize = fontSize + 'px';\n while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {\n fontSize--;\n instructionDisplay.style.fontSize = fontSize + 'px';\n }\n // const p = document.createElement('p');\n // // font size\n // p.style.fontSize = '1.1rem';\n // p.style.fontWeight = 'normal';\n // p.style.paddingTop = '20px';\n // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];\n // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n // instructionDisplay.appendChild(p);\n }\n const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);\n if (timeToCalibrateDisplay) {\n const timeToCalibrateText = this.phrases.RC_howLongToCalibrate[this.language];\n timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n timeToCalibrateDisplay.style.fontWeight = 'normal';\n timeToCalibrateDisplay.style.fontSize = '1rem';\n // timeToCalibrateDisplay.style.paddingTop = '20px';\n }\n\n // Update title - titleDisplayId\n const titleDisplay = document.getElementById(this.titleDisplayId);\n if (titleDisplay) {\n // if (this.isParticipant) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n // } else if (this.isSmartPhone) {\n // if (this.isLoudspeakerCalibration) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n if (this.isLoudspeakerCalibration) {\n if (this.isParticipant) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n } else if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');\n }\n } else {\n if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n }\n }\n }\n });\n _classPrivateFieldInitSpec(this, _removeUIElems, () => {\n const parent = document.getElementById(this.targetElement);\n while (parent.firstChild) {\n parent.firstChild.remove();\n }\n });\n /**\r\n * Called when the peer connection is opened.\r\n * Saves the peer id and calls the QR code generator.\r\n *\r\n * @param peerId - The peer id of the peer connection.\r\n * @param id\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerOpen, id => {\n // Workaround for peer.reconnect deleting previous id\n try {\n if (id === null) {\n console.error('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n if (id !== this.peer.id) {\n console.warn('DEBUG Check you assumption that id === this.peer.id');\n }\n } catch (error) {\n console.error('Error in #onPeerOpen: ', error);\n }\n _classPrivateFieldGet(_showQRCode, this).call(this);\n });\n /**\r\n * Called when the peer connection is established.\r\n * Enforces a single connection.\r\n *\r\n * @param connection - The connection object.\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerConnection, connection => {\n // Allow only a single connection\n if (this.conn && this.conn.open) {\n connection.on('open', () => {\n connection.send('Already connected to another client');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n return;\n }\n this.conn = connection;\n console.log('Connected to: ', this.conn.peer);\n _classPrivateFieldGet(_ready, this).call(this);\n });\n /**\r\n * Called when the peer connection is closed.\r\n *\r\n * @private\r\n * @example\r\n */\n _defineProperty(this, \"onPeerClose\", () => {\n this.conn = null;\n console.log('Connection destroyed');\n });\n /**\r\n * Called when the peer connection is disconnected.\r\n * Attempts to reconnect.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerDisconnected, () => {\n console.log('Connection lost. Please reconnect');\n try {\n // Workaround for peer.reconnect deleting previous id\n this.peer.id = this.lastPeerId;\n // eslint-disable-next-line no-underscore-dangle\n this.peer._lastServerId = this.lastPeerId;\n this.peer.reconnect();\n } catch (error) {\n console.error('Error in #onPeerDisconnected: ', error);\n }\n });\n /**\r\n * Called when the peer connection encounters an error.\r\n *\r\n * @param error\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerError, error => {\n // TODO: check if this function is needed or not\n console.error(error);\n });\n /**\r\n * Called when data is received from the peer connection.\r\n *\r\n * @param data\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onIncomingData, data => {\n // enforce object type\n if (!Object.prototype.hasOwnProperty.call(data, 'name') || !Object.prototype.hasOwnProperty.call(data, 'payload')) {\n console.error('Received malformed data: ', data);\n return;\n }\n switch (data.name) {\n case 'samplingRate':\n this.ac.setSamplingRates(data.payload);\n break;\n case 'sampleSize':\n this.ac.setSampleSize(data.payload);\n break;\n case 'deviceType':\n this.ac.setDeviceType(data.payload);\n break;\n case 'deviceName':\n this.ac.setDeviceName(data.payload);\n break;\n case 'flags':\n //this.ac.setDeviceName(data.payload);\n console.log('FLAGS');\n console.log(data.payload);\n this.ac.setFlags(data.payload);\n break;\n case 'deviceInfo':\n this.ac.setDeviceInfo(data.payload);\n console.log('Received device info from listener: ', data.payload);\n break;\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.UnsupportedDeviceError.name:\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.MissingSpeakerIdError.name:\n throw data.payload;\n break;\n default:\n break;\n }\n });\n /**\r\n * Called when the peer connection is #ready.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _ready, () => {\n // Perform callback with data\n this.conn.on('data', _classPrivateFieldGet(_onIncomingData, this));\n this.conn.on('close', () => {\n console.log('Connection reset<br>Awaiting connection...');\n this.conn = null;\n });\n });\n /** .\r\n * .\r\n * .\r\n * Debug method for downloading the recorded audio\r\n *\r\n * @public\r\n * @example\r\n */\n _defineProperty(this, \"downloadData\", () => {\n this.ac.downloadData();\n });\n _defineProperty(this, \"repeatCalibration\", async (params, stream, CalibratorInstance) => {\n this.ac = CalibratorInstance;\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n _classPrivateFieldGet(_showSpinner, this).call(this);\n console.log('This is a repeat');\n // wrap the calibration process in a promise so we can await it\n return new Promise(async (resolve, reject) => {\n const result = await this.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n resolve(result);\n });\n });\n this.language = (_params$language = _params === null || _params === void 0 ? void 0 : _params.language) !== null && _params$language !== void 0 ? _params$language : 'en-US';\n this.siteUrl += '/listener?';\n this.ac = _CalibratorInstance;\n this.result = null;\n this.debug = (_params$debug = _params === null || _params === void 0 ? void 0 : _params.debug) !== null && _params$debug !== void 0 ? _params$debug : false;\n this.isSmartPhone = (_params$isSmartPhone = _params === null || _params === void 0 ? void 0 : _params.isSmartPhone) !== null && _params$isSmartPhone !== void 0 ? _params$isSmartPhone : false;\n this.calibrateSoundHz = (_params$calibrateSoun = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundHz) !== null && _params$calibrateSoun !== void 0 ? _params$calibrateSoun : 48000;\n this.calibrateSoundSamplingDesiredBits = (_params$calibrateSoun2 = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundSamplingDesiredBits) !== null && _params$calibrateSoun2 !== void 0 ? _params$calibrateSoun2 : 24;\n this.instructionDisplayId = (_params$instructionDi = _params === null || _params === void 0 ? void 0 : _params.instructionDisplayId) !== null && _params$instructionDi !== void 0 ? _params$instructionDi : '';\n this.soundSubtitleId = (_params$soundSubtitle = _params === null || _params === void 0 ? void 0 : _params.soundSubtitleId) !== null && _params$soundSubtitle !== void 0 ? _params$soundSubtitle : '';\n this.timeToCalibrateDisplay = (_params$timeToCalibra = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrateId) !== null && _params$timeToCalibra !== void 0 ? _params$timeToCalibra : '';\n this.soundMessageId = (_params$soundMessageI = _params === null || _params === void 0 ? void 0 : _params.soundMessageId) !== null && _params$soundMessageI !== void 0 ? _params$soundMessageI : '';\n this.titleDisplayId = (_params$titleDisplayI = _params === null || _params === void 0 ? void 0 : _params.titleDisplayId) !== null && _params$titleDisplayI !== void 0 ? _params$titleDisplayI : '';\n this.timeToCalibrate = (_params$timeToCalibra2 = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrate) !== null && _params$timeToCalibra2 !== void 0 ? _params$timeToCalibra2 : 10;\n this.isParticipant = (_params$isParticipant = _params === null || _params === void 0 ? void 0 : _params.isParticipant) !== null && _params$isParticipant !== void 0 ? _params$isParticipant : false;\n this.isLoudspeakerCalibration = (_params$isLoudspeaker = _params === null || _params === void 0 ? void 0 : _params.isLoudspeakerCalibration) !== null && _params$isLoudspeaker !== void 0 ? _params$isLoudspeaker : false;\n this.deviceId = (_params$micrpohoneIdF = _params === null || _params === void 0 ? void 0 : _params.micrpohoneIdFromWebAudioApi) !== null && _params$micrpohoneIdF !== void 0 ? _params$micrpohoneIdF : '';\n this.buttonsContainer = (_params$buttonsContai = _params === null || _params === void 0 ? void 0 : _params.buttonsContainer) !== null && _params$buttonsContai !== void 0 ? _params$buttonsContai : document.createElement('div');\n this.phrases = (_params$phrases = _params === null || _params === void 0 ? void 0 : _params.phrases) !== null && _params$phrases !== void 0 ? _params$phrases : {};\n\n /* Set up callbacks that handle any events related to our peer object. */\n }\n}\n\n/* \r\nReferenced links:\r\nhttps://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676\r\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\r\nhttps://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]\r\n*/\n_Speaker = Speaker;\n/**\r\n * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.\r\n *\r\n * @param params - The parameters to be passed to the peer object.\r\n * @param Calibrator - The class that defines the calibration process.\r\n * @param CalibratorInstance\r\n * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).\r\n * @public\r\n * @example\r\n */\n_defineProperty(Speaker, \"startCalibration\", async function (params, CalibratorInstance) {\n let timeOut = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n await speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n if (params.displayUpdate) {\n params.displayUpdate.style.display = '';\n }\n\n // resolve when we have a result\n speaker.result = await speaker.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"testIIR\", async function (params, CalibratorInstance, IIR) {\n let timeOut = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n // resolve when we have a result\n speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"closeConnection\", () => {\n _Speaker.conn = null;\n console.log('Connection destroyed');\n});\n/* harmony default export */ __webpack_exports__[\"default\"] = (Speaker);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/speaker.js?");
|
|
162
162
|
|
|
163
163
|
/***/ }),
|
|
164
164
|
|
package/dist/main.js
CHANGED
|
@@ -114,7 +114,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core
|
|
|
114
114
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
115
115
|
|
|
116
116
|
"use strict";
|
|
117
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\n\n\n\n\n/**\r\n * @class Handles the listener's side of the connection. Responsible for getting access to user's microphone,\r\n * and initiating a call to the Speaker.\r\n * @augments AudioPeer\r\n */\nclass Listener extends _audioPeer__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n /**\r\n * Takes a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @example\r\n */\n constructor(params) {\n super(params);\n _defineProperty(this, \"onPeerOpen\", id => {\n this.displayUpdate('Listener - onPeerOpen');\n // Workaround for peer.reconnect deleting previous id\n\n if (id === null) {\n this.displayUpdate('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n this.join();\n });\n _defineProperty(this, \"onPeerConnection\", connection => {\n this.displayUpdate('Listener - onPeerConnection');\n // Disallow incoming connections\n connection.on('open', () => {\n connection.send('Sender does not accept incoming connections');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n });\n _defineProperty(this, \"onConnData\", data => {\n this.displayUpdate('Listener - onConnData');\n const hasSpeakerID = Object.prototype.hasOwnProperty.call(data, 'speakerPeerId');\n if (!hasSpeakerID) {\n this.displayUpdate('Error in parsing data received! Must set \"speakerPeerId\" property');\n throw new _peerErrors__WEBPACK_IMPORTED_MODULE_1__.MissingSpeakerIdError('Must set \"speakerPeerId\" property');\n } else {\n // this.conn.close();\n this.displayUpdate(this.speakerPeerId);\n this.speakerPeerId = data.speakerPeerId;\n const newParams = {\n speakerPeerId: this.speakerPeerId\n };\n /*\r\n FUTURE does this limit usable environments?\r\n ie does this work if internet is lost after initial page load?\r\n */\n window.location.search = this.queryStringFromObject(newParams); // Redirect to correctly constructed keypad page\n }\n });\n _defineProperty(this, \"join\", async () => {\n this.displayUpdate('Listener - join');\n /**\r\n * Create the connection between the two Peers.\r\n *\r\n * Sets up callbacks that handle any events related to the\r\n * connection and data received on it.\r\n */\n // Close old connection\n if (this.conn) {\n this.displayUpdate('Closing old connection');\n this.conn.close();\n }\n\n // Create connection to destination peer specified by the query param\n this.displayUpdate(\"Creating connection to: \".concat(this.speakerPeerId));\n this.conn = this.peer.connect(this.speakerPeerId, {\n reliable: true\n });\n this.displayUpdate('Created connection');\n this.conn.on('open', async () => {\n this.displayUpdate('Listener - conn open');\n await this.getDeviceInfo();\n // this.sendSamplingRate();\n await this.openAudioStream();\n });\n\n // Handle incoming data (messages only since this is the signal sender)\n this.conn.on('data', this.onConnData);\n this.conn.on('close', () => {\n console.log('Connection closed');\n });\n });\n _defineProperty(this, \"getMobileOS\", () => {\n var _navigator, _navigator2;\n const ua = navigator.userAgent;\n if (/android/i.test(ua)) {\n return 'Android';\n }\n if (/iPad|iPhone|iPod/.test(ua) || (((_navigator = navigator) === null || _navigator === void 0 || (_navigator = _navigator.userAgentData) === null || _navigator === void 0 ? void 0 : _navigator.platform) || ((_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.platform)) === 'MacIntel' && navigator.maxTouchPoints > 1) {\n return 'iOS';\n }\n return 'Other';\n });\n _defineProperty(this, \"sendSamplingRate\", sampleRate => {\n this.displayUpdate('Listener - sendSamplingRate');\n this.conn.send({\n name: 'samplingRate',\n payload: sampleRate\n });\n });\n _defineProperty(this, \"sendSampleSize\", sampleSize => {\n this.displayUpdate('Listener - sendSampleSize');\n this.conn.send({\n name: 'sampleSize',\n payload: sampleSize\n });\n });\n _defineProperty(this, \"sendFlags\", flags => {\n this.displayUpdate('Listener - sendFlags');\n this.conn.send({\n name: 'flags',\n payload: flags\n });\n });\n _defineProperty(this, \"getDeviceInfo\", async () => {\n const deviceInfo = {};\n try {\n fod.complete(function (data) {\n deviceInfo['IsMobile'] = data.device['ismobile'];\n deviceInfo['HardwareName'] = data.device['hardwarename'];\n deviceInfo['HardwareFamily'] = data.device['hardwarefamily'];\n deviceInfo['HardwareModel'] = data.device['hardwaremodel'];\n deviceInfo['OEM'] = data.device['oem'];\n deviceInfo['HardwareModelVariants'] = data.device['hardwaremodelvariants'];\n deviceInfo['DeviceId'] = data.device['deviceid'];\n deviceInfo['PlatformName'] = data.device['platformname'];\n deviceInfo['PlatformVersion'] = data.device['platformversion'];\n deviceInfo['DeviceType'] = data.device['devicetype'];\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n });\n } catch (error) {\n console.error('Error fetching or executing script:', error.message);\n }\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n deviceInfo['microphoneFromAPI'] = this.microphoneFromAPI;\n deviceInfo['microphoneDeviceId'] = this.microphoneDeviceId;\n deviceInfo['screenWidth'] = window.screen.width;\n deviceInfo['screenHeight'] = window.screen.height;\n console.log('deviceInfo Inside getDeviceInfo: ', deviceInfo);\n this.conn.send({\n name: 'deviceInfo',\n payload: deviceInfo\n });\n return deviceInfo;\n });\n _defineProperty(this, \"applyHQTrackConstraints\", async stream => {\n // Contraint the incoming audio to the sampling rate we want\n stream.getAudioTracks().forEach(track => {\n console.log(track, track.enabled);\n });\n const track = stream.getAudioTracks()[0];\n console.log(track);\n const capabilities = track.getCapabilities();\n this.displayUpdate(\"Listener Track Capabilities - \".concat(JSON.stringify(capabilities, undefined, 2)));\n const constraints = track.getConstraints();\n if (capabilities.echoCancellation) {\n constraints.echoCancellation = false;\n }\n if (capabilities.sampleRate) {\n constraints.sampleRate = this.calibrateSoundHz;\n }\n if (capabilities.sampleSize) {\n constraints.sampleSize = this.calibrateSoundSamplingDesiredBits;\n }\n if (capabilities.channelCount) {\n constraints.channelCount = 1;\n }\n this.displayUpdate(\"Listener Track Constraints - \".concat(JSON.stringify(constraints, undefined, 2)));\n\n // await the promise\n try {\n await track.applyConstraints(constraints);\n } catch (err) {\n console.error(err);\n this.displayUpdate(\"Error applying constraints to track: \".concat(err));\n }\n const settings = track.getSettings();\n this.displayUpdate(\"Listener Track Settings - \".concat(JSON.stringify(settings, undefined, 2)));\n return settings;\n });\n _defineProperty(this, \"getMediaDevicesAudioContraints\", async () => {\n const availableConstraints = navigator.mediaDevices.getSupportedConstraints();\n const contraints = {\n // ...(availableConstraints.echoCancellation && availableConstraints.echoCancellation == true\n // ? {echoCancellation: {exact: false}}\n // : {}),\n // ...(availableConstraints.sampleRate && availableConstraints.sampleRate == true\n // ? {sampleRate: {ideal: this.calibrateSoundHz}}\n // : {}),\n // ...(availableConstraints.sampleSize && availableConstraints.sampleSize == true\n // ? {sampleSize: {ideal: this.calibrateSoundSamplingDesiredBits}}\n // : {}),\n // ...(availableConstraints.channelCount && availableConstraints.channelCount == true\n // ? {channelCount: {exact: 1}}\n // : {}),\n autoGainControl: false,\n noiseSuppression: false,\n echoCancellation: false,\n channelCount: 1\n };\n if (this.microphoneDeviceId !== '') {\n contraints.deviceId = {\n exact: await this.getDeviceIdByLabel(this.microphoneDeviceId)\n };\n }\n console.log(contraints);\n return contraints;\n });\n _defineProperty(this, \"getDeviceIdByLabel\", async targetLabel => {\n try {\n //get permission to use audio first. (Returns empty labels on some computers if not done first)\n await navigator.mediaDevices.getUserMedia({\n audio: true\n });\n // Enumerate available media devices\n const devices = await navigator.mediaDevices.enumerateDevices();\n\n // Find the device with the matching label\n const matchingDevice = devices.find(device => device.kind === 'audioinput' && device.label === targetLabel);\n if (matchingDevice) {\n return matchingDevice.deviceId; // Return the deviceId if found\n } else {\n throw new Error(\"No audio input device found with label: \\\"\".concat(targetLabel, \"\\\"\"));\n }\n } catch (error) {\n console.error('Error finding device ID:', error);\n return null;\n }\n });\n _defineProperty(this, \"openAudioStream\", async () => {\n this.displayUpdate('Listener - openAudioStream');\n const mobileOS = this.getMobileOS();\n if (false) {}\n const constraints = await this.getMediaDevicesAudioContraints();\n console.log('Constraints right before getUserMedia:', constraints);\n navigator.mediaDevices.getUserMedia({\n audio: constraints,\n video: false\n //audio: {echoCancellation: false, noiseSuppression: false, autoGainControl: false, deviceId: {exact: await this.getDeviceIdByLabel(this.microphoneDeviceId) }},\n }).then(stream => {\n this.displayUpdate(\"Listener Track settings before applied constraints - \".concat(JSON.stringify(stream.getAudioTracks()[0].getSettings(), undefined, 2)));\n this.applyHQTrackConstraints(stream).then(settings => {\n console.log(settings);\n this.sendSamplingRate(settings.sampleRate);\n //let sampleSize = settings.sampleSize;\n let sampleSize = this.calibrateSoundSamplingDesiredBits;\n /*\r\n if (!sampleSize) {\r\n sampleSize = this.calibrateSoundSamplingDesiredBits;\r\n }\r\n */\n this.sendSampleSize(sampleSize);\n this.sendFlags({\n autoGainControl: settings.autoGainControl,\n noiseSuppression: settings.noiseSuppression,\n echoCancellation: settings.echoCancellation\n });\n this.peer.call(this.speakerPeerId, stream); // one-way call\n this.displayUpdate('Listener - openAudioStream');\n }).catch(err => {\n console.log(err);\n this.displayUpdate(\"Listener - Error in applyHQTrackConstraints - \".concat(JSON.stringify(err, undefined, 2)));\n });\n }).catch(err => {\n console.error(err);\n if (err.name === 'OverconstrainedError') {\n const constraint = err.constraint;\n const message = \"The constraint \\\"\".concat(constraint, \"\\\" cannot be satisfied by the selected microphone. Please adjust your calibration settings or choose a different microphone.\");\n this.displayUpdate(\"Listener - OverconstrainedError: \".concat(message));\n console.error(message);\n alert(\"Overconstrained Error: \".concat(message));\n }\n this.displayUpdate(\"Listener - Error in getUserMedia - \".concat(JSON.stringify(err, undefined, 2)));\n });\n });\n this.microphoneFromAPI = params.microphoneFromAPI ? params.microphoneFromAPI : '';\n this.microphoneDeviceId = params.microphoneDeviceId ? params.microphoneDeviceId : '';\n // this.deviceInfoFromUser = params.deviceInfoFromUser\n // ? params.deviceInfoFromUser\n // : {modelNumber: '', modelName: ''};\n this.startTime = Date.now();\n this.receiverPeerId = null;\n const urlParameters = this.parseURLSearchParams();\n this.calibrateSoundHz =\n // previous calibrateSoundHz\n urlParameters.hz !== null && urlParameters.hz !== undefined ? urlParameters.hz : 48000;\n this.calibrateSoundSamplingDesiredBits =\n // previous calibrateSoundSamplingDesiredBits\n urlParameters.bits !== null && urlParameters.bits !== undefined ? urlParameters.bits : 24;\n this.speakerPeerId = urlParameters.speakerPeerId;\n this.peer.on('open', this.onPeerOpen);\n this.peer.on('connection', this.onPeerConnection);\n this.peer.on('disconnected', this.onPeerDisconnected);\n this.peer.on('close', this.onPeerClose);\n this.peer.on('error', this.onPeerError);\n }\n}\n/* harmony default export */ __webpack_exports__[\"default\"] = (Listener);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/listener.js?");
|
|
117
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\n\n\n\n\n/**\r\n * @class Handles the listener's side of the connection. Responsible for getting access to user's microphone,\r\n * and initiating a call to the Speaker.\r\n * @augments AudioPeer\r\n */\nclass Listener extends _audioPeer__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n /**\r\n * Takes a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @example\r\n */\n constructor(params) {\n super(params);\n _defineProperty(this, \"onPeerOpen\", id => {\n this.displayUpdate('Listener - onPeerOpen');\n // Workaround for peer.reconnect deleting previous id\n try {\n if (id === null) {\n this.displayUpdate('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n } catch (error) {\n console.error('Error in onPeerOpen: ', error);\n }\n this.join();\n });\n _defineProperty(this, \"onPeerConnection\", connection => {\n this.displayUpdate('Listener - onPeerConnection');\n // Disallow incoming connections\n connection.on('open', () => {\n connection.send('Sender does not accept incoming connections');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n });\n _defineProperty(this, \"onConnData\", data => {\n this.displayUpdate('Listener - onConnData');\n const hasSpeakerID = Object.prototype.hasOwnProperty.call(data, 'speakerPeerId');\n if (!hasSpeakerID) {\n this.displayUpdate('Error in parsing data received! Must set \"speakerPeerId\" property');\n throw new _peerErrors__WEBPACK_IMPORTED_MODULE_1__.MissingSpeakerIdError('Must set \"speakerPeerId\" property');\n } else {\n // this.conn.close();\n this.displayUpdate(this.speakerPeerId);\n this.speakerPeerId = data.speakerPeerId;\n const newParams = {\n speakerPeerId: this.speakerPeerId\n };\n /*\r\n FUTURE does this limit usable environments?\r\n ie does this work if internet is lost after initial page load?\r\n */\n window.location.search = this.queryStringFromObject(newParams); // Redirect to correctly constructed keypad page\n }\n });\n _defineProperty(this, \"join\", async () => {\n this.displayUpdate('Listener - join');\n /**\r\n * Create the connection between the two Peers.\r\n *\r\n * Sets up callbacks that handle any events related to the\r\n * connection and data received on it.\r\n */\n // Close old connection\n if (this.conn) {\n this.displayUpdate('Closing old connection');\n this.conn.close();\n }\n\n // Create connection to destination peer specified by the query param\n this.displayUpdate(\"Creating connection to: \".concat(this.speakerPeerId));\n this.conn = this.peer.connect(this.speakerPeerId, {\n reliable: true\n });\n this.displayUpdate('Created connection');\n this.conn.on('open', async () => {\n this.displayUpdate('Listener - conn open');\n await this.getDeviceInfo();\n // this.sendSamplingRate();\n await this.openAudioStream();\n });\n\n // Handle incoming data (messages only since this is the signal sender)\n this.conn.on('data', this.onConnData);\n this.conn.on('close', () => {\n console.log('Connection closed');\n });\n });\n _defineProperty(this, \"getMobileOS\", () => {\n var _navigator, _navigator2;\n const ua = navigator.userAgent;\n if (/android/i.test(ua)) {\n return 'Android';\n }\n if (/iPad|iPhone|iPod/.test(ua) || (((_navigator = navigator) === null || _navigator === void 0 || (_navigator = _navigator.userAgentData) === null || _navigator === void 0 ? void 0 : _navigator.platform) || ((_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.platform)) === 'MacIntel' && navigator.maxTouchPoints > 1) {\n return 'iOS';\n }\n return 'Other';\n });\n _defineProperty(this, \"sendSamplingRate\", sampleRate => {\n this.displayUpdate('Listener - sendSamplingRate');\n this.conn.send({\n name: 'samplingRate',\n payload: sampleRate\n });\n });\n _defineProperty(this, \"sendSampleSize\", sampleSize => {\n this.displayUpdate('Listener - sendSampleSize');\n this.conn.send({\n name: 'sampleSize',\n payload: sampleSize\n });\n });\n _defineProperty(this, \"sendFlags\", flags => {\n this.displayUpdate('Listener - sendFlags');\n this.conn.send({\n name: 'flags',\n payload: flags\n });\n });\n _defineProperty(this, \"getDeviceInfo\", async () => {\n const deviceInfo = {};\n try {\n fod.complete(function (data) {\n deviceInfo['IsMobile'] = data.device['ismobile'];\n deviceInfo['HardwareName'] = data.device['hardwarename'];\n deviceInfo['HardwareFamily'] = data.device['hardwarefamily'];\n deviceInfo['HardwareModel'] = data.device['hardwaremodel'];\n deviceInfo['OEM'] = data.device['oem'];\n deviceInfo['HardwareModelVariants'] = data.device['hardwaremodelvariants'];\n deviceInfo['DeviceId'] = data.device['deviceid'];\n deviceInfo['PlatformName'] = data.device['platformname'];\n deviceInfo['PlatformVersion'] = data.device['platformversion'];\n deviceInfo['DeviceType'] = data.device['devicetype'];\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n });\n } catch (error) {\n console.error('Error fetching or executing script:', error.message);\n }\n // deviceInfo['deviceInfoFromUser'] = this.deviceInfoFromUser;\n deviceInfo['microphoneFromAPI'] = this.microphoneFromAPI;\n deviceInfo['microphoneDeviceId'] = this.microphoneDeviceId;\n deviceInfo['screenWidth'] = window.screen.width;\n deviceInfo['screenHeight'] = window.screen.height;\n console.log('deviceInfo Inside getDeviceInfo: ', deviceInfo);\n this.conn.send({\n name: 'deviceInfo',\n payload: deviceInfo\n });\n return deviceInfo;\n });\n _defineProperty(this, \"applyHQTrackConstraints\", async stream => {\n // Contraint the incoming audio to the sampling rate we want\n stream.getAudioTracks().forEach(track => {\n console.log(track, track.enabled);\n });\n const track = stream.getAudioTracks()[0];\n console.log(track);\n const capabilities = track.getCapabilities();\n this.displayUpdate(\"Listener Track Capabilities - \".concat(JSON.stringify(capabilities, undefined, 2)));\n const constraints = track.getConstraints();\n if (capabilities.echoCancellation) {\n constraints.echoCancellation = false;\n }\n if (capabilities.sampleRate) {\n constraints.sampleRate = this.calibrateSoundHz;\n }\n if (capabilities.sampleSize) {\n constraints.sampleSize = this.calibrateSoundSamplingDesiredBits;\n }\n if (capabilities.channelCount) {\n constraints.channelCount = 1;\n }\n this.displayUpdate(\"Listener Track Constraints - \".concat(JSON.stringify(constraints, undefined, 2)));\n\n // await the promise\n try {\n await track.applyConstraints(constraints);\n } catch (err) {\n console.error(err);\n this.displayUpdate(\"Error applying constraints to track: \".concat(err));\n }\n const settings = track.getSettings();\n this.displayUpdate(\"Listener Track Settings - \".concat(JSON.stringify(settings, undefined, 2)));\n return settings;\n });\n _defineProperty(this, \"getMediaDevicesAudioContraints\", async () => {\n const availableConstraints = navigator.mediaDevices.getSupportedConstraints();\n const contraints = {\n // ...(availableConstraints.echoCancellation && availableConstraints.echoCancellation == true\n // ? {echoCancellation: {exact: false}}\n // : {}),\n // ...(availableConstraints.sampleRate && availableConstraints.sampleRate == true\n // ? {sampleRate: {ideal: this.calibrateSoundHz}}\n // : {}),\n // ...(availableConstraints.sampleSize && availableConstraints.sampleSize == true\n // ? {sampleSize: {ideal: this.calibrateSoundSamplingDesiredBits}}\n // : {}),\n // ...(availableConstraints.channelCount && availableConstraints.channelCount == true\n // ? {channelCount: {exact: 1}}\n // : {}),\n autoGainControl: false,\n noiseSuppression: false,\n echoCancellation: false,\n channelCount: 1\n };\n if (this.microphoneDeviceId !== '') {\n contraints.deviceId = {\n exact: await this.getDeviceIdByLabel(this.microphoneDeviceId)\n };\n }\n console.log(contraints);\n return contraints;\n });\n _defineProperty(this, \"getDeviceIdByLabel\", async targetLabel => {\n try {\n //get permission to use audio first. (Returns empty labels on some computers if not done first)\n await navigator.mediaDevices.getUserMedia({\n audio: true\n });\n // Enumerate available media devices\n const devices = await navigator.mediaDevices.enumerateDevices();\n\n // Find the device with the matching label\n const matchingDevice = devices.find(device => device.kind === 'audioinput' && device.label === targetLabel);\n if (matchingDevice) {\n return matchingDevice.deviceId; // Return the deviceId if found\n } else {\n throw new Error(\"No audio input device found with label: \\\"\".concat(targetLabel, \"\\\"\"));\n }\n } catch (error) {\n console.error('Error finding device ID:', error);\n return null;\n }\n });\n _defineProperty(this, \"openAudioStream\", async () => {\n this.displayUpdate('Listener - openAudioStream');\n const mobileOS = this.getMobileOS();\n if (false) {}\n const constraints = await this.getMediaDevicesAudioContraints();\n console.log('Constraints right before getUserMedia:', constraints);\n navigator.mediaDevices.getUserMedia({\n audio: constraints,\n video: false\n //audio: {echoCancellation: false, noiseSuppression: false, autoGainControl: false, deviceId: {exact: await this.getDeviceIdByLabel(this.microphoneDeviceId) }},\n }).then(stream => {\n this.displayUpdate(\"Listener Track settings before applied constraints - \".concat(JSON.stringify(stream.getAudioTracks()[0].getSettings(), undefined, 2)));\n this.applyHQTrackConstraints(stream).then(settings => {\n console.log(settings);\n this.sendSamplingRate(settings.sampleRate);\n //let sampleSize = settings.sampleSize;\n let sampleSize = this.calibrateSoundSamplingDesiredBits;\n /*\r\n if (!sampleSize) {\r\n sampleSize = this.calibrateSoundSamplingDesiredBits;\r\n }\r\n */\n this.sendSampleSize(sampleSize);\n this.sendFlags({\n autoGainControl: settings.autoGainControl,\n noiseSuppression: settings.noiseSuppression,\n echoCancellation: settings.echoCancellation\n });\n this.peer.call(this.speakerPeerId, stream); // one-way call\n this.displayUpdate('Listener - openAudioStream');\n }).catch(err => {\n console.log(err);\n this.displayUpdate(\"Listener - Error in applyHQTrackConstraints - \".concat(JSON.stringify(err, undefined, 2)));\n });\n }).catch(err => {\n console.error(err);\n if (err.name === 'OverconstrainedError') {\n const constraint = err.constraint;\n const message = \"The constraint \\\"\".concat(constraint, \"\\\" cannot be satisfied by the selected microphone. Please adjust your calibration settings or choose a different microphone.\");\n this.displayUpdate(\"Listener - OverconstrainedError: \".concat(message));\n console.error(message);\n alert(\"Overconstrained Error: \".concat(message));\n }\n this.displayUpdate(\"Listener - Error in getUserMedia - \".concat(JSON.stringify(err, undefined, 2)));\n });\n });\n this.microphoneFromAPI = params.microphoneFromAPI ? params.microphoneFromAPI : '';\n this.microphoneDeviceId = params.microphoneDeviceId ? params.microphoneDeviceId : '';\n // this.deviceInfoFromUser = params.deviceInfoFromUser\n // ? params.deviceInfoFromUser\n // : {modelNumber: '', modelName: ''};\n this.startTime = Date.now();\n this.receiverPeerId = null;\n const urlParameters = this.parseURLSearchParams();\n this.calibrateSoundHz =\n // previous calibrateSoundHz\n urlParameters.hz !== null && urlParameters.hz !== undefined ? urlParameters.hz : 48000;\n this.calibrateSoundSamplingDesiredBits =\n // previous calibrateSoundSamplingDesiredBits\n urlParameters.bits !== null && urlParameters.bits !== undefined ? urlParameters.bits : 24;\n this.speakerPeerId = urlParameters.speakerPeerId;\n this.peer.on('open', this.onPeerOpen);\n this.peer.on('connection', this.onPeerConnection);\n this.peer.on('disconnected', this.onPeerDisconnected);\n this.peer.on('close', this.onPeerClose);\n this.peer.on('error', this.onPeerError);\n }\n}\n/* harmony default export */ __webpack_exports__[\"default\"] = (Listener);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/listener.js?");
|
|
118
118
|
|
|
119
119
|
/***/ }),
|
|
120
120
|
|
|
@@ -136,7 +136,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
|
|
|
136
136
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
137
137
|
|
|
138
138
|
"use strict";
|
|
139
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.array-buffer.slice.js */ \"./node_modules/core-js/modules/es.array-buffer.slice.js\");\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ \"./node_modules/core-js/modules/es.string.replace.js\");\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.typed-array.uint8-array.js */ \"./node_modules/core-js/modules/es.typed-array.uint8-array.js\");\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.typed-array.fill.js */ \"./node_modules/core-js/modules/es.typed-array.fill.js\");\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.typed-array.set.js */ \"./node_modules/core-js/modules/es.typed-array.set.js\");\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.typed-array.sort.js */ \"./node_modules/core-js/modules/es.typed-array.sort.js\");\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/web.dom-collections.iterator.js */ \"./node_modules/core-js/modules/web.dom-collections.iterator.js\");\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__);\n/* harmony import */ var qrcode__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! qrcode */ \"./node_modules/qrcode/lib/browser.js\");\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils */ \"./src/utils.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\n/* harmony import */ var peerjs__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! peerjs */ \"./node_modules/peerjs/dist/bundler.mjs\");\nvar _Speaker;\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }\nfunction _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); }\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nfunction _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }\nfunction _assertClassBrand(e, t, n) { if (\"function\" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError(\"Private element is not present on this object\"); }\n\n\n\n\n\n\n//import {phrases} from '../../dist/example/i18n';\n\n/**\r\n * @class Handles the speaker's side of the connection. Responsible for initiating the connection,\r\n * rendering the QRCode, and answering the call.\r\n * @augments AudioPeer\r\n */\nvar _showQRCode = /*#__PURE__*/new WeakMap();\nvar _showSpinner = /*#__PURE__*/new WeakMap();\nvar _removeUIElems = /*#__PURE__*/new WeakMap();\nvar _onPeerOpen = /*#__PURE__*/new WeakMap();\nvar _onPeerConnection = /*#__PURE__*/new WeakMap();\nvar _onPeerDisconnected = /*#__PURE__*/new WeakMap();\nvar _onPeerError = /*#__PURE__*/new WeakMap();\nvar _onIncomingData = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Speaker extends _audioPeer__WEBPACK_IMPORTED_MODULE_8__[\"default\"] {\n /**\r\n * Takes the url of the current site and a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.\r\n * @param CalibratorInstance\r\n * @example\r\n */\n constructor(_params, _CalibratorInstance) {\n var _params$language, _params$debug, _params$isSmartPhone, _params$calibrateSoun, _params$calibrateSoun2, _params$instructionDi, _params$soundSubtitle, _params$timeToCalibra, _params$soundMessageI, _params$titleDisplayI, _params$timeToCalibra2, _params$isParticipant, _params$isLoudspeaker, _params$micrpohoneIdF, _params$buttonsContai, _params$phrases;\n super(_params);\n _defineProperty(this, \"uri\", '');\n _defineProperty(this, \"qrImage\", void 0);\n _defineProperty(this, \"shortURL\", void 0);\n _defineProperty(this, \"initPeer\", async () => {\n const id = await this.generateTimeBasedPeerID();\n this.peer = new peerjs__WEBPACK_IMPORTED_MODULE_11__[\"default\"](id, {\n secure: true,\n host: 'easyeyes-peer-server.herokuapp.com',\n port: 443,\n config: {\n iceServers: [{\n urls: 'stun:stun.relay.metered.ca:80'\n }, {\n urls: 'turn:global.relay.metered.ca:80',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:80?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:443',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turns:global.relay.metered.ca:443?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }]\n }\n });\n this.peer.on('open', _classPrivateFieldGet(_onPeerOpen, this));\n this.peer.on('connection', _classPrivateFieldGet(_onPeerConnection, this));\n this.peer.on('close', this.onPeerClose);\n this.peer.on('disconnected', _classPrivateFieldGet(_onPeerDisconnected, this));\n this.peer.on('error', _classPrivateFieldGet(_onPeerError, this));\n });\n _defineProperty(this, \"generateTimeBasedPeerID\", async () => {\n const now = new Date().getTime();\n const randomBuffer = new Uint8Array(10);\n crypto.getRandomValues(randomBuffer);\n const randomPart = Array.from(randomBuffer).map(b => b.toString(36)).join('');\n const toHash = \"\".concat(now, \"-\").concat(randomPart);\n const encoder = new TextEncoder();\n const data = encoder.encode(toHash);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const hashArray = Array.from(new Uint8Array(hash)); // Convert buffer to byte array\n const hashString = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n const shortHash = hashString.substring(0, 12); // Use more of the hash for a longer ID\n // return shortHash; // Consider converting this to Base62\n return this.encodeBase62(parseInt(shortHash, 16));\n });\n _defineProperty(this, \"encodeBase62\", num => {\n const base = 36;\n const characters = '0123456789abcdefghijklmnopqrstuvwxyz';\n let result = '';\n while (num > 0) {\n result = characters[num % base] + result;\n num = Math.floor(num / base);\n }\n return result;\n });\n /**\r\n * Called after the peer conncection has been opened.\r\n * Generates a QR code for the connection and displays it.\r\n *\r\n * @private\r\n * @example\r\n */\n\n _classPrivateFieldInitSpec(this, _showQRCode, async () => {\n // Get query string, the URL parameters to specify a Listener\n const queryStringParameters = {\n speakerPeerId: this.peer.id,\n sp: this.isSmartPhone,\n hz: this.calibrateSoundHz,\n bits: this.calibrateSoundSamplingDesiredBits,\n lang: this.language,\n deviceId: this.deviceId\n };\n const queryString = this.queryStringFromObject(queryStringParameters);\n this.uri = this.siteUrl + queryString;\n if (this.isSmartPhone) {\n // if (true) { // test smartphone QR\n // Display QR code for the participant to scan\n const qrCanvas = document.createElement('canvas');\n qrCanvas.setAttribute('id', 'qrCanvas');\n qrcode__WEBPACK_IMPORTED_MODULE_7__.toCanvas(qrCanvas, this.uri, error => {\n if (error) console.error(error);\n });\n const explanation = document.createElement('h2');\n explanation.id = 'skipQRExplanation';\n explanation.style = \"\\n user-select: text;\\n margin-top: 9px;\\n font-size: 1.1rem;\\n \";\n // Define the URL and options for the request\n const url = 'https://api.short.io/links/public';\n const options = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: 'pk_fysLKGj3legZz4XZ'\n },\n body: JSON.stringify({\n domain: 'listeners.link',\n // Ensure this domain is valid for your account\n originalURL: this.uri\n })\n };\n\n // Make the request using fetch\n await fetch(url, options).then(response => {\n if (!response.ok) {\n throw new Error(\"HTTP error! Status: \".concat(response.status));\n }\n return response.json(); // Parse the JSON response\n }).then(data => {\n explanation.innerHTML = (0,_utils__WEBPACK_IMPORTED_MODULE_9__.formatLineBreak)(this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language].replace('xxx', \"<b style=\\\"user-select: text\\\">\".concat(data.shortURL, \"</b>\")).replace('XXX', \"<b style=\\\"user-select: text\\\">\".concat(data.shortURL, \"</b>\")), this.phrases.RC_checkInternetConnection[this.language]);\n const checkConnection = document.createElement('a');\n checkConnection.id = 'check-connection';\n checkConnection.href = '#';\n checkConnection.innerHTML = \"check the phone's internet connection\";\n const lang = this.language;\n const phrases = this.phrases;\n checkConnection.addEventListener('click', function (event) {\n console.log('clicked');\n event.preventDefault(); // Prevent the default link action\n (0,_utils__WEBPACK_IMPORTED_MODULE_9__.createAndShowPopup)(lang, phrases);\n });\n explanation.querySelector('a#check-connection').replaceWith(checkConnection);\n }).catch(error => {\n console.error('Error:', error.message); // Handle errors\n });\n const qrImage = new Image(400, 400);\n qrImage.setAttribute('id', 'compatibilityCheckQRImage');\n qrImage.style.zIndex = Infinity;\n qrImage.style.width = 400;\n qrImage.style.height = 400;\n qrImage.style.aspectRatio = 1;\n qrImage.src = qrCanvas.toDataURL();\n qrImage.style.maxHeight = '150px';\n qrImage.style.maxWidth = '150px';\n this.qrImage = qrImage;\n const container = document.createElement('div');\n container.style.display = 'flex';\n container.style.justifyContent = 'space-between';\n container.style.alignItems = 'top';\n container.id = 'skipQRContainer';\n container.appendChild(qrImage);\n container.appendChild(explanation);\n container.appendChild(this.buttonsContainer);\n const qrContainer = document.createElement('div');\n qrContainer.appendChild(container);\n document.getElementById(this.targetElement).appendChild(qrContainer);\n } else {\n // show the link to the user\n // If specified HTML Id is available, show QR code there\n if (document.getElementById(this.targetElement)) {\n // const linkTag = document.createElement('a');\n // linkTag.setAttribute('href', uri);\n // linkTag.innerHTML = 'Click here to start the calibration';\n // linkTag.target = '_blank';\n // document.getElementById(this.targetElement).appendChild(linkTag);\n // document.getElementById(this.targetElement).appendChild(qrCanvas);\n\n const proceedButton = document.createElement('button');\n proceedButton.setAttribute('id', 'calibrationProceedButton');\n proceedButton.setAttribute('class', 'btn btn-success');\n proceedButton.innerHTML = this.phrases.T_proceed[this.language];\n proceedButton.onclick = () => {\n // open the link in a new tab\n window.open(this.uri, '_blank');\n // remove the button\n document.getElementById('calibrationProceedButton').remove();\n };\n document.getElementById(this.targetElement).appendChild(proceedButton);\n }\n }\n // or just print it to console\n console.log('TEST: Peer reachable at: ', this.uri);\n });\n _classPrivateFieldInitSpec(this, _showSpinner, () => {\n const spinner = document.createElement('div');\n spinner.className = 'spinner-border ml-auto';\n spinner.role = 'status';\n spinner.ariaHidden = 'true';\n spinner.style.marginTop = '0.8rem';\n document.getElementById(this.targetElement).appendChild(spinner);\n\n // clear instructionDisplay\n const soundMessage = document.getElementById(this.soundMessageId);\n soundMessage.innerHTML = '';\n soundMessage.style.display = 'none';\n const instructionDisplay = document.getElementById(this.instructionDisplayId);\n const background = document.getElementById('background'); // todo: get background id from params\n const subtitle = document.getElementById(this.soundSubtitleId);\n if (subtitle) {\n subtitle.innerHTML = '';\n }\n if (instructionDisplay) {\n instructionDisplay.innerHTML = '';\n instructionDisplay.style.whiteSpace = 'nowrap';\n instructionDisplay.style.fontWeight = 'bold';\n instructionDisplay.style.width = 'fit-content';\n instructionDisplay.innerHTML = this.phrases.RC_soundRecording[this.language];\n let fontSize = 100;\n instructionDisplay.style.fontSize = fontSize + 'px';\n while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {\n fontSize--;\n instructionDisplay.style.fontSize = fontSize + 'px';\n }\n // const p = document.createElement('p');\n // // font size\n // p.style.fontSize = '1.1rem';\n // p.style.fontWeight = 'normal';\n // p.style.paddingTop = '20px';\n // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];\n // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n // instructionDisplay.appendChild(p);\n }\n const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);\n if (timeToCalibrateDisplay) {\n const timeToCalibrateText = this.phrases.RC_howLongToCalibrate[this.language];\n timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n timeToCalibrateDisplay.style.fontWeight = 'normal';\n timeToCalibrateDisplay.style.fontSize = '1rem';\n // timeToCalibrateDisplay.style.paddingTop = '20px';\n }\n\n // Update title - titleDisplayId\n const titleDisplay = document.getElementById(this.titleDisplayId);\n if (titleDisplay) {\n // if (this.isParticipant) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n // } else if (this.isSmartPhone) {\n // if (this.isLoudspeakerCalibration) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n if (this.isLoudspeakerCalibration) {\n if (this.isParticipant) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n } else if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');\n }\n } else {\n if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n }\n }\n }\n });\n _classPrivateFieldInitSpec(this, _removeUIElems, () => {\n const parent = document.getElementById(this.targetElement);\n while (parent.firstChild) {\n parent.firstChild.remove();\n }\n });\n /**\r\n * Called when the peer connection is opened.\r\n * Saves the peer id and calls the QR code generator.\r\n *\r\n * @param peerId - The peer id of the peer connection.\r\n * @param id\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerOpen, id => {\n // Workaround for peer.reconnect deleting previous id\n if (id === null) {\n console.error('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n if (id !== this.peer.id) {\n console.warn('DEBUG Check you assumption that id === this.peer.id');\n }\n _classPrivateFieldGet(_showQRCode, this).call(this);\n });\n /**\r\n * Called when the peer connection is established.\r\n * Enforces a single connection.\r\n *\r\n * @param connection - The connection object.\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerConnection, connection => {\n // Allow only a single connection\n if (this.conn && this.conn.open) {\n connection.on('open', () => {\n connection.send('Already connected to another client');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n return;\n }\n this.conn = connection;\n console.log('Connected to: ', this.conn.peer);\n _classPrivateFieldGet(_ready, this).call(this);\n });\n /**\r\n * Called when the peer connection is closed.\r\n *\r\n * @private\r\n * @example\r\n */\n _defineProperty(this, \"onPeerClose\", () => {\n this.conn = null;\n console.log('Connection destroyed');\n });\n /**\r\n * Called when the peer connection is disconnected.\r\n * Attempts to reconnect.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerDisconnected, () => {\n console.log('Connection lost. Please reconnect');\n\n // Workaround for peer.reconnect deleting previous id\n this.peer.id = this.lastPeerId;\n // eslint-disable-next-line no-underscore-dangle\n this.peer._lastServerId = this.lastPeerId;\n this.peer.reconnect();\n });\n /**\r\n * Called when the peer connection encounters an error.\r\n *\r\n * @param error\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerError, error => {\n // TODO: check if this function is needed or not\n console.error(error);\n });\n /**\r\n * Called when data is received from the peer connection.\r\n *\r\n * @param data\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onIncomingData, data => {\n // enforce object type\n if (!Object.prototype.hasOwnProperty.call(data, 'name') || !Object.prototype.hasOwnProperty.call(data, 'payload')) {\n console.error('Received malformed data: ', data);\n return;\n }\n switch (data.name) {\n case 'samplingRate':\n this.ac.setSamplingRates(data.payload);\n break;\n case 'sampleSize':\n this.ac.setSampleSize(data.payload);\n break;\n case 'deviceType':\n this.ac.setDeviceType(data.payload);\n break;\n case 'deviceName':\n this.ac.setDeviceName(data.payload);\n break;\n case 'flags':\n //this.ac.setDeviceName(data.payload);\n console.log('FLAGS');\n console.log(data.payload);\n this.ac.setFlags(data.payload);\n break;\n case 'deviceInfo':\n this.ac.setDeviceInfo(data.payload);\n console.log('Received device info from listener: ', data.payload);\n break;\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.UnsupportedDeviceError.name:\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.MissingSpeakerIdError.name:\n throw data.payload;\n break;\n default:\n break;\n }\n });\n /**\r\n * Called when the peer connection is #ready.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _ready, () => {\n // Perform callback with data\n this.conn.on('data', _classPrivateFieldGet(_onIncomingData, this));\n this.conn.on('close', () => {\n console.log('Connection reset<br>Awaiting connection...');\n this.conn = null;\n });\n });\n /** .\r\n * .\r\n * .\r\n * Debug method for downloading the recorded audio\r\n *\r\n * @public\r\n * @example\r\n */\n _defineProperty(this, \"downloadData\", () => {\n this.ac.downloadData();\n });\n _defineProperty(this, \"repeatCalibration\", async (params, stream, CalibratorInstance) => {\n this.ac = CalibratorInstance;\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n _classPrivateFieldGet(_showSpinner, this).call(this);\n console.log('This is a repeat');\n // wrap the calibration process in a promise so we can await it\n return new Promise(async (resolve, reject) => {\n const result = await this.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n resolve(result);\n });\n });\n this.language = (_params$language = _params === null || _params === void 0 ? void 0 : _params.language) !== null && _params$language !== void 0 ? _params$language : 'en-US';\n this.siteUrl += '/listener?';\n this.ac = _CalibratorInstance;\n this.result = null;\n this.debug = (_params$debug = _params === null || _params === void 0 ? void 0 : _params.debug) !== null && _params$debug !== void 0 ? _params$debug : false;\n this.isSmartPhone = (_params$isSmartPhone = _params === null || _params === void 0 ? void 0 : _params.isSmartPhone) !== null && _params$isSmartPhone !== void 0 ? _params$isSmartPhone : false;\n this.calibrateSoundHz = (_params$calibrateSoun = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundHz) !== null && _params$calibrateSoun !== void 0 ? _params$calibrateSoun : 48000;\n this.calibrateSoundSamplingDesiredBits = (_params$calibrateSoun2 = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundSamplingDesiredBits) !== null && _params$calibrateSoun2 !== void 0 ? _params$calibrateSoun2 : 24;\n this.instructionDisplayId = (_params$instructionDi = _params === null || _params === void 0 ? void 0 : _params.instructionDisplayId) !== null && _params$instructionDi !== void 0 ? _params$instructionDi : '';\n this.soundSubtitleId = (_params$soundSubtitle = _params === null || _params === void 0 ? void 0 : _params.soundSubtitleId) !== null && _params$soundSubtitle !== void 0 ? _params$soundSubtitle : '';\n this.timeToCalibrateDisplay = (_params$timeToCalibra = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrateId) !== null && _params$timeToCalibra !== void 0 ? _params$timeToCalibra : '';\n this.soundMessageId = (_params$soundMessageI = _params === null || _params === void 0 ? void 0 : _params.soundMessageId) !== null && _params$soundMessageI !== void 0 ? _params$soundMessageI : '';\n this.titleDisplayId = (_params$titleDisplayI = _params === null || _params === void 0 ? void 0 : _params.titleDisplayId) !== null && _params$titleDisplayI !== void 0 ? _params$titleDisplayI : '';\n this.timeToCalibrate = (_params$timeToCalibra2 = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrate) !== null && _params$timeToCalibra2 !== void 0 ? _params$timeToCalibra2 : 10;\n this.isParticipant = (_params$isParticipant = _params === null || _params === void 0 ? void 0 : _params.isParticipant) !== null && _params$isParticipant !== void 0 ? _params$isParticipant : false;\n this.isLoudspeakerCalibration = (_params$isLoudspeaker = _params === null || _params === void 0 ? void 0 : _params.isLoudspeakerCalibration) !== null && _params$isLoudspeaker !== void 0 ? _params$isLoudspeaker : false;\n this.deviceId = (_params$micrpohoneIdF = _params === null || _params === void 0 ? void 0 : _params.micrpohoneIdFromWebAudioApi) !== null && _params$micrpohoneIdF !== void 0 ? _params$micrpohoneIdF : '';\n this.buttonsContainer = (_params$buttonsContai = _params === null || _params === void 0 ? void 0 : _params.buttonsContainer) !== null && _params$buttonsContai !== void 0 ? _params$buttonsContai : document.createElement('div');\n this.phrases = (_params$phrases = _params === null || _params === void 0 ? void 0 : _params.phrases) !== null && _params$phrases !== void 0 ? _params$phrases : {};\n\n /* Set up callbacks that handle any events related to our peer object. */\n }\n}\n\n/* \r\nReferenced links:\r\nhttps://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676\r\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\r\nhttps://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]\r\n*/\n_Speaker = Speaker;\n/**\r\n * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.\r\n *\r\n * @param params - The parameters to be passed to the peer object.\r\n * @param Calibrator - The class that defines the calibration process.\r\n * @param CalibratorInstance\r\n * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).\r\n * @public\r\n * @example\r\n */\n_defineProperty(Speaker, \"startCalibration\", async function (params, CalibratorInstance) {\n let timeOut = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n await speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n if (params.displayUpdate) {\n params.displayUpdate.style.display = '';\n }\n\n // resolve when we have a result\n speaker.result = await speaker.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"testIIR\", async function (params, CalibratorInstance, IIR) {\n let timeOut = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n // resolve when we have a result\n speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"closeConnection\", () => {\n _Speaker.conn = null;\n console.log('Connection destroyed');\n});\n/* harmony default export */ __webpack_exports__[\"default\"] = (Speaker);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/speaker.js?");
|
|
139
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! core-js/modules/es.array-buffer.slice.js */ \"./node_modules/core-js/modules/es.array-buffer.slice.js\");\n/* harmony import */ var core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_array_buffer_slice_js__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core-js/modules/es.string.replace.js */ \"./node_modules/core-js/modules/es.string.replace.js\");\n/* harmony import */ var core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_string_replace_js__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! core-js/modules/es.typed-array.uint8-array.js */ \"./node_modules/core-js/modules/es.typed-array.uint8-array.js\");\n/* harmony import */ var core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_uint8_array_js__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! core-js/modules/es.typed-array.fill.js */ \"./node_modules/core-js/modules/es.typed-array.fill.js\");\n/* harmony import */ var core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_fill_js__WEBPACK_IMPORTED_MODULE_3__);\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! core-js/modules/es.typed-array.set.js */ \"./node_modules/core-js/modules/es.typed-array.set.js\");\n/* harmony import */ var core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_set_js__WEBPACK_IMPORTED_MODULE_4__);\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! core-js/modules/es.typed-array.sort.js */ \"./node_modules/core-js/modules/es.typed-array.sort.js\");\n/* harmony import */ var core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_es_typed_array_sort_js__WEBPACK_IMPORTED_MODULE_5__);\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! core-js/modules/web.dom-collections.iterator.js */ \"./node_modules/core-js/modules/web.dom-collections.iterator.js\");\n/* harmony import */ var core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(core_js_modules_web_dom_collections_iterator_js__WEBPACK_IMPORTED_MODULE_6__);\n/* harmony import */ var qrcode__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! qrcode */ \"./node_modules/qrcode/lib/browser.js\");\n/* harmony import */ var _audioPeer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./audioPeer */ \"./src/peer-connection/audioPeer.js\");\n/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils */ \"./src/utils.js\");\n/* harmony import */ var _peerErrors__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./peerErrors */ \"./src/peer-connection/peerErrors.js\");\n/* harmony import */ var peerjs__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! peerjs */ \"./node_modules/peerjs/dist/bundler.mjs\");\nvar _Speaker;\n\n\n\n\n\n\n\nfunction _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }\nfunction _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError(\"Cannot initialize the same private elements twice on an object\"); }\nfunction _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }\nfunction _toPropertyKey(t) { var i = _toPrimitive(t, \"string\"); return \"symbol\" == typeof i ? i : i + \"\"; }\nfunction _toPrimitive(t, r) { if (\"object\" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || \"default\"); if (\"object\" != typeof i) return i; throw new TypeError(\"@@toPrimitive must return a primitive value.\"); } return (\"string\" === r ? String : Number)(t); }\nfunction _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }\nfunction _assertClassBrand(e, t, n) { if (\"function\" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError(\"Private element is not present on this object\"); }\n\n\n\n\n\n\n//import {phrases} from '../../dist/example/i18n';\n\n/**\r\n * @class Handles the speaker's side of the connection. Responsible for initiating the connection,\r\n * rendering the QRCode, and answering the call.\r\n * @augments AudioPeer\r\n */\nvar _showQRCode = /*#__PURE__*/new WeakMap();\nvar _showSpinner = /*#__PURE__*/new WeakMap();\nvar _removeUIElems = /*#__PURE__*/new WeakMap();\nvar _onPeerOpen = /*#__PURE__*/new WeakMap();\nvar _onPeerConnection = /*#__PURE__*/new WeakMap();\nvar _onPeerDisconnected = /*#__PURE__*/new WeakMap();\nvar _onPeerError = /*#__PURE__*/new WeakMap();\nvar _onIncomingData = /*#__PURE__*/new WeakMap();\nvar _ready = /*#__PURE__*/new WeakMap();\nclass Speaker extends _audioPeer__WEBPACK_IMPORTED_MODULE_8__[\"default\"] {\n /**\r\n * Takes the url of the current site and a target element where html elements will be appended.\r\n *\r\n * @param params - See type definition for initParameters.\r\n * @param Calibrator - An instance of the AudioCalibrator class, should not use AudioCalibrator directly, instead use an extended class available in /tasks/.\r\n * @param CalibratorInstance\r\n * @example\r\n */\n constructor(_params, _CalibratorInstance) {\n var _params$language, _params$debug, _params$isSmartPhone, _params$calibrateSoun, _params$calibrateSoun2, _params$instructionDi, _params$soundSubtitle, _params$timeToCalibra, _params$soundMessageI, _params$titleDisplayI, _params$timeToCalibra2, _params$isParticipant, _params$isLoudspeaker, _params$micrpohoneIdF, _params$buttonsContai, _params$phrases;\n super(_params);\n _defineProperty(this, \"uri\", '');\n _defineProperty(this, \"qrImage\", void 0);\n _defineProperty(this, \"shortURL\", void 0);\n _defineProperty(this, \"initPeer\", async () => {\n const id = await this.generateTimeBasedPeerID();\n this.peer = new peerjs__WEBPACK_IMPORTED_MODULE_11__[\"default\"](id, {\n secure: true,\n host: 'easyeyes-peer-server.herokuapp.com',\n port: 443,\n config: {\n iceServers: [{\n urls: 'stun:stun.relay.metered.ca:80'\n }, {\n urls: 'turn:global.relay.metered.ca:80',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:80?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turn:global.relay.metered.ca:443',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }, {\n urls: 'turns:global.relay.metered.ca:443?transport=tcp',\n username: 'de884cfc34189cdf1a5dd616',\n credential: 'IcOpouU9/TYBmpHU'\n }]\n }\n });\n this.peer.on('open', _classPrivateFieldGet(_onPeerOpen, this));\n this.peer.on('connection', _classPrivateFieldGet(_onPeerConnection, this));\n this.peer.on('close', this.onPeerClose);\n this.peer.on('disconnected', _classPrivateFieldGet(_onPeerDisconnected, this));\n this.peer.on('error', _classPrivateFieldGet(_onPeerError, this));\n });\n _defineProperty(this, \"generateTimeBasedPeerID\", async () => {\n const now = new Date().getTime();\n const randomBuffer = new Uint8Array(10);\n crypto.getRandomValues(randomBuffer);\n const randomPart = Array.from(randomBuffer).map(b => b.toString(36)).join('');\n const toHash = \"\".concat(now, \"-\").concat(randomPart);\n const encoder = new TextEncoder();\n const data = encoder.encode(toHash);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const hashArray = Array.from(new Uint8Array(hash)); // Convert buffer to byte array\n const hashString = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n const shortHash = hashString.substring(0, 12); // Use more of the hash for a longer ID\n // return shortHash; // Consider converting this to Base62\n return this.encodeBase62(parseInt(shortHash, 16));\n });\n _defineProperty(this, \"encodeBase62\", num => {\n const base = 36;\n const characters = '0123456789abcdefghijklmnopqrstuvwxyz';\n let result = '';\n while (num > 0) {\n result = characters[num % base] + result;\n num = Math.floor(num / base);\n }\n return result;\n });\n /**\r\n * Called after the peer conncection has been opened.\r\n * Generates a QR code for the connection and displays it.\r\n *\r\n * @private\r\n * @example\r\n */\n\n _classPrivateFieldInitSpec(this, _showQRCode, async () => {\n const queryStringParameters = {\n speakerPeerId: this.peer.id,\n sp: this.isSmartPhone,\n hz: this.calibrateSoundHz,\n bits: this.calibrateSoundSamplingDesiredBits,\n lang: this.language,\n deviceId: this.deviceId\n };\n const queryString = this.queryStringFromObject(queryStringParameters);\n this.uri = this.siteUrl + queryString;\n if (this.isSmartPhone) {\n // Generate QR code\n const qrCanvas = document.createElement('canvas');\n qrCanvas.setAttribute('id', 'qrCanvas');\n qrcode__WEBPACK_IMPORTED_MODULE_7__.toCanvas(qrCanvas, this.uri, error => {\n if (error) console.error(error);\n });\n\n // Create QR image\n const qrImage = new Image();\n qrImage.setAttribute('id', 'compatibilityCheckQRImage');\n qrImage.style.zIndex = Infinity;\n qrImage.style.height = '150px';\n qrImage.style.width = '150px';\n qrImage.style.margin = '-10px';\n qrImage.style.aspectRatio = 1;\n qrImage.src = qrCanvas.toDataURL();\n this.qrImage = qrImage;\n\n // Get shortened URL\n let shortURL = '';\n try {\n const response = await fetch('https://api.short.io/links/public', {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: 'pk_fysLKGj3legZz4XZ'\n },\n body: JSON.stringify({\n domain: 'listeners.link',\n originalURL: this.uri\n })\n });\n if (!response.ok) {\n throw new Error(\"HTTP error! Status: \".concat(response.status));\n }\n const data = await response.json();\n shortURL = data.shortURL;\n } catch (error) {\n console.error('Error:', error.message);\n }\n\n // Main container with 3 columns\n const container = document.createElement('div');\n container.style.display = 'flex';\n container.style.alignItems = 'flex-start';\n container.style.paddingTop = '0';\n container.id = 'skipQRContainer';\n\n // Column 1: QR Code\n const qrColumn = document.createElement('div');\n qrColumn.style.flex = '0 0 auto';\n qrColumn.appendChild(qrImage);\n\n // Column 2: Explanation Text\n const textColumn = document.createElement('div');\n textColumn.style.flex = '1';\n textColumn.style.padding = '0 20px';\n textColumn.style.maxWidth = '560px';\n const explanation = document.createElement('h2');\n explanation.style.fontSize = '1.1rem';\n explanation.id = 'skipQRExplanation';\n explanation.style.margin = '0';\n explanation.style.textAlign = 'left';\n explanation.innerHTML = (0,_utils__WEBPACK_IMPORTED_MODULE_9__.formatLineBreak)(this.phrases.RC_skipQR_ExplanationWithoutPreferNot[this.language].replace('xxx', \"<b style=\\\"user-select: text\\\">\".concat(shortURL, \"</b>\")).replace('XXX', \"<b style=\\\"user-select: text\\\">\".concat(shortURL, \"</b>\")), this.phrases.RC_checkInternetConnection[this.language]);\n const checkConnection = document.createElement('a');\n checkConnection.id = 'check-connection';\n checkConnection.href = '#';\n checkConnection.innerHTML = \"check the phone's internet connection\";\n checkConnection.addEventListener('click', function (event) {\n event.preventDefault();\n (0,_utils__WEBPACK_IMPORTED_MODULE_9__.createAndShowPopup)(this.language, this.phrases);\n });\n explanation.querySelector('a#check-connection').replaceWith(checkConnection);\n textColumn.appendChild(explanation);\n\n // Column 3: Buttons\n const buttonColumn = document.createElement('div');\n buttonColumn.style.display = 'flex';\n buttonColumn.style.flexDirection = 'column';\n buttonColumn.style.gap = '10px';\n buttonColumn.style.flex = '0 0 auto';\n buttonColumn.style.alignItems = 'flex-end';\n buttonColumn.appendChild(this.buttonsContainer);\n\n // Assemble the columns\n container.appendChild(qrColumn);\n container.appendChild(textColumn);\n container.appendChild(buttonColumn);\n document.getElementById(this.targetElement).appendChild(container);\n } else {\n // show the link to the user\n // If specified HTML Id is available, show QR code there\n if (document.getElementById(this.targetElement)) {\n // const linkTag = document.createElement('a');\n // linkTag.setAttribute('href', uri);\n // linkTag.innerHTML = 'Click here to start the calibration';\n // linkTag.target = '_blank';\n // document.getElementById(this.targetElement).appendChild(linkTag);\n // document.getElementById(this.targetElement).appendChild(qrCanvas);\n\n const proceedButton = document.createElement('button');\n proceedButton.setAttribute('id', 'calibrationProceedButton');\n proceedButton.setAttribute('class', 'btn btn-success');\n proceedButton.innerHTML = this.phrases.T_proceed[this.language];\n proceedButton.onclick = () => {\n // open the link in a new tab\n window.open(this.uri, '_blank');\n // remove the button\n document.getElementById('calibrationProceedButton').remove();\n };\n document.getElementById(this.targetElement).appendChild(proceedButton);\n }\n }\n // or just print it to console\n console.log('TEST: Peer reachable at: ', this.uri);\n });\n _classPrivateFieldInitSpec(this, _showSpinner, () => {\n const spinner = document.createElement('div');\n spinner.className = 'spinner-border ml-auto';\n spinner.role = 'status';\n spinner.ariaHidden = 'true';\n spinner.style.marginTop = '0.8rem';\n document.getElementById(this.targetElement).appendChild(spinner);\n\n // clear instructionDisplay\n const soundMessage = document.getElementById(this.soundMessageId);\n soundMessage.innerHTML = '';\n soundMessage.style.display = 'none';\n const instructionDisplay = document.getElementById(this.instructionDisplayId);\n const background = document.getElementById('background'); // todo: get background id from params\n const subtitle = document.getElementById(this.soundSubtitleId);\n if (subtitle) {\n subtitle.innerHTML = '';\n }\n if (instructionDisplay) {\n instructionDisplay.innerHTML = '';\n instructionDisplay.style.whiteSpace = 'nowrap';\n instructionDisplay.style.fontWeight = 'bold';\n instructionDisplay.style.width = 'fit-content';\n instructionDisplay.innerHTML = this.phrases.RC_soundRecording[this.language];\n let fontSize = 100;\n instructionDisplay.style.fontSize = fontSize + 'px';\n while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {\n fontSize--;\n instructionDisplay.style.fontSize = fontSize + 'px';\n }\n // const p = document.createElement('p');\n // // font size\n // p.style.fontSize = '1.1rem';\n // p.style.fontWeight = 'normal';\n // p.style.paddingTop = '20px';\n // const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];\n // p.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n // instructionDisplay.appendChild(p);\n }\n const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);\n if (timeToCalibrateDisplay) {\n const timeToCalibrateText = this.phrases.RC_howLongToCalibrate[this.language];\n timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);\n timeToCalibrateDisplay.style.fontWeight = 'normal';\n timeToCalibrateDisplay.style.fontSize = '1rem';\n // timeToCalibrateDisplay.style.paddingTop = '20px';\n }\n\n // Update title - titleDisplayId\n const titleDisplay = document.getElementById(this.titleDisplayId);\n if (titleDisplay) {\n // if (this.isParticipant) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n // } else if (this.isSmartPhone) {\n // if (this.isLoudspeakerCalibration) {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n // } else {\n // titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n // }\n if (this.isLoudspeakerCalibration) {\n if (this.isParticipant) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n } else if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('6', '7');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('4', '5');\n }\n } else {\n if (this.isSmartPhone) {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('5', '6');\n } else {\n titleDisplay.innerHTML = titleDisplay.innerHTML.replace('3', '4');\n }\n }\n }\n });\n _classPrivateFieldInitSpec(this, _removeUIElems, () => {\n const parent = document.getElementById(this.targetElement);\n while (parent.firstChild) {\n parent.firstChild.remove();\n }\n });\n /**\r\n * Called when the peer connection is opened.\r\n * Saves the peer id and calls the QR code generator.\r\n *\r\n * @param peerId - The peer id of the peer connection.\r\n * @param id\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerOpen, id => {\n // Workaround for peer.reconnect deleting previous id\n try {\n if (id === null) {\n console.error('Received null id from peer open');\n this.peer.id = this.lastPeerId;\n } else {\n this.lastPeerId = this.peer.id;\n }\n if (id !== this.peer.id) {\n console.warn('DEBUG Check you assumption that id === this.peer.id');\n }\n } catch (error) {\n console.error('Error in #onPeerOpen: ', error);\n }\n _classPrivateFieldGet(_showQRCode, this).call(this);\n });\n /**\r\n * Called when the peer connection is established.\r\n * Enforces a single connection.\r\n *\r\n * @param connection - The connection object.\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerConnection, connection => {\n // Allow only a single connection\n if (this.conn && this.conn.open) {\n connection.on('open', () => {\n connection.send('Already connected to another client');\n setTimeout(() => {\n connection.close();\n }, 500);\n });\n return;\n }\n this.conn = connection;\n console.log('Connected to: ', this.conn.peer);\n _classPrivateFieldGet(_ready, this).call(this);\n });\n /**\r\n * Called when the peer connection is closed.\r\n *\r\n * @private\r\n * @example\r\n */\n _defineProperty(this, \"onPeerClose\", () => {\n this.conn = null;\n console.log('Connection destroyed');\n });\n /**\r\n * Called when the peer connection is disconnected.\r\n * Attempts to reconnect.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerDisconnected, () => {\n console.log('Connection lost. Please reconnect');\n try {\n // Workaround for peer.reconnect deleting previous id\n this.peer.id = this.lastPeerId;\n // eslint-disable-next-line no-underscore-dangle\n this.peer._lastServerId = this.lastPeerId;\n this.peer.reconnect();\n } catch (error) {\n console.error('Error in #onPeerDisconnected: ', error);\n }\n });\n /**\r\n * Called when the peer connection encounters an error.\r\n *\r\n * @param error\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onPeerError, error => {\n // TODO: check if this function is needed or not\n console.error(error);\n });\n /**\r\n * Called when data is received from the peer connection.\r\n *\r\n * @param data\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _onIncomingData, data => {\n // enforce object type\n if (!Object.prototype.hasOwnProperty.call(data, 'name') || !Object.prototype.hasOwnProperty.call(data, 'payload')) {\n console.error('Received malformed data: ', data);\n return;\n }\n switch (data.name) {\n case 'samplingRate':\n this.ac.setSamplingRates(data.payload);\n break;\n case 'sampleSize':\n this.ac.setSampleSize(data.payload);\n break;\n case 'deviceType':\n this.ac.setDeviceType(data.payload);\n break;\n case 'deviceName':\n this.ac.setDeviceName(data.payload);\n break;\n case 'flags':\n //this.ac.setDeviceName(data.payload);\n console.log('FLAGS');\n console.log(data.payload);\n this.ac.setFlags(data.payload);\n break;\n case 'deviceInfo':\n this.ac.setDeviceInfo(data.payload);\n console.log('Received device info from listener: ', data.payload);\n break;\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.UnsupportedDeviceError.name:\n case _peerErrors__WEBPACK_IMPORTED_MODULE_10__.MissingSpeakerIdError.name:\n throw data.payload;\n break;\n default:\n break;\n }\n });\n /**\r\n * Called when the peer connection is #ready.\r\n *\r\n * @private\r\n * @example\r\n */\n _classPrivateFieldInitSpec(this, _ready, () => {\n // Perform callback with data\n this.conn.on('data', _classPrivateFieldGet(_onIncomingData, this));\n this.conn.on('close', () => {\n console.log('Connection reset<br>Awaiting connection...');\n this.conn = null;\n });\n });\n /** .\r\n * .\r\n * .\r\n * Debug method for downloading the recorded audio\r\n *\r\n * @public\r\n * @example\r\n */\n _defineProperty(this, \"downloadData\", () => {\n this.ac.downloadData();\n });\n _defineProperty(this, \"repeatCalibration\", async (params, stream, CalibratorInstance) => {\n this.ac = CalibratorInstance;\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n _classPrivateFieldGet(_showSpinner, this).call(this);\n console.log('This is a repeat');\n // wrap the calibration process in a promise so we can await it\n return new Promise(async (resolve, reject) => {\n const result = await this.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, this).call(this);\n resolve(result);\n });\n });\n this.language = (_params$language = _params === null || _params === void 0 ? void 0 : _params.language) !== null && _params$language !== void 0 ? _params$language : 'en-US';\n this.siteUrl += '/listener?';\n this.ac = _CalibratorInstance;\n this.result = null;\n this.debug = (_params$debug = _params === null || _params === void 0 ? void 0 : _params.debug) !== null && _params$debug !== void 0 ? _params$debug : false;\n this.isSmartPhone = (_params$isSmartPhone = _params === null || _params === void 0 ? void 0 : _params.isSmartPhone) !== null && _params$isSmartPhone !== void 0 ? _params$isSmartPhone : false;\n this.calibrateSoundHz = (_params$calibrateSoun = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundHz) !== null && _params$calibrateSoun !== void 0 ? _params$calibrateSoun : 48000;\n this.calibrateSoundSamplingDesiredBits = (_params$calibrateSoun2 = _params === null || _params === void 0 ? void 0 : _params.calibrateSoundSamplingDesiredBits) !== null && _params$calibrateSoun2 !== void 0 ? _params$calibrateSoun2 : 24;\n this.instructionDisplayId = (_params$instructionDi = _params === null || _params === void 0 ? void 0 : _params.instructionDisplayId) !== null && _params$instructionDi !== void 0 ? _params$instructionDi : '';\n this.soundSubtitleId = (_params$soundSubtitle = _params === null || _params === void 0 ? void 0 : _params.soundSubtitleId) !== null && _params$soundSubtitle !== void 0 ? _params$soundSubtitle : '';\n this.timeToCalibrateDisplay = (_params$timeToCalibra = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrateId) !== null && _params$timeToCalibra !== void 0 ? _params$timeToCalibra : '';\n this.soundMessageId = (_params$soundMessageI = _params === null || _params === void 0 ? void 0 : _params.soundMessageId) !== null && _params$soundMessageI !== void 0 ? _params$soundMessageI : '';\n this.titleDisplayId = (_params$titleDisplayI = _params === null || _params === void 0 ? void 0 : _params.titleDisplayId) !== null && _params$titleDisplayI !== void 0 ? _params$titleDisplayI : '';\n this.timeToCalibrate = (_params$timeToCalibra2 = _params === null || _params === void 0 ? void 0 : _params.timeToCalibrate) !== null && _params$timeToCalibra2 !== void 0 ? _params$timeToCalibra2 : 10;\n this.isParticipant = (_params$isParticipant = _params === null || _params === void 0 ? void 0 : _params.isParticipant) !== null && _params$isParticipant !== void 0 ? _params$isParticipant : false;\n this.isLoudspeakerCalibration = (_params$isLoudspeaker = _params === null || _params === void 0 ? void 0 : _params.isLoudspeakerCalibration) !== null && _params$isLoudspeaker !== void 0 ? _params$isLoudspeaker : false;\n this.deviceId = (_params$micrpohoneIdF = _params === null || _params === void 0 ? void 0 : _params.micrpohoneIdFromWebAudioApi) !== null && _params$micrpohoneIdF !== void 0 ? _params$micrpohoneIdF : '';\n this.buttonsContainer = (_params$buttonsContai = _params === null || _params === void 0 ? void 0 : _params.buttonsContainer) !== null && _params$buttonsContai !== void 0 ? _params$buttonsContai : document.createElement('div');\n this.phrases = (_params$phrases = _params === null || _params === void 0 ? void 0 : _params.phrases) !== null && _params$phrases !== void 0 ? _params$phrases : {};\n\n /* Set up callbacks that handle any events related to our peer object. */\n }\n}\n\n/* \r\nReferenced links:\r\nhttps://stackoverflow.com/questions/28016664/when-you-pass-this-as-an-argument/28016676#28016676\r\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\r\nhttps://stackoverflow.com/questions/879152/how-do-i-make-javascript-beep [3]\r\n*/\n_Speaker = Speaker;\n/**\r\n * Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.\r\n *\r\n * @param params - The parameters to be passed to the peer object.\r\n * @param Calibrator - The class that defines the calibration process.\r\n * @param CalibratorInstance\r\n * @param timeOut - The amount of time to wait before timing out the connection (in milliseconds).\r\n * @public\r\n * @example\r\n */\n_defineProperty(Speaker, \"startCalibration\", async function (params, CalibratorInstance) {\n let timeOut = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n await speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n if (params.displayUpdate) {\n params.displayUpdate.style.display = '';\n }\n\n // resolve when we have a result\n speaker.result = await speaker.ac.startCalibration(stream, params.gainValues, params.ICalib, params.knownIR, params.microphoneName, params.calibrateSoundCheck, params.isSmartPhone, params.calibrateSoundBurstDb, params.calibrateSoundBurstFilteredExtraDb, params.calibrateSoundBurstLevelReTBool, params.calibrateSoundBurstUses1000HzGainBool, params.calibrateSoundBurstRepeats, params.calibrateSoundBurstSec, params._calibrateSoundBurstPreSec, params._calibrateSoundBurstPostSec, params.calibrateSoundHz, params.calibrateSoundIRSec, params.calibrateSoundIIRSec, params.calibrateSoundIIRPhase, params.calibrateSound1000HzPreSec, params.calibrateSound1000HzSec, params.calibrateSound1000HzPostSec, params.calibrateSoundBackgroundSecs, params.calibrateSoundSmoothOctaves, params.calibrateSoundSmoothMinBandwidthHz, params.calibrateSoundPowerBinDesiredSec, params.calibrateSoundPowerDbSDToleratedDb, params.calibrateSoundTaperSec, params.micManufacturer, params.micSerialNumber, params.micModelNumber, params.micModelName, params.calibrateMicrophonesBool, params.authorEmails, params.webAudioDeviceNames, params.IDsToSaveInSoundProfileLibrary, params.restartButton, params.reminder, params.calibrateSoundLimit, params.calibrateSoundBurstNormalizeBy1000HzGainBool, params.calibrateSoundBurstScalarDB, params.calibrateSound1000HzMaxSD_dB, params._calibrateSoundBurstMaxSD_dB, params.calibrateSoundSamplingDesiredBits, params.language, params.loudspeakerModelName, params.phrases, params.soundSubtitleId);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"testIIR\", async function (params, CalibratorInstance, IIR) {\n let timeOut = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 180000;\n window.speaker = new _Speaker(params, CalibratorInstance);\n const {\n speaker\n } = window;\n speaker.initPeer();\n // wrap the calibration process in a promise so we can await it\n return new Promise((resolve, reject) => {\n // when a call is received\n speaker.peer.on('call', async call => {\n // Answer the call (one way)\n call.answer();\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n _classPrivateFieldGet(_showSpinner, speaker).call(speaker);\n speaker.ac.createLocalAudio(document.getElementById(speaker.targetElement));\n // when we start receiving audio\n call.on('stream', async stream => {\n window.localStream = stream;\n window.localAudio.srcObject = stream;\n window.localAudio.autoplay = false;\n\n // if the sinkSamplingRate is not set sleep\n while (!speaker.ac.sampleRatesSet()) {\n console.log('SinkSamplingRate is undefined, sleeping');\n await (0,_utils__WEBPACK_IMPORTED_MODULE_9__.sleep)(1);\n }\n // resolve when we have a result\n speaker.result = await speaker.ac.playMLSwithIIR(stream, IIR);\n _classPrivateFieldGet(_removeUIElems, speaker).call(speaker);\n resolve(speaker.result);\n });\n // if we do not receive a result within the timeout, reject\n setTimeout(() => {\n reject(new _peerErrors__WEBPACK_IMPORTED_MODULE_10__.CalibrationTimedOutError(\"Calibration failed to produce a result after \".concat(timeOut / 1000, \" seconds. Try increasing \\\"_timeoutSec\\\", which is currently \").concat(timeOut / 1000, \" seconds.\")));\n }, timeOut);\n });\n });\n});\n_defineProperty(Speaker, \"closeConnection\", () => {\n _Speaker.conn = null;\n console.log('Connection destroyed');\n});\n/* harmony default export */ __webpack_exports__[\"default\"] = (Speaker);\n\n//# sourceURL=webpack://speakerCalibrator/./src/peer-connection/speaker.js?");
|
|
140
140
|
|
|
141
141
|
/***/ }),
|
|
142
142
|
|
package/package.json
CHANGED
|
@@ -43,12 +43,15 @@ class Listener extends AudioPeer {
|
|
|
43
43
|
onPeerOpen = id => {
|
|
44
44
|
this.displayUpdate('Listener - onPeerOpen');
|
|
45
45
|
// Workaround for peer.reconnect deleting previous id
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
try {
|
|
47
|
+
if (id === null) {
|
|
48
|
+
this.displayUpdate('Received null id from peer open');
|
|
49
|
+
this.peer.id = this.lastPeerId;
|
|
50
|
+
} else {
|
|
51
|
+
this.lastPeerId = this.peer.id;
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error('Error in onPeerOpen: ', error);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
this.join();
|