Skip to content

Commit

Permalink
refactor: comments rft
Browse files Browse the repository at this point in the history
  • Loading branch information
arn4b committed Sep 14, 2023
1 parent 41cdac5 commit 703ad98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 53 deletions.
54 changes: 4 additions & 50 deletions packages/restapi/src/lib/spaceV2/acceptInvite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { produce } from 'immer';
import { initSpaceV2Data, type SpaceV2 } from './SpaceV2';
import sendSpaceNotification from './helpers/sendSpaceNotification';

import { SPACE_ACCEPT_REQUEST_TYPE, SPACE_DISCONNECT_TYPE, SPACE_REQUEST_TYPE } from '../payloads/constants';
import { SPACE_ACCEPT_REQUEST_TYPE, SPACE_DISCONNECT_TYPE } from '../payloads/constants';
import { VideoCallStatus } from '../types';

// imports from Video
import getIncomingIndexFromAddress from '../video/helpers/getIncomingIndexFromAddress';
import getConnectedAddresses from '../video/helpers/getConnectedAddresses';
import getConnectToAddresses from '../video/helpers/getConnectToAddresses';
import isJSON from '../video/helpers/isJSON';
import { endStream } from '../video/helpers/mediaToggle';
import { getIceServerConfig } from '../video/helpers/getIceServerConfig';
Expand Down Expand Up @@ -136,23 +134,6 @@ export async function acceptInvite(
})
);

// send the addresses the local peer is connected to remote peer
const connectedAddresses = getConnectedAddresses({
incomingPeers: this.data.incomingPeerStreams,
});

console.log(
'ACCEPT REQUEST - SENDING THE CONNECTED ADDRESSES',
'connectedAddresses',
connectedAddresses
);
peerConnection.send(
JSON.stringify({
type: 'connectedAddresses',
value: connectedAddresses,
})
);

// set videoCallInfo state with status connected for the receiver's end
this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
Expand All @@ -169,36 +150,6 @@ export async function acceptInvite(
if (isJSON(data)) {
const parsedData = JSON.parse(data);

if (parsedData.type === 'connectedAddresses') {
console.log(
'ACCEPT REQUEST - RECEIVING CONNECTED ADDRESSES',
'CONNECTED ADDRESSES',
parsedData.value
);

const receivedConnectedAddresses = parsedData.value;
const localConnectedAddresses = getConnectedAddresses({
incomingPeers: this.data.incomingPeerStreams,
});

// find out the address to which local peer is not connected to but the remote peer is
// then connect with them
const connectToAddresses = getConnectToAddresses({
localAddress: senderAddress,
localConnectedAddresses,
receivedConnectedAddresses,
});
this.request({
senderAddress,
recipientAddress: connectToAddresses,
spaceId,
details: {
type: SPACE_REQUEST_TYPE.ESTABLISH_MESH,
data: {},
},
});
}

if (parsedData.type === 'isVideoOn') {
console.log('IS VIDEO ON', parsedData.value);
this.setSpaceV2Data((oldData) => {
Expand Down Expand Up @@ -288,8 +239,11 @@ export async function acceptInvite(
// this.data.pendingPeerStreams[pendingIndex].audio
// );

// remove stream from pendingPeerStreams and add it to incomingPeerStreams
this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
draft.incomingPeerStreams.push(draft.pendingPeerStreams[incomingIndex]);
draft.pendingPeerStreams.splice(incomingIndex, 1);
draft.incomingPeerStreams[incomingIndex].stream = currentStream;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface SpaceInfoType {
signalData: any;
status: VideoCallStatus;
env?: ENV;
callType?: VIDEO_CALL_TYPE;
callDetails?: CallDetailsType;
}

Expand Down Expand Up @@ -50,7 +49,6 @@ const sendSpaceNotification = async (
status,
signalData = null,
env = Constants.ENV.PROD,
callType = VIDEO_CALL_TYPE.PUSH_VIDEO,
callDetails
}: SpaceInfoType
) => {
Expand Down Expand Up @@ -93,7 +91,7 @@ const sendSpaceNotification = async (
cta: '',
img: '',
additionalMeta: {
type: `${callType}+1`,
type: `${VIDEO_CALL_TYPE.PUSH_SPACE}+1`,
data: JSON.stringify(spaceData),
},
},
Expand Down

0 comments on commit 703ad98

Please sign in to comment.