From 4dbcaf851fffbb1b14033f831b64af6a6471dfae Mon Sep 17 00:00:00 2001 From: paweldomas Date: Tue, 27 Feb 2018 08:09:49 -0600 Subject: [PATCH] flow(AbstractAudio): specific function types --- .../base/media/components/AbstractAudio.js | 27 ++++++++----- react/features/chat/constants.js | 4 +- react/features/chat/middleware.js | 39 ++++++++++--------- react/features/chat/sounds.web.js | 1 + 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/react/features/base/media/components/AbstractAudio.js b/react/features/base/media/components/AbstractAudio.js index f5f0d4f9c..7919bcc66 100644 --- a/react/features/base/media/components/AbstractAudio.js +++ b/react/features/base/media/components/AbstractAudio.js @@ -7,10 +7,10 @@ import { Component } from 'react'; * playback. */ export type AudioElement = { - pause: Function, - play: Function, - setSinkId: ?Function -} + pause: () => void, + play: () => void, + setSinkId?: string => void +}; /** * {@code AbstractAudio} component's property types. @@ -21,7 +21,7 @@ type Props = { * A callback which will be called with {@code AbstractAudio} instance once * the audio element is loaded. */ - setRef: ?Function, + setRef?: ?AudioElement => void, /** * The URL of a media resource to use in the element. @@ -59,27 +59,31 @@ export default class AbstractAudio extends Component { this.setAudioElementImpl = this.setAudioElementImpl.bind(this); } + pause: () => void; + /** * Attempts to pause the playback of the media. * * @public * @returns {void} */ - pause() { + pause(): void { this._audioElementImpl && this._audioElementImpl.pause(); } + play: () => void; + /** * Attempts to being the playback of the media. * * @public * @returns {void} */ - play() { + play(): void { this._audioElementImpl && this._audioElementImpl.play(); } - setAudioElementImpl: (?AudioElement) => void; + setAudioElementImpl: ?AudioElement => void; /** * Set the (reference to the) {@link AudioElement} object which implements @@ -90,15 +94,18 @@ export default class AbstractAudio extends Component { * @protected * @returns {void} */ - setAudioElementImpl(element: ?AudioElement) { + setAudioElementImpl(element: ?AudioElement): void { this._audioElementImpl = element; // setRef const { setRef } = this.props; + // $FlowFixMe typeof setRef === 'function' && setRef(element ? this : null); } + setSinkId: string => void; + /** * Sets the sink ID (output device ID) on the underlying audio element. * NOTE: Currently, implemented only on Web. @@ -106,7 +113,7 @@ export default class AbstractAudio extends Component { * @param {string} sinkId - The sink ID (output device ID). * @returns {void} */ - setSinkId(sinkId: String) { + setSinkId(sinkId: string): void { this._audioElementImpl && typeof this._audioElementImpl.setSinkId === 'function' && this._audioElementImpl.setSinkId(sinkId); diff --git a/react/features/chat/constants.js b/react/features/chat/constants.js index 699a4a61f..25c5e6551 100644 --- a/react/features/chat/constants.js +++ b/react/features/chat/constants.js @@ -1,9 +1,7 @@ -/* eslint-disable no-unused-vars */ -import { playAudio } from '../base/media'; - /** * The audio ID of the audio element for which the {@link playAudio} action is * triggered when new chat message is received. + * * @type {string} */ export const INCOMING_MSG_SOUND_ID = 'INCOMING_MSG_SOUND'; diff --git a/react/features/chat/middleware.js b/react/features/chat/middleware.js index f8b0440b6..cfa5b923c 100644 --- a/react/features/chat/middleware.js +++ b/react/features/chat/middleware.js @@ -19,22 +19,24 @@ declare var APP: Object; */ MiddlewareRegistry.register(store => next => action => { switch (action.type) { - case APP_WILL_MOUNT: { - // Register chat msg sound only on web - typeof APP !== 'undefined' - && store.dispatch( + case APP_WILL_MOUNT: + // Register the chat message sound on Web only because there's no chat + // on mobile. + typeof APP === 'undefined' + || store.dispatch( registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC)); break; - } - case APP_WILL_UNMOUNT: { - // Register chat msg sound only on web - typeof APP !== 'undefined' - && store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID)); + + case APP_WILL_UNMOUNT: + // Unregister the chat message sound on Web because it's registered + // there only. + typeof APP === 'undefined' + || store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID)); break; - } + case CONFERENCE_JOINED: - typeof APP !== 'undefined' - && _addChatMsgListener(action.conference, store); + typeof APP === 'undefined' + || _addChatMsgListener(action.conference, store); break; } @@ -49,18 +51,17 @@ MiddlewareRegistry.register(store => next => action => { * new event listener will be registered. * @param {Dispatch} next - The redux dispatch function to dispatch the * specified action to the specified store. - * @returns {void} * @private + * @returns {void} */ function _addChatMsgListener(conference, { dispatch }) { - // XXX Currently there's no need to remove the listener, because - // conference instance can not be re-used. Listener will be gone with - // the conference instance. + // XXX Currently, there's no need to remove the listener, because the + // JitsiConference instance cannot be reused. Hence, the listener will be + // gone with the JitsiConference instance. conference.on( JitsiConferenceEvents.MESSAGE_RECEIVED, () => { - if (!APP.UI.isChatVisible()) { - dispatch(playSound(INCOMING_MSG_SOUND_ID)); - } + APP.UI.isChatVisible() + || dispatch(playSound(INCOMING_MSG_SOUND_ID)); }); } diff --git a/react/features/chat/sounds.web.js b/react/features/chat/sounds.web.js index 980276081..486ad14db 100644 --- a/react/features/chat/sounds.web.js +++ b/react/features/chat/sounds.web.js @@ -1,5 +1,6 @@ /** * The audio source for the incoming chat message sound. + * * @type {string} */ export const INCOMING_MSG_SOUND_SRC = 'sounds/incomingMessage.wav';