2022-10-04 10:52:09 +00:00
|
|
|
import { IStore } from '../app/types';
|
2022-04-06 02:13:39 +00:00
|
|
|
import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
|
2022-10-04 10:52:09 +00:00
|
|
|
import { IJitsiConference } from '../base/conference/reducer';
|
2017-11-21 22:45:14 +00:00
|
|
|
import {
|
|
|
|
JitsiConferenceEvents,
|
|
|
|
JitsiSIPVideoGWStatus
|
|
|
|
} from '../base/lib-jitsi-meet';
|
2022-10-04 10:52:09 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2017-11-21 22:45:14 +00:00
|
|
|
import {
|
|
|
|
showErrorNotification,
|
|
|
|
showNotification,
|
|
|
|
showWarningNotification
|
2022-10-04 10:52:09 +00:00
|
|
|
} from '../notifications/actions';
|
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
2017-11-21 22:45:14 +00:00
|
|
|
|
2019-08-21 14:50:00 +00:00
|
|
|
import {
|
|
|
|
SIP_GW_AVAILABILITY_CHANGED,
|
|
|
|
SIP_GW_INVITE_ROOMS
|
|
|
|
} from './actionTypes';
|
|
|
|
import logger from './logger';
|
2022-10-20 09:11:27 +00:00
|
|
|
import { ISipRoom, ISipSessionChangedEvent } from './types';
|
2017-11-21 22:45:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures conference video sip gw events and stores
|
|
|
|
* the global sip gw availability in redux or show appropriate notification
|
|
|
|
* for sip gw sessions.
|
|
|
|
* Captures invitation actions that create sip gw sessions or display
|
|
|
|
* appropriate error/warning notifications.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-04-06 02:13:39 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch }) => next => action => {
|
2017-11-21 22:45:14 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2022-04-06 02:13:39 +00:00
|
|
|
case CONFERENCE_JOIN_IN_PROGRESS: {
|
|
|
|
const { conference } = action;
|
2017-11-21 22:45:14 +00:00
|
|
|
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.VIDEO_SIP_GW_AVAILABILITY_CHANGED,
|
2022-10-04 10:52:09 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2017-11-21 22:45:14 +00:00
|
|
|
(...args) => dispatch(_availabilityChanged(...args)));
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.VIDEO_SIP_GW_SESSION_STATE_CHANGED,
|
2022-10-20 09:11:27 +00:00
|
|
|
(event: ISipSessionChangedEvent) => {
|
2017-11-21 22:45:14 +00:00
|
|
|
const toDispatch = _sessionStateChanged(event);
|
|
|
|
|
|
|
|
// sessionStateChanged can decide there is nothing to dispatch
|
|
|
|
if (toDispatch) {
|
|
|
|
dispatch(toDispatch);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-05-16 14:00:16 +00:00
|
|
|
case SIP_GW_INVITE_ROOMS:
|
|
|
|
_inviteRooms(action.rooms, action.conference, dispatch);
|
|
|
|
break;
|
2017-11-21 22:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals that sip gw availability had changed.
|
|
|
|
*
|
|
|
|
* @param {string} status - The new status of the service.
|
|
|
|
* @returns {{
|
|
|
|
* type: SIP_GW_AVAILABILITY_CHANGED,
|
|
|
|
* status: string
|
|
|
|
* }}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _availabilityChanged(status: string) {
|
|
|
|
return {
|
|
|
|
type: SIP_GW_AVAILABILITY_CHANGED,
|
|
|
|
status
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-05-16 14:00:16 +00:00
|
|
|
/**
|
|
|
|
* Processes the action from the actionType {@code SIP_GW_INVITE_ROOMS} by
|
|
|
|
* inviting rooms into the conference or showing an error message.
|
|
|
|
*
|
|
|
|
* @param {Array} rooms - The conference rooms to invite.
|
|
|
|
* @param {Object} conference - The JitsiConference to invite the rooms to.
|
|
|
|
* @param {Function} dispatch - The redux dispatch function for emitting state
|
|
|
|
* changes (queuing error notifications).
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
function _inviteRooms(rooms: ISipRoom[], conference: IJitsiConference, dispatch: IStore['dispatch']) {
|
2018-05-16 14:00:16 +00:00
|
|
|
for (const room of rooms) {
|
|
|
|
const { id: sipAddress, name: displayName } = room;
|
|
|
|
|
|
|
|
if (sipAddress && displayName) {
|
|
|
|
const newSession = conference
|
|
|
|
.createVideoSIPGWSession(sipAddress, displayName);
|
|
|
|
|
|
|
|
if (newSession instanceof Error) {
|
|
|
|
const e = newSession;
|
|
|
|
|
|
|
|
switch (e.message) {
|
|
|
|
case JitsiSIPVideoGWStatus.ERROR_NO_CONNECTION: {
|
|
|
|
dispatch(showErrorNotification({
|
|
|
|
descriptionKey: 'videoSIPGW.errorInvite',
|
|
|
|
titleKey: 'videoSIPGW.errorInviteTitle'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2018-05-16 14:00:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case JitsiSIPVideoGWStatus.ERROR_SESSION_EXISTS: {
|
|
|
|
dispatch(showWarningNotification({
|
|
|
|
titleKey: 'videoSIPGW.errorAlreadyInvited',
|
|
|
|
titleArguments: { displayName }
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2018-05-16 14:00:16 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error(
|
|
|
|
'Unknown error trying to create sip videogw session',
|
|
|
|
e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newSession.start();
|
|
|
|
} else {
|
|
|
|
logger.error(`No display name or sip number for ${
|
|
|
|
JSON.stringify(room)}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 22:45:14 +00:00
|
|
|
/**
|
|
|
|
* Signals that a session we created has a change in its status.
|
|
|
|
*
|
|
|
|
* @param {string} event - The event describing the session state change.
|
2021-11-04 21:10:43 +00:00
|
|
|
* @returns {Object|null} - A notification action.
|
2017-11-21 22:45:14 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function _sessionStateChanged(
|
2022-10-20 09:11:27 +00:00
|
|
|
event: ISipSessionChangedEvent) {
|
2017-11-21 22:45:14 +00:00
|
|
|
switch (event.newState) {
|
|
|
|
case JitsiSIPVideoGWStatus.STATE_PENDING: {
|
2017-12-11 18:33:09 +00:00
|
|
|
return showNotification({
|
|
|
|
titleKey: 'videoSIPGW.pending',
|
|
|
|
titleArguments: {
|
|
|
|
displayName: event.displayName
|
|
|
|
}
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.SHORT);
|
2017-11-21 22:45:14 +00:00
|
|
|
}
|
|
|
|
case JitsiSIPVideoGWStatus.STATE_FAILED: {
|
|
|
|
return showErrorNotification({
|
|
|
|
titleKey: 'videoSIPGW.errorInviteFailedTitle',
|
|
|
|
titleArguments: {
|
|
|
|
displayName: event.displayName
|
|
|
|
},
|
|
|
|
descriptionKey: 'videoSIPGW.errorInviteFailed'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG);
|
2017-11-21 22:45:14 +00:00
|
|
|
}
|
2018-05-16 14:00:16 +00:00
|
|
|
case JitsiSIPVideoGWStatus.STATE_OFF: {
|
|
|
|
if (event.failureReason === JitsiSIPVideoGWStatus.STATUS_BUSY) {
|
|
|
|
return showErrorNotification({
|
|
|
|
descriptionKey: 'videoSIPGW.busy',
|
|
|
|
titleKey: 'videoSIPGW.busyTitle'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG);
|
2018-05-16 14:00:16 +00:00
|
|
|
} else if (event.failureReason) {
|
|
|
|
logger.error(`Unknown sip videogw error ${event.newState} ${
|
|
|
|
event.failureReason}`);
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 22:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nothing to show
|
|
|
|
return null;
|
|
|
|
}
|