浏览代码

flow(AbstractAudio): specific function types

master
paweldomas 7 年前
父节点
当前提交
4dbcaf851f

+ 17
- 10
react/features/base/media/components/AbstractAudio.js 查看文件

7
  * playback.
7
  * playback.
8
  */
8
  */
9
 export type AudioElement = {
9
 export type AudioElement = {
10
-    pause: Function,
11
-    play: Function,
12
-    setSinkId: ?Function
13
-}
10
+    pause: () => void,
11
+    play: () => void,
12
+    setSinkId?: string => void
13
+};
14
 
14
 
15
 /**
15
 /**
16
  * {@code AbstractAudio} component's property types.
16
  * {@code AbstractAudio} component's property types.
21
      * A callback which will be called with {@code AbstractAudio} instance once
21
      * A callback which will be called with {@code AbstractAudio} instance once
22
      * the audio element is loaded.
22
      * the audio element is loaded.
23
      */
23
      */
24
-    setRef: ?Function,
24
+    setRef?: ?AudioElement => void,
25
 
25
 
26
     /**
26
     /**
27
      * The URL of a media resource to use in the element.
27
      * The URL of a media resource to use in the element.
59
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
59
         this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
60
     }
60
     }
61
 
61
 
62
+    pause: () => void;
63
+
62
     /**
64
     /**
63
      * Attempts to pause the playback of the media.
65
      * Attempts to pause the playback of the media.
64
      *
66
      *
65
      * @public
67
      * @public
66
      * @returns {void}
68
      * @returns {void}
67
      */
69
      */
68
-    pause() {
70
+    pause(): void {
69
         this._audioElementImpl && this._audioElementImpl.pause();
71
         this._audioElementImpl && this._audioElementImpl.pause();
70
     }
72
     }
71
 
73
 
74
+    play: () => void;
75
+
72
     /**
76
     /**
73
      * Attempts to being the playback of the media.
77
      * Attempts to being the playback of the media.
74
      *
78
      *
75
      * @public
79
      * @public
76
      * @returns {void}
80
      * @returns {void}
77
      */
81
      */
78
-    play() {
82
+    play(): void {
79
         this._audioElementImpl && this._audioElementImpl.play();
83
         this._audioElementImpl && this._audioElementImpl.play();
80
     }
84
     }
81
 
85
 
82
-    setAudioElementImpl: (?AudioElement) => void;
86
+    setAudioElementImpl: ?AudioElement => void;
83
 
87
 
84
     /**
88
     /**
85
      * Set the (reference to the) {@link AudioElement} object which implements
89
      * Set the (reference to the) {@link AudioElement} object which implements
90
      * @protected
94
      * @protected
91
      * @returns {void}
95
      * @returns {void}
92
      */
96
      */
93
-    setAudioElementImpl(element: ?AudioElement) {
97
+    setAudioElementImpl(element: ?AudioElement): void {
94
         this._audioElementImpl = element;
98
         this._audioElementImpl = element;
95
 
99
 
96
         // setRef
100
         // setRef
97
         const { setRef } = this.props;
101
         const { setRef } = this.props;
98
 
102
 
103
+        // $FlowFixMe
99
         typeof setRef === 'function' && setRef(element ? this : null);
104
         typeof setRef === 'function' && setRef(element ? this : null);
100
     }
105
     }
101
 
106
 
107
+    setSinkId: string => void;
108
+
102
     /**
109
     /**
103
      * Sets the sink ID (output device ID) on the underlying audio element.
110
      * Sets the sink ID (output device ID) on the underlying audio element.
104
      * NOTE: Currently, implemented only on Web.
111
      * NOTE: Currently, implemented only on Web.
106
      * @param {string} sinkId - The sink ID (output device ID).
113
      * @param {string} sinkId - The sink ID (output device ID).
107
      * @returns {void}
114
      * @returns {void}
108
      */
115
      */
109
-    setSinkId(sinkId: String) {
116
+    setSinkId(sinkId: string): void {
110
         this._audioElementImpl
117
         this._audioElementImpl
111
             && typeof this._audioElementImpl.setSinkId === 'function'
118
             && typeof this._audioElementImpl.setSinkId === 'function'
112
             && this._audioElementImpl.setSinkId(sinkId);
119
             && this._audioElementImpl.setSinkId(sinkId);

+ 1
- 3
react/features/chat/constants.js 查看文件

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

+ 20
- 19
react/features/chat/middleware.js 查看文件

19
  */
19
  */
20
 MiddlewareRegistry.register(store => next => action => {
20
 MiddlewareRegistry.register(store => next => action => {
21
     switch (action.type) {
21
     switch (action.type) {
22
-    case APP_WILL_MOUNT: {
23
-        // Register chat msg sound only on web
24
-        typeof APP !== 'undefined'
25
-            && store.dispatch(
22
+    case APP_WILL_MOUNT:
23
+        // Register the chat message sound on Web only because there's no chat
24
+        // on mobile.
25
+        typeof APP === 'undefined'
26
+            || store.dispatch(
26
                 registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
27
                 registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
27
         break;
28
         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));
29
+
30
+    case APP_WILL_UNMOUNT:
31
+        // Unregister the chat message sound on Web because it's registered
32
+        // there only.
33
+        typeof APP === 'undefined'
34
+            || store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
33
         break;
35
         break;
34
-    }
36
+
35
     case CONFERENCE_JOINED:
37
     case CONFERENCE_JOINED:
36
-        typeof APP !== 'undefined'
37
-            && _addChatMsgListener(action.conference, store);
38
+        typeof APP === 'undefined'
39
+            || _addChatMsgListener(action.conference, store);
38
         break;
40
         break;
39
     }
41
     }
40
 
42
 
49
  * new event listener will be registered.
51
  * new event listener will be registered.
50
  * @param {Dispatch} next - The redux dispatch function to dispatch the
52
  * @param {Dispatch} next - The redux dispatch function to dispatch the
51
  * specified action to the specified store.
53
  * specified action to the specified store.
52
- * @returns {void}
53
  * @private
54
  * @private
55
+ * @returns {void}
54
  */
56
  */
55
 function _addChatMsgListener(conference, { dispatch }) {
57
 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.
58
+    // XXX Currently, there's no need to remove the listener, because the
59
+    // JitsiConference instance cannot be reused. Hence, the listener will be
60
+    // gone with the JitsiConference instance.
59
     conference.on(
61
     conference.on(
60
         JitsiConferenceEvents.MESSAGE_RECEIVED,
62
         JitsiConferenceEvents.MESSAGE_RECEIVED,
61
         () => {
63
         () => {
62
-            if (!APP.UI.isChatVisible()) {
63
-                dispatch(playSound(INCOMING_MSG_SOUND_ID));
64
-            }
64
+            APP.UI.isChatVisible()
65
+                || dispatch(playSound(INCOMING_MSG_SOUND_ID));
65
         });
66
         });
66
 }
67
 }

+ 1
- 0
react/features/chat/sounds.web.js 查看文件

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

正在加载...
取消
保存