flow(AbstractAudio): specific function types
This commit is contained in:
parent
04dff9059b
commit
4dbcaf851f
|
@ -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<Props> {
|
|||
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<Props> {
|
|||
* @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<Props> {
|
|||
* @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);
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/**
|
||||
* The audio source for the incoming chat message sound.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
export const INCOMING_MSG_SOUND_SRC = 'sounds/incomingMessage.wav';
|
||||
|
|
Loading…
Reference in New Issue