diff --git a/packages/restapi/src/lib/constantsV2.ts b/packages/restapi/src/lib/constantsV2.ts index f3b993268..62d8521c5 100644 --- a/packages/restapi/src/lib/constantsV2.ts +++ b/packages/restapi/src/lib/constantsV2.ts @@ -1,6 +1,6 @@ import { ENV, MessageType, ALPHA_FEATURES, ENCRYPTION_TYPE } from './constants'; import { ChatListType } from './pushapi/pushAPITypes'; -import { STREAM } from './pushstream/pushStreamTypes'; +import { STREAM, VideoEventType } from './pushstream/pushStreamTypes'; import { ConditionType, GROUP_INVITER_ROLE, @@ -29,6 +29,9 @@ const CONSTANTS = { }, }, }, + VIDEO: { + EVENT: VideoEventType + }, ALPHA_FEATURES: ALPHA_FEATURES, USER: { ENCRYPTION_TYPE: ENCRYPTION_TYPE }, }; diff --git a/packages/restapi/src/lib/pushapi/video.ts b/packages/restapi/src/lib/pushapi/video.ts index 9a1495841..c595feb1b 100644 --- a/packages/restapi/src/lib/pushapi/video.ts +++ b/packages/restapi/src/lib/pushapi/video.ts @@ -6,7 +6,7 @@ import { Signer as PushSigner } from '../helpers'; import { Video as VideoV1, initVideoCallData } from '../video/Video'; import { VideoV2 } from '../video/VideoV2'; import { VideoInitializeOptions } from './pushAPITypes'; -import { VideoEvent, VideoEventType } from '../pushstream/pushStreamTypes'; +import { VideoEvent } from '../pushstream/pushStreamTypes'; import { produce } from 'immer'; import { endStream } from '../video/helpers/mediaToggle'; @@ -73,7 +73,7 @@ export class Video { const chatId = rules.access.data.chatId; // If the event is RequestVideo, update the video call 'data' state with the incoming call data - if (data.event === VideoEventType.RequestVideo) { + if (data.event === CONSTANTS.VIDEO.EVENT.REQUEST) { videoV1Instance.setData((oldData) => { return produce(oldData, (draft) => { draft.local.address = this.account; @@ -89,7 +89,7 @@ export class Video { // Check if the chatId from the incoming video event matches the chatId of the current video instance if (chatId && chatId === videoV1Instance.data.meta.chatId) { // If the event is DenyVideo, destroy the local stream & reset the video call data - if (data.event === VideoEventType.DenyVideo) { + if (data.event === CONSTANTS.VIDEO.EVENT.DENY) { // destroy the local stream if (videoV1Instance.data.local.stream) { endStream(videoV1Instance.data.local.stream); @@ -100,15 +100,15 @@ export class Video { // If the event is ApproveVideo or RetryApproveVideo, connect to the video if ( - data.event === VideoEventType.ApproveVideo || - data.event === VideoEventType.RetryApproveVideo + data.event === CONSTANTS.VIDEO.EVENT.APPROVE || + data.event === CONSTANTS.VIDEO.EVENT.RETRY_APPROVE ) { videoV1Instance.connect({ peerAddress: address, signalData: signal }); } // If the event is RetryRequestVideo and the current instance is the initiator, send a request if ( - data.event === VideoEventType.RetryRequestVideo && + data.event === CONSTANTS.VIDEO.EVENT.RETRY_REQUEST && videoV1Instance.isInitiator() ) { videoV1Instance.request({ @@ -121,7 +121,7 @@ export class Video { // If the event is RetryRequestVideo and the current instance is not the initiator, accept the request if ( - data.event === VideoEventType.RetryRequestVideo && + data.event === CONSTANTS.VIDEO.EVENT.RETRY_REQUEST && !videoV1Instance.isInitiator() ) { videoV1Instance.acceptRequest({ diff --git a/packages/restapi/src/lib/pushstream/DataModifier.ts b/packages/restapi/src/lib/pushstream/DataModifier.ts index 2c4cb62cd..b835ea278 100644 --- a/packages/restapi/src/lib/pushstream/DataModifier.ts +++ b/packages/restapi/src/lib/pushstream/DataModifier.ts @@ -400,19 +400,19 @@ export class DataModifier { ): VideoEventType { switch (currentVideoStatus) { case VideoCallStatus.INITIALIZED: - return VideoEventType.RequestVideo; + return VideoEventType.REQUEST; case VideoCallStatus.RECEIVED: - return VideoEventType.ApproveVideo; + return VideoEventType.APPROVE; case VideoCallStatus.CONNECTED: - return VideoEventType.ConnectVideo; + return VideoEventType.CONNECT; case VideoCallStatus.ENDED: - return VideoEventType.DisconnectVideo; + return VideoEventType.DISCONNECT; case VideoCallStatus.DISCONNECTED: - return VideoEventType.DenyVideo; + return VideoEventType.DENY; case VideoCallStatus.RETRY_INITIALIZED: - return VideoEventType.RetryRequestVideo; + return VideoEventType.RETRY_REQUEST; case VideoCallStatus.RETRY_RECEIVED: - return VideoEventType.RetryApproveVideo; + return VideoEventType.RETRY_APPROVE; default: throw new Error(`Unknown video call status: ${currentVideoStatus}`); } diff --git a/packages/restapi/src/lib/pushstream/pushStreamTypes.ts b/packages/restapi/src/lib/pushstream/pushStreamTypes.ts index 01cf61e7b..b72b26831 100644 --- a/packages/restapi/src/lib/pushstream/pushStreamTypes.ts +++ b/packages/restapi/src/lib/pushstream/pushStreamTypes.ts @@ -54,14 +54,14 @@ export enum GroupEventType { } export enum VideoEventType { - RequestVideo = 'video.request', - ApproveVideo = 'video.approve', - DenyVideo = 'video.deny', - ConnectVideo = 'video.connect', - DisconnectVideo = 'video.disconnect', + REQUEST = 'video.request', + APPROVE = 'video.approve', + DENY = 'video.deny', + CONNECT = 'video.connect', + DISCONNECT = 'video.disconnect', // retry events - RetryRequestVideo = 'video.retry.request', - RetryApproveVideo = 'video.retry.approve' + RETRY_REQUEST = 'video.retry.request', + RETRY_APPROVE = 'video.retry.approve' } export enum ProposedEventNames {