|
@@ -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
|
+}
|