change videoConf saga to TS

This commit is contained in:
GleidsonDaniel 2023-03-08 17:01:04 -03:00
parent 60defec633
commit 1d144cf19c
5 changed files with 169 additions and 43 deletions

View File

@ -84,5 +84,10 @@ export const ENCRYPTION = createRequestTypes('ENCRYPTION', ['INIT', 'STOP', 'DEC
export const PERMISSIONS = createRequestTypes('PERMISSIONS', ['SET', 'UPDATE']);
export const ROLES = createRequestTypes('ROLES', ['SET', 'UPDATE', 'REMOVE']);
export const VIDEO_CONF = createRequestTypes('VIDEO_CONF', ['HANDLE_INCOMING_WEBSOCKET_MESSAGES']);
export const VIDEO_CONF = createRequestTypes('VIDEO_CONF', [
'HANDLE_INCOMING_WEBSOCKET_MESSAGES',
'SET',
'REMOVE',
'CLEAR',
'INIT_CALL'
]);

View File

@ -1,16 +1,50 @@
import { Action } from 'redux';
import { ICallInfo } from '../reducers/videoConf';
import { VIDEO_CONF } from './actionsTypes';
export interface IVideoConfGenericAction extends Action {
interface IHandleVideoConfIncomingWebsocketMessages extends Action {
data: any;
}
export type TActionUserTyping = IVideoConfGenericAction & Action;
export type TCallProps = { mic: boolean; cam: boolean; direct: boolean; roomId: string };
export function handleVideoConfIncomingWebsocketMessages(data: any): IVideoConfGenericAction {
export interface IVideoConfGenericAction extends Action {
payload: ICallInfo;
}
export type TActionVideoConf = IHandleVideoConfIncomingWebsocketMessages & IVideoConfGenericAction & Action;
export function handleVideoConfIncomingWebsocketMessages(data: any): IHandleVideoConfIncomingWebsocketMessages {
return {
type: VIDEO_CONF.HANDLE_INCOMING_WEBSOCKET_MESSAGES,
data
};
}
export function setVideoConfCall(payload: ICallInfo): IVideoConfGenericAction {
return {
type: VIDEO_CONF.SET,
payload
};
}
export function removeVideoConfCall(payload: ICallInfo): IVideoConfGenericAction {
return {
type: VIDEO_CONF.REMOVE,
payload
};
}
export function clearVideoConfCalls(): Action {
return {
type: VIDEO_CONF.CLEAR
};
}
export function initVideoCall(payload: TCallProps): Action & { payload: TCallProps } {
return {
type: VIDEO_CONF.INIT_CALL,
payload
};
}

View File

@ -1,5 +1,10 @@
import { TypedUseSelectorHook, useSelector } from 'react-redux';
import { select } from 'redux-saga/effects';
import { IApplicationState } from '../../definitions';
export const useAppSelector: TypedUseSelectorHook<IApplicationState> = useSelector;
export function* appSelector<TSelected>(selector: (state: IApplicationState) => TSelected): Generator<any, TSelected, TSelected> {
return yield select(selector);
}

View File

@ -1,38 +0,0 @@
import { takeLatest } from 'redux-saga/effects';
import { VIDEO_CONF } from '../actions/actionsTypes';
const handleVideoConfIncomingWebsocketMessages = function* handleVideoConfIncomingWebsocketMessages({ data }) {
const { action, params } = data.action;
if (!action || typeof action !== 'string') {
return;
}
if (!params || typeof params !== 'object' || !params.callId || !params.uid || !params.rid) {
return;
}
console.log(action, params);
// switch (action) {
// case 'call':
// return this.onDirectCall(params);
// case 'canceled':
// return this.onDirectCallCanceled(params);
// case 'accepted':
// return this.onDirectCallAccepted(params);
// case 'rejected':
// return this.onDirectCallRejected(params);
// case 'confirmed':
// return this.onDirectCallConfirmed(params);
// case 'join':
// return this.onDirectCallJoined(params);
// case 'end':
// return this.onDirectCallEnded(params);
// }
};
const root = function* root() {
yield takeLatest(VIDEO_CONF.HANDLE_INCOMING_WEBSOCKET_MESSAGES, handleVideoConfIncomingWebsocketMessages);
};
export default root;

120
app/sagas/videoConf.ts Normal file
View File

@ -0,0 +1,120 @@
import { Action } from 'redux';
import { call, takeLatest } from 'typed-redux-saga';
import { VIDEO_CONF } from '../actions/actionsTypes';
import { IVideoConfGenericAction, TCallProps } from '../actions/videoConf';
import i18n from '../i18n';
import { getSubscriptionByRoomId } from '../lib/database/services/Subscription';
import { appSelector } from '../lib/hooks';
import { callJitsi } from '../lib/methods';
import { compareServerVersion, showErrorAlert } from '../lib/methods/helpers';
import log from '../lib/methods/helpers/log';
import { videoConfJoin } from '../lib/methods/videoConf';
import { Services } from '../lib/services';
import { ICallInfo } from '../reducers/videoConf';
type TGenerator = Generator<IVideoConfGenericAction>;
function* onDirectCall(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallCanceled(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallAccepted(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallRejected(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallConfirmed(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallJoined(payload: ICallInfo): TGenerator {
return null;
}
function* onDirectCallEnded(payload: ICallInfo): TGenerator {
return null;
}
function* handleVideoConfIncomingWebsocketMessages({ data }: { data: any }) {
const { action, params } = data.action;
if (!action || typeof action !== 'string') {
return;
}
if (!params || typeof params !== 'object' || !params.callId || !params.uid || !params.rid) {
return;
}
const prop = { ...params, action };
switch (action) {
case 'call':
yield call(onDirectCall, prop);
break;
case 'canceled':
yield call(onDirectCallCanceled, prop);
break;
case 'accepted':
yield call(onDirectCallAccepted, prop);
break;
case 'rejected':
yield call(onDirectCallRejected, prop);
break;
case 'confirmed':
yield call(onDirectCallConfirmed, prop);
break;
case 'join':
yield call(onDirectCallJoined, prop);
break;
case 'end':
yield call(onDirectCallEnded, prop);
break;
}
}
function* initCall({ payload: { mic, cam, direct, roomId } }: { payload: TCallProps }) {
const serverVersion = yield* appSelector(state => state.server.version);
const isServer5OrNewer = compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '5.0.0');
if (isServer5OrNewer) {
try {
const videoConfResponse = yield* call(Services.videoConferenceStart, roomId);
if (videoConfResponse.success) {
if (direct) {
// callUser({ uid: data.calleeId, rid: roomId, callId: data.callId });
} else {
videoConfJoin(videoConfResponse.data.callId, cam, mic);
}
// setCalling(false);
}
} catch (e) {
// setCalling(false);
showErrorAlert(i18n.t('error-init-video-conf'));
log(e);
}
} else {
const sub = yield* call(getSubscriptionByRoomId, roomId);
if (sub) {
callJitsi({ room: sub, cam });
// setCalling(false);
}
}
}
interface IGenericAction extends Action {
type: string;
}
export default function* root(): Generator {
yield takeLatest<
IGenericAction & {
data: any;
}
>(VIDEO_CONF.HANDLE_INCOMING_WEBSOCKET_MESSAGES, handleVideoConfIncomingWebsocketMessages);
yield takeLatest<IGenericAction & { payload: TCallProps }>(VIDEO_CONF.INIT_CALL, initCall);
}