mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Play sounds when someone is joining or leaving a call
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
d602a1020b
commit
09341afb03
4 changed files with 114 additions and 1 deletions
BIN
img/LibremEmailNotification.ogg
Normal file
BIN
img/LibremEmailNotification.ogg
Normal file
Binary file not shown.
BIN
img/LibremTextMessage.ogg
Normal file
BIN
img/LibremTextMessage.ogg
Normal file
Binary file not shown.
83
src/utils/sounds.js
Normal file
83
src/utils/sounds.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import { generateFilePath } from '@nextcloud/router'
|
||||
|
||||
export const Sounds = {
|
||||
isInCall: false,
|
||||
lastPlayedJoin: 0,
|
||||
lastPlayedLeave: 0,
|
||||
|
||||
_playFile(soundFile) {
|
||||
const file = generateFilePath('spreed', 'img', soundFile)
|
||||
const audio = new Audio(file)
|
||||
audio.play()
|
||||
},
|
||||
|
||||
playJoin(force) {
|
||||
if (force) {
|
||||
this.isInCall = true
|
||||
} else if (!this.isInCall) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentTime = (new Date()).getTime()
|
||||
if (!force && this.lastPlayedJoin >= (currentTime - 7000)) {
|
||||
if (this.lastPlayedJoin >= (currentTime - 7000)) {
|
||||
console.debug('Skipping join sound because it was played %.2f seconds ago', currentTime - this.lastPlayedJoin)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (force) {
|
||||
// Don't play sounds for 8 more seconds when you just joined.
|
||||
this.lastPlayedJoin = currentTime + 8000
|
||||
this.lastPlayedLeave = currentTime + 8000
|
||||
console.debug('Playing join sound because of self joining')
|
||||
} else {
|
||||
this.lastPlayedJoin = currentTime
|
||||
console.debug('Playing join sound')
|
||||
}
|
||||
this._playFile('LibremEmailNotification.ogg')
|
||||
},
|
||||
|
||||
playLeave(force) {
|
||||
if (!this.isInCall) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentTime = (new Date()).getTime()
|
||||
if (!force && this.lastPlayedLeave >= (currentTime - 7000)) {
|
||||
if (this.lastPlayedLeave >= (currentTime - 7000)) {
|
||||
console.debug('Skipping leave sound because it was played %f.2 seconds ago', currentTime - this.lastPlayedLeave)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (force) {
|
||||
console.debug('Playing leave sound because of self leaving')
|
||||
this.isInCall = false
|
||||
} else {
|
||||
console.debug('Playing leave sound')
|
||||
}
|
||||
this.lastPlayedLeave = currentTime
|
||||
this._playFile('LibremTextMessage.ogg')
|
||||
},
|
||||
}
|
||||
|
|
@ -34,6 +34,7 @@ import {
|
|||
TOAST_PERMANENT_TIMEOUT,
|
||||
TOAST_DEFAULT_TIMEOUT,
|
||||
} from '@nextcloud/dialogs'
|
||||
import { Sounds } from '../sounds.js'
|
||||
|
||||
let webrtc
|
||||
const spreedPeerConnectionTable = []
|
||||
|
|
@ -211,6 +212,9 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
|
|||
checkStartPublishOwnPeer(signaling)
|
||||
}
|
||||
|
||||
let playJoinSound = false
|
||||
let playLeaveSound = false
|
||||
|
||||
newUsers.forEach(function(user) {
|
||||
if (!user.inCall) {
|
||||
return
|
||||
|
|
@ -219,6 +223,9 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
|
|||
// TODO(fancycode): Adjust property name of internal PHP backend to be all lowercase.
|
||||
const sessionId = user.sessionId || user.sessionid
|
||||
if (!sessionId || sessionId === currentSessionId || previousUsersInRoom.indexOf(sessionId) !== -1) {
|
||||
if (sessionId === currentSessionId && previousUsersInRoom.indexOf(sessionId) !== -1) {
|
||||
Sounds.playJoin(true)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -270,6 +277,8 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
|
|||
}
|
||||
}
|
||||
|
||||
playJoinSound = true
|
||||
|
||||
const createPeer = function() {
|
||||
const peer = webrtc.webrtc.createPeer({
|
||||
id: sessionId,
|
||||
|
|
@ -339,12 +348,24 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
|
|||
clearInterval(delayedConnectionToPeer[sessionId])
|
||||
delete delayedConnectionToPeer[sessionId]
|
||||
}
|
||||
|
||||
playLeaveSound = true
|
||||
})
|
||||
|
||||
if (selfInCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED) {
|
||||
if (playJoinSound) {
|
||||
Sounds.playJoin()
|
||||
} else if (playLeaveSound) {
|
||||
Sounds.playLeave()
|
||||
}
|
||||
}
|
||||
|
||||
previousUsersInRoom = arrayDiff(previousUsersInRoom, disconnectedSessionIds)
|
||||
}
|
||||
|
||||
function usersInCallChanged(signaling, users) {
|
||||
const previousSelfInCall = selfInCall
|
||||
|
||||
// The passed list are the users that are currently in the room,
|
||||
// i.e. that are in the call and should call each other.
|
||||
const currentSessionId = signaling.getSessionId()
|
||||
|
|
@ -370,7 +391,15 @@ function usersInCallChanged(signaling, users) {
|
|||
userMapping[sessionId] = user
|
||||
}
|
||||
|
||||
if (!selfInCall) {
|
||||
if (previousSelfInCall === PARTICIPANT.CALL_FLAG.DISCONNECTED
|
||||
&& selfInCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED) {
|
||||
Sounds.playJoin(true)
|
||||
} else if (previousSelfInCall !== PARTICIPANT.CALL_FLAG.DISCONNECTED
|
||||
&& selfInCall === PARTICIPANT.CALL_FLAG.DISCONNECTED) {
|
||||
Sounds.playLeave(true)
|
||||
}
|
||||
|
||||
if (selfInCall === PARTICIPANT.CALL_FLAG.DISCONNECTED) {
|
||||
// Own session is no longer in the call, disconnect from all others.
|
||||
usersChanged(signaling, [], previousUsersInRoom)
|
||||
return
|
||||
|
|
@ -440,6 +469,7 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
|
|||
}
|
||||
|
||||
clearErrorNotification()
|
||||
Sounds.playLeave(true)
|
||||
webrtc.leaveCall()
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue