Browse Source
Play sounds when someone is joining or leaving a call
Play sounds when someone is joining or leaving a call
Signed-off-by: Joas Schilling <coding@schilljs.com>pull/5410/head
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
4 changed files with 114 additions and 1 deletions
-
BINimg/LibremEmailNotification.ogg
-
BINimg/LibremTextMessage.ogg
-
83src/utils/sounds.js
-
32src/utils/webrtc/webrtc.js
@ -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') |
|||
}, |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue