Skip to content

Commit

Permalink
fix(video stream): add video event type enum in CONSTANTS (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur-push authored Jan 17, 2024
1 parent a1c3956 commit ee392ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
5 changes: 4 additions & 1 deletion packages/restapi/src/lib/constantsV2.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -29,6 +29,9 @@ const CONSTANTS = {
},
},
},
VIDEO: {
EVENT: VideoEventType
},
ALPHA_FEATURES: ALPHA_FEATURES,
USER: { ENCRYPTION_TYPE: ENCRYPTION_TYPE },
};
Expand Down
14 changes: 7 additions & 7 deletions packages/restapi/src/lib/pushapi/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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({
Expand All @@ -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({
Expand Down
14 changes: 7 additions & 7 deletions packages/restapi/src/lib/pushstream/DataModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/restapi/src/lib/pushstream/pushStreamTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ee392ef

Please sign in to comment.