Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxAlyokhin committed Apr 22, 2023
1 parent 297b663 commit 13dce9c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 66 deletions.
2 changes: 1 addition & 1 deletion client/src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ const fourierCoefficients = {
export function audioInit() {
// Checking context support in the browser
try {
audioContext = new (window.AudioContext || window.webkitAudioContext)()
audioContext = new (window.AudioContext || window.webkitAudioContext)({ latencyHint: 0 })
} catch (error) {
window.alert(`Браузер не поддерживается / Browser is not support`)
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/js/latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function latency(device) {

// From the smartphone returns pong with the same desktop time
socket.on('pong', (dateOfPing) => {
latencyElement.textContent = (Date.now() - dateOfPing) / 2 + toFixedNumber(audioContext.outputLatency, 3) * 1000
latencyElement.textContent = `${(Date.now() - dateOfPing) / 2} + ${toFixedNumber(audioContext.outputLatency || audioContext.baseLatency, 3) * 1000}`
})
}

Expand All @@ -42,7 +42,7 @@ export function latency(device) {
intervalIsInit = true
// Writing a latency in the DOM
setInterval(() => {
latencyElement.textContent = toFixedNumber(audioContext.outputLatency, 3) * 1000
latencyElement.textContent = toFixedNumber(audioContext.outputLatency || audioContext.baseLatency, 3) * 1000
}, updateFrequency)
}
}
Expand Down
127 changes: 66 additions & 61 deletions client/src/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Mutations are triggered by events in the interface
// and synchronize settings over a websocket with the remote desktop

import device from 'current-device'

import { updateCompressorSettings } from './audio'
import { toFixedNumber } from './helpers'
import { language } from './language'
Expand Down Expand Up @@ -549,46 +551,13 @@ export function syncSettings() {
socket.emit('settings message', settings)
}

updateCompressorSettings(settings.audio.compressor)
syncLocalStorage(settings)
}

// Linking the settings object to the interface
export function settingsInit() {

// Enabling the websocket on a smartphone
synthesisRegimeElement.addEventListener('change', function (event) {
if (!socketIsInit) {
socketInit()

socket.connect()

// On updating the settings object
socket.on('settings message', (settingsData) => {
Object.assign(settings, settingsData) // Updating an object
syncSettingsFrontend(settingsData) // Updating input fields
syncLocalStorage(settingsData)
})

// Hanging listeners of websocket events
socket.on('connect', () => {
connectionsToServer.textContent = language.connection.ready
connectionsToServer.classList.remove('connections--wait', 'connections--error')
connectionsToServer.classList.add('connections--ready')
})

socket.on('disconnect', () => {
connectionsToServer.textContent = language.connection.failed
connectionsToServer.classList.remove('connections--wait', 'connections--ready')
connectionsToServer.classList.add('connections--error')
})

// Here hangs the pong event listener from the desktop to calculate the latency to the desktop
latency('mobile')
}

mutations.audio.setSynthesisRegime(event.target.value)
})

frequencyRegimeElement.addEventListener('change', function (event) {
mutations.audio.setFrequencyRegime(event.target.value)
})
Expand Down Expand Up @@ -789,42 +758,78 @@ export function settingsInit() {
// Setting up the compressor
updateCompressorSettings(settings.audio.compressor)

// If the URL has ?remote, then immediately switch to the relevant mode
const markerFromURL = document.location.search.slice(1)
if (device.mobile()) {
// Enabling the websocket on a smartphone
synthesisRegimeElement.addEventListener('change', function (event) {
if (!socketIsInit) {
socketInit()

if (markerFromURL === 'remote') {
settings.audio.synthesisRegime = 'remote'
document.querySelector('#remote').checked = true
socket.connect()

if (!socketIsInit) {
socketInit()
// On updating the settings object
socket.on('settings message', (settingsData) => {
Object.assign(settings, settingsData) // Updating an object
syncSettingsFrontend(settingsData) // Updating input fields
syncLocalStorage(settingsData)
})

// Hanging listeners of websocket events
socket.on('connect', () => {
connectionsToServer.textContent = language.connection.ready
connectionsToServer.classList.remove('connections--wait', 'connections--error')
connectionsToServer.classList.add('connections--ready')
})

socket.on('disconnect', () => {
connectionsToServer.textContent = language.connection.failed
connectionsToServer.classList.remove('connections--wait', 'connections--ready')
connectionsToServer.classList.add('connections--error')
})

// Here hangs the pong event listener from the desktop to calculate the latency to the desktop
latency('mobile')
}

socket.connect()
mutations.audio.setSynthesisRegime(event.target.value)
})

socket.on('settings message', (settingsData) => {
Object.assign(settings, settingsData)
syncSettingsFrontend(settingsData)
})
// If the URL has ?remote, then immediately switch to the relevant mode
const markerFromURL = document.location.search.slice(1)

socket.on('connect', () => {
connectionsToServer.textContent = language.connection.ready
connectionsToServer.classList.remove('connections--wait', 'connections--error')
connectionsToServer.classList.add('connections--ready')
})
if (markerFromURL === 'remote') {
settings.audio.synthesisRegime = 'remote'
document.querySelector('#remote').checked = true

socket.on('disconnect', () => {
connectionsToServer.textContent = language.connection.failed
connectionsToServer.classList.remove('connections--wait', 'connections--ready')
connectionsToServer.classList.add('connections--error')
})
if (!socketIsInit) {
socketInit()

socket.connect()

socket.on('settings message', (settingsData) => {
Object.assign(settings, settingsData)
syncSettingsFrontend(settingsData)
})

socket.on('connect', () => {
connectionsToServer.textContent = language.connection.ready
connectionsToServer.classList.remove('connections--wait', 'connections--error')
connectionsToServer.classList.add('connections--ready')
})

socket.on('disconnect', () => {
connectionsToServer.textContent = language.connection.failed
connectionsToServer.classList.remove('connections--wait', 'connections--ready')
connectionsToServer.classList.add('connections--error')
})
}

mutations.audio.setSynthesisRegime('remote')
}

mutations.audio.setSynthesisRegime('remote')
// Calculate the delay, which is equal to audioContext.outputLatency for the smartphone
// Also here hangs the pong event listener from the desktop to calculate the latency to the desktop
latency('mobile')
}

// Calculate the delay, which is equal to audioContext.outputLatency for the smartphone
// Also here hangs the pong event listener from the desktop to calculate the latency to the desktop
latency('mobile')
}

// Hotkey control
Expand Down
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Max Alyokhin",
"license": "MIT",
"dependencies": {
"component-emitter": "^1.3.0",
"express": "^4.17.1",
"open": "^8.4.0",
"socket.io": "^4.1.2"
Expand Down

0 comments on commit 13dce9c

Please sign in to comment.