Skip to content

Commit

Permalink
fix: comments fic
Browse files Browse the repository at this point in the history
  • Loading branch information
arn4b committed Sep 14, 2023
1 parent b2a13e2 commit 1f9a753
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions packages/restapi/src/lib/spaceV2/acceptInvite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ export async function acceptInvite(
// set videoCallInfo state with status connected for the receiver's end
this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
const incomingIndex = getIncomingIndexFromAddress(
oldData.incomingPeerStreams,
const pendingIndex = getIncomingIndexFromAddress(
oldData.pendingPeerStreams,
recipientAddress
);
draft.incomingPeerStreams[incomingIndex].status = VideoCallStatus.CONNECTED;
draft.pendingPeerStreams[pendingIndex].status = VideoCallStatus.CONNECTED;
});
});
});
Expand All @@ -150,28 +150,29 @@ export async function acceptInvite(
if (isJSON(data)) {
const parsedData = JSON.parse(data);

if (parsedData.type === 'isVideoOn') {
console.log('IS VIDEO ON', parsedData.value);
this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
const incomingIndex = getIncomingIndexFromAddress(
oldData.incomingPeerStreams,
recipientAddress
);
draft.incomingPeerStreams[incomingIndex].video = parsedData.value;
});
});
}

if (parsedData.type === 'isAudioOn') {
console.log('IS AUDIO ON', parsedData.value);
console.log('IS AUDIO ON', parsedData.value)

this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
const incomingIndex = getIncomingIndexFromAddress(
oldData.incomingPeerStreams,
recipientAddress
);
draft.incomingPeerStreams[incomingIndex].audio = parsedData.value;
let arrayToUpdate = null;

// Check if the peer is in pendingPeerStreams
const indexInPending = draft.pendingPeerStreams.findIndex(peer => peer.address === recipientAddress);
if (indexInPending !== -1) {
arrayToUpdate = draft.pendingPeerStreams;
}

// Check if the peer is in incomingPeerStreams
const indexInIncoming = draft.incomingPeerStreams.findIndex(peer => peer.address === recipientAddress);
if (indexInIncoming !== -1) {
arrayToUpdate = draft.incomingPeerStreams;
}

// If the peer is found in either array, update the property
if (arrayToUpdate) {
arrayToUpdate[indexInIncoming !== -1 ? indexInIncoming : indexInPending].audio = parsedData.value;
}
});
});
}
Expand Down Expand Up @@ -242,15 +243,10 @@ export async function acceptInvite(
// remove stream from pendingPeerStreams and add it to incomingPeerStreams
this.setSpaceV2Data((oldData) => {
return produce(oldData, (draft) => {
draft.incomingPeerStreams.push(draft.pendingPeerStreams[pendingStreamIndex]);
const peerStream = draft.pendingPeerStreams[pendingStreamIndex];
peerStream.stream = currentStream;
draft.incomingPeerStreams.push(peerStream);
draft.pendingPeerStreams.splice(pendingStreamIndex, 1);

const incomingStreamIndex = getIncomingIndexFromAddress(
this.data.incomingPeerStreams,
recipientAddress
);

draft.incomingPeerStreams[incomingStreamIndex].stream = currentStream;
});
});
}
Expand Down

0 comments on commit 1f9a753

Please sign in to comment.