Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Jun 12, 2023
2 parents 712a5e5 + 439fd96 commit 494916b
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions packages/restapi/src/lib/video/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export class Video {
if (isJSON(data)) {
const parsedData = JSON.parse(data);
if (parsedData.type === 'isVideoOn') {
console.log('IS VIDEO ON', parsedData.isVideoOn);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].video = parsedData.isVideoOn;
Expand All @@ -206,7 +205,6 @@ export class Video {
}

if (parsedData.type === 'isAudioOn') {
console.log('IS AUDIO ON', parsedData.isAudioOn);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].audio = parsedData.isAudioOn;
Expand All @@ -215,7 +213,10 @@ export class Video {
}

if (parsedData.type === 'endCall') {
console.log('END CALL', parsedData.endCall);
// destroy the peerInstance
this.peerInstance?.destroy();
this.peerInstance = null;

// destroy the local stream
if (this.data.local.stream) {
endStream(this.data.local.stream);
Expand All @@ -230,7 +231,6 @@ export class Video {
});

this.peerInstance.on('stream', (currentStream: MediaStream) => {
console.log('received incoming stream', currentStream);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].stream = currentStream;
Expand Down Expand Up @@ -273,8 +273,8 @@ export class Video {
'accept request',
'options',
options,
'localStream',
this.data.local.stream
'peerInstance',
this.peerInstance
);

// if peerInstance is not null -> acceptRequest/request was called before
Expand All @@ -283,6 +283,20 @@ export class Video {
return Promise.resolve();
}

// set videoCallInfo state with status 2 (call received)
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.local.address = senderAddress;
draft.incoming[0].address = recipientAddress;
draft.meta.chatId = chatId;
draft.meta.initiator.address = senderAddress;
draft.incoming[0].status = retry
? VideoCallStatus.RETRY_RECEIVED
: VideoCallStatus.RECEIVED;
draft.incoming[0].retryCount += retry ? 1 : 0;
});
});

this.peerInstance = new Peer({
initiator: false,
trickle: false,
Expand Down Expand Up @@ -344,7 +358,6 @@ export class Video {
if (isJSON(data)) {
const parsedData = JSON.parse(data);
if (parsedData.type === 'isVideoOn') {
console.log('IS VIDEO ON', parsedData.isVideoOn);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].video = parsedData.isVideoOn;
Expand All @@ -353,7 +366,6 @@ export class Video {
}

if (parsedData.type === 'isAudioOn') {
console.log('IS AUDIO ON', parsedData.isAudioOn);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].audio = parsedData.isAudioOn;
Expand All @@ -362,7 +374,10 @@ export class Video {
}

if (parsedData.type === 'endCall') {
console.log('END CALL', parsedData.endCall);
// destroy the peerInstance
this.peerInstance?.destroy();
this.peerInstance = null;

// destroy the local stream
if (this.data.local.stream) {
endStream(this.data.local.stream);
Expand All @@ -377,27 +392,12 @@ export class Video {
});

this.peerInstance.on('stream', (currentStream: MediaStream) => {
console.log('received incoming stream', currentStream);
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.incoming[0].stream = currentStream;
});
});
});

// set videoCallInfo state with status 2 (call received)
this.setData((oldData) => {
return produce(oldData, (draft) => {
draft.local.address = senderAddress;
draft.incoming[0].address = recipientAddress;
draft.meta.chatId = chatId;
draft.meta.initiator.address = senderAddress;
draft.incoming[0].status = retry
? VideoCallStatus.RETRY_RECEIVED
: VideoCallStatus.RECEIVED;
draft.incoming[0].retryCount += retry ? 1 : 0;
});
});
} catch (err) {
console.log('error in accept request', err);

Expand Down Expand Up @@ -464,7 +464,6 @@ export class Video {
this.peerInstance?.send(
JSON.stringify({ type: 'endCall', endCall: true })
);
this.peerInstance?.destroy();
} else {
// for disconnecting during status INITIALIZED, RECEIVED, RETRY_INITIALIZED, RETRY_RECEIVED
// send a notif to the other user signaling status = DISCONNECTED
Expand All @@ -486,6 +485,7 @@ export class Video {
}

// destroy the peerInstance
this.peerInstance?.destroy();
this.peerInstance = null;

// destroy the local stream
Expand All @@ -505,13 +505,6 @@ export class Video {
enableVideo(options: EnableVideoInputOptions): void {
const { state } = options || {};

console.log(
'enableVideo',
'current video',
this.data.local.video,
'requested state',
state
);
if (this.data.local.video !== state) {
// need to change the video state

Expand Down Expand Up @@ -540,15 +533,7 @@ export class Video {

enableAudio(options: EnableAudioInputOptions): void {
const { state } = options || {};

console.log(
'enableAudio',
'current audio',
this.data.local.audio,
'requested state',
state
);


if (this.data.local.audio !== state) {
// need to change the audio state

Expand Down

0 comments on commit 494916b

Please sign in to comment.