2018-05-01 04:43:47 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-05-16 15:03:10 +00:00
|
|
|
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../app';
|
|
|
|
import {
|
2018-05-21 20:52:30 +00:00
|
|
|
getParticipantPresenceStatus,
|
2018-05-21 21:40:15 +00:00
|
|
|
PARTICIPANT_JOINED,
|
2018-05-21 20:52:30 +00:00
|
|
|
PARTICIPANT_JOINED_SOUND_ID,
|
|
|
|
PARTICIPANT_LEFT,
|
|
|
|
PARTICIPANT_UPDATED
|
2018-05-16 15:03:10 +00:00
|
|
|
} from '../base/participants';
|
2017-05-19 22:35:10 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2018-05-16 15:03:10 +00:00
|
|
|
import {
|
|
|
|
playSound,
|
|
|
|
registerSound,
|
|
|
|
stopSound,
|
|
|
|
unregisterSound
|
|
|
|
} from '../base/sounds';
|
|
|
|
import {
|
|
|
|
CALLING,
|
2018-05-21 20:52:30 +00:00
|
|
|
CONNECTED_USER,
|
|
|
|
EXPIRED,
|
2018-05-16 15:03:10 +00:00
|
|
|
INVITED,
|
2018-05-21 20:52:30 +00:00
|
|
|
REJECTED,
|
2018-05-16 15:03:10 +00:00
|
|
|
RINGING
|
|
|
|
} from '../presence-status';
|
2017-05-19 22:35:10 +00:00
|
|
|
|
|
|
|
import { UPDATE_DIAL_IN_NUMBERS_FAILED } from './actionTypes';
|
2018-05-16 15:03:10 +00:00
|
|
|
import {
|
2018-05-21 20:52:30 +00:00
|
|
|
OUTGOING_CALL_EXPIRED_SOUND_ID,
|
|
|
|
OUTGOING_CALL_REJECTED_SOUND_ID,
|
|
|
|
OUTGOING_CALL_RINGING_SOUND_ID,
|
|
|
|
OUTGOING_CALL_START_SOUND_ID
|
2018-05-16 15:03:10 +00:00
|
|
|
} from './constants';
|
2018-05-21 20:52:30 +00:00
|
|
|
import { sounds } from './sounds';
|
2017-05-19 22:35:10 +00:00
|
|
|
|
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
|
|
|
|
2018-05-16 15:03:10 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
2018-05-21 20:52:30 +00:00
|
|
|
/**
|
|
|
|
* Maps the presence status with the ID of the sound that will be played when
|
|
|
|
* the status is received.
|
|
|
|
*/
|
|
|
|
const statusToRingtone = {
|
|
|
|
[CALLING]: OUTGOING_CALL_START_SOUND_ID,
|
|
|
|
[CONNECTED_USER]: PARTICIPANT_JOINED_SOUND_ID,
|
|
|
|
[EXPIRED]: OUTGOING_CALL_EXPIRED_SOUND_ID,
|
|
|
|
[INVITED]: OUTGOING_CALL_START_SOUND_ID,
|
|
|
|
[REJECTED]: OUTGOING_CALL_REJECTED_SOUND_ID,
|
|
|
|
[RINGING]: OUTGOING_CALL_RINGING_SOUND_ID
|
|
|
|
};
|
|
|
|
|
2017-05-19 22:35:10 +00:00
|
|
|
/**
|
2018-05-01 04:43:47 +00:00
|
|
|
* The middleware of the feature invite common to mobile/react-native and
|
|
|
|
* Web/React.
|
2017-05-19 22:35:10 +00:00
|
|
|
*
|
2018-05-01 04:43:47 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-05-19 22:35:10 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2018-05-16 15:03:10 +00:00
|
|
|
let oldParticipantPresence;
|
|
|
|
|
|
|
|
if (action.type === PARTICIPANT_UPDATED
|
|
|
|
|| action.type === PARTICIPANT_LEFT) {
|
|
|
|
oldParticipantPresence
|
2018-05-21 20:52:30 +00:00
|
|
|
= getParticipantPresenceStatus(
|
|
|
|
store.getState(),
|
|
|
|
action.participant.id);
|
2018-05-16 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 22:35:10 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2018-05-16 15:03:10 +00:00
|
|
|
case APP_WILL_MOUNT:
|
2018-05-21 20:52:30 +00:00
|
|
|
for (const [ soundId, sound ] of sounds.entries()) {
|
|
|
|
store.dispatch(registerSound(soundId, sound.file, sound.options));
|
|
|
|
}
|
2018-05-16 15:03:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APP_WILL_UNMOUNT:
|
2018-05-21 20:52:30 +00:00
|
|
|
for (const soundId of sounds.keys()) {
|
|
|
|
store.dispatch(unregisterSound(soundId));
|
|
|
|
}
|
2018-05-16 15:03:10 +00:00
|
|
|
break;
|
|
|
|
|
2018-05-21 21:40:15 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
2018-05-16 15:03:10 +00:00
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
case PARTICIPANT_UPDATED: {
|
|
|
|
const newParticipantPresence
|
2018-05-21 20:52:30 +00:00
|
|
|
= getParticipantPresenceStatus(
|
|
|
|
store.getState(),
|
|
|
|
action.participant.id);
|
2018-05-16 15:03:10 +00:00
|
|
|
|
|
|
|
if (oldParticipantPresence === newParticipantPresence) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-21 20:52:30 +00:00
|
|
|
const oldSoundId
|
|
|
|
= oldParticipantPresence
|
|
|
|
&& statusToRingtone[oldParticipantPresence];
|
|
|
|
const newSoundId
|
|
|
|
= newParticipantPresence
|
|
|
|
&& statusToRingtone[newParticipantPresence];
|
|
|
|
|
|
|
|
|
|
|
|
if (oldSoundId === newSoundId) {
|
2018-05-16 15:03:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-21 20:52:30 +00:00
|
|
|
if (oldSoundId) {
|
|
|
|
store.dispatch(stopSound(oldSoundId));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newSoundId) {
|
|
|
|
store.dispatch(playSound(newSoundId));
|
2018-05-16 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-05-19 22:35:10 +00:00
|
|
|
case UPDATE_DIAL_IN_NUMBERS_FAILED:
|
2017-06-15 00:40:51 +00:00
|
|
|
logger.error(
|
|
|
|
'Error encountered while fetching dial-in numbers:',
|
|
|
|
action.error);
|
2017-05-19 22:35:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|