2022-07-27 10:28:10 +00:00
|
|
|
import { PARTICIPANT_ID_CHANGED } from '../participants/actionTypes';
|
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { set } from '../redux/functions';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
2019-11-25 12:31:08 +00:00
|
|
|
SET_NO_SRC_DATA_NOTIFICATION_UID,
|
2016-10-05 14:36:59 +00:00
|
|
|
TRACK_ADDED,
|
2017-11-09 21:59:31 +00:00
|
|
|
TRACK_CREATE_CANCELED,
|
|
|
|
TRACK_CREATE_ERROR,
|
2019-06-12 21:05:41 +00:00
|
|
|
TRACK_NO_DATA_FROM_SOURCE,
|
2016-10-05 14:36:59 +00:00
|
|
|
TRACK_REMOVED,
|
2020-12-08 14:01:16 +00:00
|
|
|
TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT,
|
2017-11-15 15:23:22 +00:00
|
|
|
TRACK_UPDATED,
|
|
|
|
TRACK_WILL_CREATE
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
2022-07-27 10:28:10 +00:00
|
|
|
interface ITrack {
|
|
|
|
isReceivingData: boolean;
|
2022-09-14 07:54:56 +00:00
|
|
|
jitsiTrack: any;
|
2022-07-27 10:28:10 +00:00
|
|
|
lastMediaEvent?: string;
|
|
|
|
local: boolean;
|
|
|
|
mediaType: string;
|
|
|
|
mirror: boolean;
|
|
|
|
muted: boolean;
|
|
|
|
participantId: string;
|
2022-08-11 18:56:01 +00:00
|
|
|
streamingStatus?: string;
|
2022-07-27 10:28:10 +00:00
|
|
|
videoStarted: boolean;
|
2022-09-08 09:52:36 +00:00
|
|
|
videoType?: string | null;
|
2022-07-27 10:28:10 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2021-11-26 08:11:23 +00:00
|
|
|
* Track type.
|
|
|
|
*
|
|
|
|
* @typedef {object} Track
|
|
|
|
* @property {JitsiLocalTrack|JitsiRemoteTrack} jitsiTrack - The associated
|
2017-11-13 22:10:54 +00:00
|
|
|
* {@code JitsiTrack} instance. Optional for local tracks if those are still
|
2021-11-26 08:11:23 +00:00
|
|
|
* being created (ie {@code getUserMedia} is still in progress).
|
2017-11-13 22:10:54 +00:00
|
|
|
* @property {Promise} [gumProcess] - If a local track is still being created,
|
|
|
|
* it will have no {@code JitsiTrack}, but a {@code gumProcess} set to a
|
|
|
|
* {@code Promise} with and extra {@code cancel()}.
|
|
|
|
* @property {boolean} local=false - If the track is local.
|
|
|
|
* @property {MEDIA_TYPE} mediaType=false - The media type of the track.
|
2017-04-05 05:18:41 +00:00
|
|
|
* @property {boolean} mirror=false - The indicator which determines whether the
|
|
|
|
* display/rendering of the track should be mirrored. It only makes sense in the
|
|
|
|
* context of video (at least at the time of this writing).
|
2017-11-13 22:10:54 +00:00
|
|
|
* @property {boolean} muted=false - If the track is muted.
|
|
|
|
* @property {(string|undefined)} participantId - The ID of the participant whom
|
|
|
|
* the track belongs to.
|
|
|
|
* @property {boolean} videoStarted=false - If the video track has already
|
|
|
|
* started to play.
|
|
|
|
* @property {(VIDEO_TYPE|undefined)} videoType - The type of video track if
|
|
|
|
* any.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer function for a single track.
|
|
|
|
*
|
|
|
|
* @param {Track|undefined} state - Track to be modified.
|
|
|
|
* @param {Object} action - Action object.
|
|
|
|
* @param {string} action.type - Type of action.
|
2020-12-08 14:01:16 +00:00
|
|
|
* @param {string} action.name - Name of last media event.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @param {string} action.newValue - New participant ID value (in this
|
|
|
|
* particular case).
|
|
|
|
* @param {string} action.oldValue - Old participant ID value (in this
|
|
|
|
* particular case).
|
|
|
|
* @param {Track} action.track - Information about track to be changed.
|
|
|
|
* @param {Participant} action.participant - Information about participant.
|
|
|
|
* @returns {Track|undefined}
|
|
|
|
*/
|
2022-07-27 10:28:10 +00:00
|
|
|
function track(state: ITrack, action: any) {
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case PARTICIPANT_ID_CHANGED:
|
|
|
|
if (state.participantId === action.oldValue) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
participantId: action.newValue
|
|
|
|
};
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRACK_UPDATED: {
|
|
|
|
const t = action.track;
|
|
|
|
|
|
|
|
if (state.jitsiTrack === t.jitsiTrack) {
|
|
|
|
// Make sure that there's an actual update in order to reduce the
|
|
|
|
// risk of unnecessary React Component renders.
|
|
|
|
for (const p in t) {
|
2022-07-27 10:28:10 +00:00
|
|
|
// @ts-ignore
|
2016-10-05 14:36:59 +00:00
|
|
|
if (state[p] !== t[p]) {
|
|
|
|
// There's an actual update.
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...t
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-12-08 14:01:16 +00:00
|
|
|
case TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT: {
|
|
|
|
const t = action.track;
|
|
|
|
|
|
|
|
if (state.jitsiTrack === t) {
|
|
|
|
if (state.lastMediaEvent !== action.name) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lastMediaEvent: action.name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-06-12 21:05:41 +00:00
|
|
|
case TRACK_NO_DATA_FROM_SOURCE: {
|
|
|
|
const t = action.track;
|
|
|
|
|
|
|
|
if (state.jitsiTrack === t.jitsiTrack) {
|
|
|
|
const isReceivingData = t.jitsiTrack.isReceivingData();
|
|
|
|
|
|
|
|
if (state.isReceivingData !== isReceivingData) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isReceivingData
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-07-27 10:28:10 +00:00
|
|
|
export type ITracksState = ITrack[];
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Listen for actions that mutate (e.g. Add, remove) local and remote tracks.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<ITracksState>('features/base/tracks', (state = [], action): ITracksState => {
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case PARTICIPANT_ID_CHANGED:
|
2019-06-12 21:05:41 +00:00
|
|
|
case TRACK_NO_DATA_FROM_SOURCE:
|
2020-12-08 14:01:16 +00:00
|
|
|
case TRACK_UPDATE_LAST_VIDEO_MEDIA_EVENT:
|
2016-10-05 14:36:59 +00:00
|
|
|
case TRACK_UPDATED:
|
2022-07-27 10:28:10 +00:00
|
|
|
return state.map((t: ITrack) => track(t, action));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-11-09 21:59:31 +00:00
|
|
|
case TRACK_ADDED: {
|
|
|
|
let withoutTrackStub = state;
|
|
|
|
|
|
|
|
if (action.track.local) {
|
|
|
|
withoutTrackStub
|
|
|
|
= state.filter(
|
2022-07-27 10:28:10 +00:00
|
|
|
(t: ITrack) => !t.local || t.mediaType !== action.track.mediaType);
|
2017-11-09 21:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [ ...withoutTrackStub, action.track ];
|
|
|
|
}
|
|
|
|
|
|
|
|
case TRACK_CREATE_CANCELED:
|
|
|
|
case TRACK_CREATE_ERROR: {
|
2022-07-27 10:28:10 +00:00
|
|
|
return state.filter((t: ITrack) => !t.local || t.mediaType !== action.trackType);
|
2017-11-09 21:59:31 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
case TRACK_REMOVED:
|
2022-07-27 10:28:10 +00:00
|
|
|
return state.filter((t: ITrack) => t.jitsiTrack !== action.track.jitsiTrack);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-11-15 15:23:22 +00:00
|
|
|
case TRACK_WILL_CREATE:
|
|
|
|
return [ ...state, action.track ];
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|
2019-10-03 08:15:49 +00:00
|
|
|
|
2022-07-27 10:28:10 +00:00
|
|
|
export interface INoSrcDataState {
|
2022-09-08 09:52:36 +00:00
|
|
|
noSrcDataNotificationUid?: string | number;
|
2022-07-27 10:28:10 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 08:15:49 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Listen for actions that mutate the no-src-data state, like the current notification id.
|
2019-10-03 08:15:49 +00:00
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<INoSrcDataState>('features/base/no-src-data', (state = {}, action): INoSrcDataState => {
|
2019-10-03 08:15:49 +00:00
|
|
|
switch (action.type) {
|
2019-11-25 12:31:08 +00:00
|
|
|
case SET_NO_SRC_DATA_NOTIFICATION_UID:
|
2019-11-22 14:02:59 +00:00
|
|
|
return set(state, 'noSrcDataNotificationUid', action.uid);
|
2019-10-03 08:15:49 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|