Quellcode durchsuchen

ref(chat): port incoming chat msg sound to react

master
paweldomas vor 7 Jahren
Ursprung
Commit
26cd2f17f6

+ 0
- 3
modules/UI/side_pannels/chat/Chat.js Datei anzeigen

@@ -25,8 +25,6 @@ const htmlStr = `
25 25
         </div>
26 26
 
27 27
         <div id="chatconversation"></div>
28
-        <audio id="chatNotification" src="sounds/incomingMessage.wav"
29
-            preload="auto"></audio>
30 28
         <textarea id="usermsg" autofocus
31 29
             data-i18n="[placeholder]chat.messagebox"></textarea>
32 30
         <div id="smileysarea">
@@ -285,7 +283,6 @@ const Chat = {
285 283
 
286 284
             if (!Chat.isVisible()) {
287 285
                 unreadMessages++;
288
-                UIUtil.playSoundNotification('chatNotification');
289 286
                 updateVisualNotification();
290 287
             }
291 288
         }

+ 0
- 9
modules/UI/util/UIUtil.js Datei anzeigen

@@ -66,15 +66,6 @@ const UIUtil = {
66 66
         return el.clientHeight + 1;
67 67
     },
68 68
 
69
-    /**
70
-     * Plays the sound given by id.
71
-     *
72
-     * @param id the identifier of the audio element.
73
-     */
74
-    playSoundNotification(id) {
75
-        document.getElementById(id).play();
76
-    },
77
-
78 69
     /**
79 70
      * Escapes the given text.
80 71
      */

+ 1
- 0
react/features/app/components/App.web.js Datei anzeigen

@@ -3,6 +3,7 @@ import React from 'react';
3 3
 
4 4
 import '../../base/responsive-ui';
5 5
 import { getLocationContextRoot } from '../../base/util';
6
+import '../../chat';
6 7
 import '../../room-lock';
7 8
 
8 9
 import { AbstractApp } from './AbstractApp';

+ 9
- 0
react/features/chat/constants.js Datei anzeigen

@@ -0,0 +1,9 @@
1
+/* eslint-disable no-unused-vars */
2
+import { playAudio } from '../base/media';
3
+
4
+/**
5
+ * The audio ID of the audio element for which the {@link playAudio} action is
6
+ * triggered when new chat message is received.
7
+ * @type {string}
8
+ */
9
+export const INCOMING_MSG_SOUND_ID = 'INCOMING_MSG_SOUND';

+ 3
- 0
react/features/chat/index.js Datei anzeigen

@@ -0,0 +1,3 @@
1
+export * from './constants';
2
+
3
+import './middleware';

+ 66
- 0
react/features/chat/middleware.js Datei anzeigen

@@ -0,0 +1,66 @@
1
+// @flow
2
+
3
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
4
+import { CONFERENCE_JOINED } from '../base/conference';
5
+import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
6
+import { MiddlewareRegistry } from '../base/redux';
7
+import { playSound, registerSound, unregisterSound } from '../base/sounds';
8
+
9
+import { INCOMING_MSG_SOUND_ID } from './constants';
10
+import { INCOMING_MSG_SOUND_SRC } from './sounds';
11
+
12
+declare var APP: Object;
13
+
14
+/**
15
+ * Implements the middleware of the chat feature.
16
+ *
17
+ * @param {Store} store - The redux store.
18
+ * @returns {Function}
19
+ */
20
+MiddlewareRegistry.register(store => next => action => {
21
+    switch (action.type) {
22
+    case APP_WILL_MOUNT: {
23
+        // Register chat msg sound only on web
24
+        typeof APP !== 'undefined'
25
+            && store.dispatch(
26
+                registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
27
+        break;
28
+    }
29
+    case APP_WILL_UNMOUNT: {
30
+        // Register chat msg sound only on web
31
+        typeof APP !== 'undefined'
32
+            && store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
33
+        break;
34
+    }
35
+    case CONFERENCE_JOINED:
36
+        typeof APP !== 'undefined'
37
+            && _addChatMsgListener(action.conference, store);
38
+        break;
39
+    }
40
+
41
+    return next(action);
42
+});
43
+
44
+/**
45
+ * Registers listener for {@link JitsiConferenceEvents.MESSAGE_RECEIVED} which
46
+ * will play a sound on the event, given that the chat is not currently visible.
47
+ *
48
+ * @param {JitsiConference} conference - The conference instance on which the
49
+ * new event listener will be registered.
50
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
51
+ * specified action to the specified store.
52
+ * @returns {void}
53
+ * @private
54
+ */
55
+function _addChatMsgListener(conference, { dispatch }) {
56
+    // XXX Currently there's no need to remove the listener, because
57
+    // conference instance can not be re-used. Listener will be gone with
58
+    // the conference instance.
59
+    conference.on(
60
+        JitsiConferenceEvents.MESSAGE_RECEIVED,
61
+        () => {
62
+            if (!APP.UI.isChatVisible()) {
63
+                dispatch(playSound(INCOMING_MSG_SOUND_ID));
64
+            }
65
+        });
66
+}

+ 5
- 0
react/features/chat/sounds.web.js Datei anzeigen

@@ -0,0 +1,5 @@
1
+/**
2
+ * The audio source for the incoming chat message sound.
3
+ * @type {string}
4
+ */
5
+export const INCOMING_MSG_SOUND_SRC = 'sounds/incomingMessage.wav';

Laden…
Abbrechen
Speichern