flow(AbstractAudio): specific function types
This commit is contained in:
parent
04dff9059b
commit
4dbcaf851f
|
@ -7,10 +7,10 @@ import { Component } from 'react';
|
||||||
* playback.
|
* playback.
|
||||||
*/
|
*/
|
||||||
export type AudioElement = {
|
export type AudioElement = {
|
||||||
pause: Function,
|
pause: () => void,
|
||||||
play: Function,
|
play: () => void,
|
||||||
setSinkId: ?Function
|
setSinkId?: string => void
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code AbstractAudio} component's property types.
|
* {@code AbstractAudio} component's property types.
|
||||||
|
@ -21,7 +21,7 @@ type Props = {
|
||||||
* A callback which will be called with {@code AbstractAudio} instance once
|
* A callback which will be called with {@code AbstractAudio} instance once
|
||||||
* the audio element is loaded.
|
* the audio element is loaded.
|
||||||
*/
|
*/
|
||||||
setRef: ?Function,
|
setRef?: ?AudioElement => void,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URL of a media resource to use in the element.
|
* 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);
|
this.setAudioElementImpl = this.setAudioElementImpl.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pause: () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to pause the playback of the media.
|
* Attempts to pause the playback of the media.
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
pause() {
|
pause(): void {
|
||||||
this._audioElementImpl && this._audioElementImpl.pause();
|
this._audioElementImpl && this._audioElementImpl.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
play: () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to being the playback of the media.
|
* Attempts to being the playback of the media.
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
play() {
|
play(): void {
|
||||||
this._audioElementImpl && this._audioElementImpl.play();
|
this._audioElementImpl && this._audioElementImpl.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
setAudioElementImpl: (?AudioElement) => void;
|
setAudioElementImpl: ?AudioElement => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the (reference to the) {@link AudioElement} object which implements
|
* Set the (reference to the) {@link AudioElement} object which implements
|
||||||
|
@ -90,15 +94,18 @@ export default class AbstractAudio extends Component<Props> {
|
||||||
* @protected
|
* @protected
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
setAudioElementImpl(element: ?AudioElement) {
|
setAudioElementImpl(element: ?AudioElement): void {
|
||||||
this._audioElementImpl = element;
|
this._audioElementImpl = element;
|
||||||
|
|
||||||
// setRef
|
// setRef
|
||||||
const { setRef } = this.props;
|
const { setRef } = this.props;
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
typeof setRef === 'function' && setRef(element ? this : null);
|
typeof setRef === 'function' && setRef(element ? this : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSinkId: string => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the sink ID (output device ID) on the underlying audio element.
|
* Sets the sink ID (output device ID) on the underlying audio element.
|
||||||
* NOTE: Currently, implemented only on Web.
|
* 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).
|
* @param {string} sinkId - The sink ID (output device ID).
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
setSinkId(sinkId: String) {
|
setSinkId(sinkId: string): void {
|
||||||
this._audioElementImpl
|
this._audioElementImpl
|
||||||
&& typeof this._audioElementImpl.setSinkId === 'function'
|
&& typeof this._audioElementImpl.setSinkId === 'function'
|
||||||
&& this._audioElementImpl.setSinkId(sinkId);
|
&& 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
|
* The audio ID of the audio element for which the {@link playAudio} action is
|
||||||
* triggered when new chat message is received.
|
* triggered when new chat message is received.
|
||||||
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const INCOMING_MSG_SOUND_ID = 'INCOMING_MSG_SOUND';
|
export const INCOMING_MSG_SOUND_ID = 'INCOMING_MSG_SOUND';
|
||||||
|
|
|
@ -19,22 +19,24 @@ declare var APP: Object;
|
||||||
*/
|
*/
|
||||||
MiddlewareRegistry.register(store => next => action => {
|
MiddlewareRegistry.register(store => next => action => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case APP_WILL_MOUNT: {
|
case APP_WILL_MOUNT:
|
||||||
// Register chat msg sound only on web
|
// Register the chat message sound on Web only because there's no chat
|
||||||
typeof APP !== 'undefined'
|
// on mobile.
|
||||||
&& store.dispatch(
|
typeof APP === 'undefined'
|
||||||
|
|| store.dispatch(
|
||||||
registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
|
registerSound(INCOMING_MSG_SOUND_ID, INCOMING_MSG_SOUND_SRC));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case APP_WILL_UNMOUNT: {
|
case APP_WILL_UNMOUNT:
|
||||||
// Register chat msg sound only on web
|
// Unregister the chat message sound on Web because it's registered
|
||||||
typeof APP !== 'undefined'
|
// there only.
|
||||||
&& store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
|
typeof APP === 'undefined'
|
||||||
|
|| store.dispatch(unregisterSound(INCOMING_MSG_SOUND_ID));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case CONFERENCE_JOINED:
|
case CONFERENCE_JOINED:
|
||||||
typeof APP !== 'undefined'
|
typeof APP === 'undefined'
|
||||||
&& _addChatMsgListener(action.conference, store);
|
|| _addChatMsgListener(action.conference, store);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,18 +51,17 @@ MiddlewareRegistry.register(store => next => action => {
|
||||||
* new event listener will be registered.
|
* new event listener will be registered.
|
||||||
* @param {Dispatch} next - The redux dispatch function to dispatch the
|
* @param {Dispatch} next - The redux dispatch function to dispatch the
|
||||||
* specified action to the specified store.
|
* specified action to the specified store.
|
||||||
* @returns {void}
|
|
||||||
* @private
|
* @private
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function _addChatMsgListener(conference, { dispatch }) {
|
function _addChatMsgListener(conference, { dispatch }) {
|
||||||
// XXX Currently there's no need to remove the listener, because
|
// XXX Currently, there's no need to remove the listener, because the
|
||||||
// conference instance can not be re-used. Listener will be gone with
|
// JitsiConference instance cannot be reused. Hence, the listener will be
|
||||||
// the conference instance.
|
// gone with the JitsiConference instance.
|
||||||
conference.on(
|
conference.on(
|
||||||
JitsiConferenceEvents.MESSAGE_RECEIVED,
|
JitsiConferenceEvents.MESSAGE_RECEIVED,
|
||||||
() => {
|
() => {
|
||||||
if (!APP.UI.isChatVisible()) {
|
APP.UI.isChatVisible()
|
||||||
dispatch(playSound(INCOMING_MSG_SOUND_ID));
|
|| dispatch(playSound(INCOMING_MSG_SOUND_ID));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* The audio source for the incoming chat message sound.
|
* The audio source for the incoming chat message sound.
|
||||||
|
*
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const INCOMING_MSG_SOUND_SRC = 'sounds/incomingMessage.wav';
|
export const INCOMING_MSG_SOUND_SRC = 'sounds/incomingMessage.wav';
|
||||||
|
|
Loading…
Reference in New Issue