2018-07-30 14:38:25 +00:00
|
|
|
// @flow
|
2017-02-06 21:32:03 +00:00
|
|
|
|
2017-01-20 18:11:11 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
2017-01-18 19:30:11 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../../base/app';
|
2017-01-18 19:30:11 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_FAILED,
|
|
|
|
CONFERENCE_LEFT,
|
2018-05-15 09:23:59 +00:00
|
|
|
CONFERENCE_JOINED,
|
2019-02-13 15:41:33 +00:00
|
|
|
SET_AUDIO_ONLY,
|
|
|
|
getCurrentConference
|
2017-03-27 09:39:10 +00:00
|
|
|
} from '../../base/conference';
|
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2017-01-18 19:30:11 +00:00
|
|
|
|
2018-07-30 14:38:25 +00:00
|
|
|
const { AudioMode } = NativeModules;
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
2018-08-01 12:31:18 +00:00
|
|
|
|
2017-01-18 19:30:11 +00:00
|
|
|
/**
|
2017-01-20 18:11:11 +00:00
|
|
|
* Middleware that captures conference actions and sets the correct audio mode
|
|
|
|
* based on the type of conference. Audio-only conferences don't use the speaker
|
|
|
|
* by default, and video conferences do.
|
2017-01-18 19:30:11 +00:00
|
|
|
*
|
2017-08-04 21:06:42 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-01-18 19:30:11 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-08-04 21:06:42 +00:00
|
|
|
MiddlewareRegistry.register(({ getState }) => next => action => {
|
2018-08-01 12:31:18 +00:00
|
|
|
const result = next(action);
|
2017-01-20 18:11:11 +00:00
|
|
|
|
|
|
|
if (AudioMode) {
|
2017-01-28 23:28:13 +00:00
|
|
|
let mode;
|
2017-01-20 18:11:11 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
case CONFERENCE_FAILED:
|
2019-02-13 15:41:33 +00:00
|
|
|
case CONFERENCE_LEFT: {
|
|
|
|
const conference = getCurrentConference(getState());
|
|
|
|
|
|
|
|
if (typeof conference === 'undefined') {
|
|
|
|
mode = AudioMode.DEFAULT;
|
|
|
|
}
|
|
|
|
|
2017-01-20 18:11:11 +00:00
|
|
|
break;
|
2019-02-13 15:41:33 +00:00
|
|
|
}
|
2017-01-20 18:11:11 +00:00
|
|
|
|
2018-05-15 09:23:59 +00:00
|
|
|
/*
|
|
|
|
* NOTE: We moved the audio mode setting from CONFERENCE_WILL_JOIN to
|
|
|
|
* CONFERENCE_JOINED because in case of a locked room, the app goes
|
|
|
|
* through CONFERENCE_FAILED state and gets to CONFERENCE_JOINED only
|
|
|
|
* after a correct password, so we want to make sure we have the correct
|
|
|
|
* audio mode set up when we finally get to the conf, but also make sure
|
|
|
|
* that the app is in the right audio mode if the user leaves the
|
|
|
|
* conference after the password prompt appears.
|
|
|
|
*/
|
|
|
|
case CONFERENCE_JOINED:
|
2017-08-02 15:00:51 +00:00
|
|
|
case SET_AUDIO_ONLY: {
|
2018-08-01 12:31:18 +00:00
|
|
|
const { audioOnly, conference }
|
|
|
|
= getState()['features/base/conference'];
|
|
|
|
|
|
|
|
conference
|
|
|
|
&& (mode = audioOnly
|
|
|
|
? AudioMode.AUDIO_CALL
|
|
|
|
: AudioMode.VIDEO_CALL);
|
2017-01-20 18:11:11 +00:00
|
|
|
break;
|
2017-08-02 15:00:51 +00:00
|
|
|
}
|
2017-01-20 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 21:06:42 +00:00
|
|
|
if (typeof mode !== 'undefined') {
|
2017-01-28 23:28:13 +00:00
|
|
|
AudioMode.setMode(mode)
|
|
|
|
.catch(err =>
|
2018-07-30 14:38:25 +00:00
|
|
|
logger.error(
|
2017-06-15 00:40:51 +00:00
|
|
|
`Failed to set audio mode ${String(mode)}: ${err}`));
|
2017-01-20 18:11:11 +00:00
|
|
|
}
|
2017-01-18 19:30:11 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 12:31:18 +00:00
|
|
|
return result;
|
2017-01-18 19:30:11 +00:00
|
|
|
});
|