diff --git a/img/COPYING b/img/COPYING
index 864f9dcc290..3342a3be628 100644
--- a/img/COPYING
+++ b/img/COPYING
@@ -5,3 +5,11 @@
## leave_call.ogg
@author Marco Ambrosini (marcoambrosini@icloud.com)
@license CC0-1.0
+
+## join_call.flac
+@author Marco Ambrosini (marcoambrosini@icloud.com)
+@license CC0-1.0
+
+## leave_call.flac
+@author Marco Ambrosini (marcoambrosini@icloud.com)
+@license CC0-1.0
\ No newline at end of file
diff --git a/img/LibremPhoneCall.flac b/img/LibremPhoneCall.flac
new file mode 100644
index 00000000000..be9310431d9
Binary files /dev/null and b/img/LibremPhoneCall.flac differ
diff --git a/img/join_call.flac b/img/join_call.flac
new file mode 100644
index 00000000000..bd09fb9c45a
Binary files /dev/null and b/img/join_call.flac differ
diff --git a/img/leave_call.flac b/img/leave_call.flac
new file mode 100644
index 00000000000..0efdd194849
Binary files /dev/null and b/img/leave_call.flac differ
diff --git a/src/components/SettingsDialog/SettingsDialog.vue b/src/components/SettingsDialog/SettingsDialog.vue
index 5e8ed454fde..e83fc111876 100644
--- a/src/components/SettingsDialog/SettingsDialog.vue
+++ b/src/components/SettingsDialog/SettingsDialog.vue
@@ -81,7 +81,7 @@
@update:checked="togglePlaySounds">
{{ t('spreed', 'Play sounds when participants join or leave a call') }}
- {{ t('spreed', 'Sounds can currently not be played in Safari browser and iPad and iPhone devices due to technical restrictions by the manufacturer.') }}
+ {{ t('spreed', 'Sounds can currently not be played on iPad and iPhone devices due to technical restrictions by the manufacturer.') }}
spreed/img/myAudio.ogg
+ *
+ * @param {string} fileName The name of the file without extension
+ * @return {string} The full path to the file in the spreed/img directory and adds .ogg/.flac depending on supported codecs
+ */
+const getFullAudioFilepath = function(fileName) {
+ const tempAudio = new Audio()
+
+ // Prefer the .ogg version of sounds, but fall back to .flac in case .ogg is not supported (Safari)
+ if (tempAudio.canPlayType('audio/ogg')) {
+ return generateFilePath('spreed', 'img', fileName + '.ogg')
+ } else {
+ return generateFilePath('spreed', 'img', fileName + '.flac')
+ }
+}
+
+/**
+ * Creates a HTMLAudioElement with the specified filePath and loads it
+ *
+ * @param {string} filePath Path to the file
+ * @return {HTMLAudioElement} The created and loaded HTMLAudioElement
+ */
+const createAudioObject = function(filePath) {
+ const audio = new Audio(filePath)
+ audio.load()
+
+ return audio
}
const actions = {
@@ -78,6 +153,85 @@ const actions = {
await setPlaySounds(!context.state.userId, enabled)
context.commit('setPlaySounds', enabled)
},
+
+ /**
+ * Plays the join audio file with a volume of 0.75
+ *
+ * @param {object} context default store context
+ */
+ playJoinAudio(context) {
+ // Make sure the audio objects are really created before playing it
+ context.dispatch('createAudioObjects')
+
+ const audio = context.state.joinAudioObject
+ audio.load()
+ audio.volume = 0.75
+ audio.play()
+ },
+
+ /**
+ * Plays the leave audio file with a volume of 0.75
+ *
+ * @param {object} context default store context
+ */
+ playLeaveAudio(context) {
+ // Make sure the audio objects are really created before playing it
+ context.dispatch('createAudioObjects')
+
+ const audio = context.state.leaveAudioObject
+ audio.load()
+ audio.volume = 0.75
+ audio.play()
+ },
+
+ /**
+ * Plays the wait audio file with a volume of 0.5
+ *
+ * @param {object} context default store context
+ */
+ playWaitAudio(context) {
+ // Make sure the audio objects are really created before playing it
+ context.dispatch('createAudioObjects')
+
+ const audio = context.state.waitAudioObject
+ audio.load()
+ audio.volume = 0.5
+ audio.play()
+ },
+
+ /**
+ * Pauses the wait audio playback
+ *
+ * @param {object} context default store context
+ */
+ pauseWaitAudio(context) {
+ const audio = context.state.waitAudioObject
+ audio.pause()
+ },
+
+ /**
+ * If not already created, this creates audio objects for join, leave and wait sounds
+ *
+ * @param {object} context default store context
+ */
+ createAudioObjects(context) {
+ // No need to create the audio objects, if they were created already
+ if (context.state.audioObjectsCreated) {
+ return
+ }
+
+ const joinFilepath = getFullAudioFilepath('join_call')
+ const joinAudio = createAudioObject(joinFilepath)
+ context.commit('setJoinAudioObject', joinAudio)
+
+ const leaveFilepath = getFullAudioFilepath('leave_call')
+ const leaveAudio = createAudioObject(leaveFilepath)
+ context.commit('setLeaveAudioObject', leaveAudio)
+
+ const waitFilepath = getFullAudioFilepath('LibremPhoneCall')
+ const waitAudio = createAudioObject(waitFilepath)
+ context.commit('setWaitAudioObject', waitAudio)
+ },
}
export default { state, mutations, getters, actions }
diff --git a/src/utils/sounds.js b/src/utils/sounds.js
index 35563d67000..e712b286688 100644
--- a/src/utils/sounds.js
+++ b/src/utils/sounds.js
@@ -18,8 +18,6 @@
*
*/
-import { generateFilePath } from '@nextcloud/router'
-
import store from '../store/index.js'
export const Sounds = {
@@ -29,22 +27,11 @@ export const Sounds = {
lastPlayedJoin: 0,
lastPlayedLeave: 0,
playedWaiting: 0,
- backgroundAudio: null,
backgroundInterval: null,
- _playSoundOnce(soundFile) {
- const file = generateFilePath('spreed', 'img', soundFile)
- const audio = new Audio(file)
- audio.volume = 0.75
- audio.play()
- },
-
_stopWaiting() {
console.debug('Stop waiting sound')
- if (this.backgroundAudio) {
- this.backgroundAudio.pause()
- this.backgroundAudio = null
- }
+ store.dispatch('pauseWaitAudio')
clearInterval(this.backgroundInterval)
},
@@ -53,15 +40,8 @@ export const Sounds = {
return
}
- if (!this.backgroundAudio) {
- console.debug('Loading waiting sound')
- const file = generateFilePath('spreed', 'img', 'LibremPhoneCall.ogg')
- this.backgroundAudio = new Audio(file)
- this.backgroundAudio.volume = 0.5
- }
-
console.debug('Playing waiting sound')
- this.backgroundAudio.play()
+ store.dispatch('playWaitAudio')
this.playedWaiting = 0
this.backgroundInterval = setInterval(() => {
@@ -77,7 +57,7 @@ export const Sounds = {
}
console.debug('Playing waiting sound')
- this.backgroundAudio.play()
+ store.dispatch('playWaitAudio')
this.playedWaiting++
}, 15000)
@@ -114,7 +94,7 @@ export const Sounds = {
if (playWaitingSound) {
await this.playWaiting()
} else {
- this._playSoundOnce('join_call.ogg')
+ store.dispatch('playJoinAudio')
}
},
@@ -145,7 +125,7 @@ export const Sounds = {
}
this.lastPlayedLeave = currentTime
- this._playSoundOnce('leave_call.ogg')
+ store.dispatch('playLeaveAudio')
if (playWaitingSound) {
this.playWaiting()