Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-03-24 23:28:51 +0300
committerJoas Schilling <coding@schilljs.com>2020-07-09 10:29:26 +0300
commit5589b80465e6b331e2f7ac1a8a8aadfb58d4c8c8 (patch)
treef8ec1f995d19bec7e54a14f048a3d6293d38106e
parenta3aacda9f1c80f1cb65b78ff0c7831b0a9761bf1 (diff)
Play sounds when someone is joining or leaving a call
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--img/LibremEmailNotification.oggbin0 -> 88688 bytes
-rw-r--r--img/LibremTextMessage.oggbin0 -> 82206 bytes
-rw-r--r--lib/Controller/PageController.php4
-rw-r--r--src/utils/sounds.js83
-rw-r--r--src/utils/webrtc/webrtc.js32
5 files changed, 117 insertions, 2 deletions
diff --git a/img/LibremEmailNotification.ogg b/img/LibremEmailNotification.ogg
new file mode 100644
index 000000000..ebe8fb3ed
--- /dev/null
+++ b/img/LibremEmailNotification.ogg
Binary files differ
diff --git a/img/LibremTextMessage.ogg b/img/LibremTextMessage.ogg
new file mode 100644
index 000000000..567f9ce94
--- /dev/null
+++ b/img/LibremTextMessage.ogg
Binary files differ
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index d3246e1d0..0d48015cf 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -252,7 +252,9 @@ class PageController extends Controller {
$response = new TemplateResponse($this->appName, 'index');
$csp = new ContentSecurityPolicy();
$csp->addAllowedConnectDomain('*');
- $csp->addAllowedMediaDomain('blob:');
+// $csp->addAllowedMediaDomain('blob:');
+ $csp->addAllowedMediaDomain('*');
+ $csp->addAllowedObjectDomain('*');
$response->setContentSecurityPolicy($csp);
return $response;
}
diff --git a/src/utils/sounds.js b/src/utils/sounds.js
new file mode 100644
index 000000000..d7249e46d
--- /dev/null
+++ b/src/utils/sounds.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')
+ },
+}
diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js
index 649a68f9e..296b4f14b 100644
--- a/src/utils/webrtc/webrtc.js
+++ b/src/utils/webrtc/webrtc.js
@@ -30,6 +30,7 @@ import SimpleWebRTC from './simplewebrtc/simplewebrtc'
import { PARTICIPANT } from '../../constants.js'
import store from '../../store/index.js'
import { showError } from '@nextcloud/dialogs'
+import { Sounds } from '../sounds.js'
let webrtc
const spreedPeerConnectionTable = []
@@ -155,6 +156,9 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
checkStartPublishOwnPeer(signaling)
}
+ let playJoinSound = false
+ let playLeaveSound = false
+
newUsers.forEach(function(user) {
if (!user.inCall) {
return
@@ -163,6 +167,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
}
@@ -191,6 +198,8 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
callParticipantModel.setPeer(null)
}
+ playJoinSound = true
+
const createPeer = function() {
const peer = webrtc.webrtc.createPeer({
id: sessionId,
@@ -260,12 +269,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()
@@ -291,7 +312,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
@@ -341,6 +370,7 @@ export default function initWebRTC(signaling, _callParticipantCollection) {
return
}
+ Sounds.playLeave(true)
webrtc.leaveCall()
})