Skip to content

Commit

Permalink
新的私人视频通话逻辑测试通过:white_check_mark:
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1ny committed May 31, 2022
1 parent 459dfb3 commit 4061bdb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default function ChatInput(props: ChatInputProps) {
},
getContainer: getMainContent,
});
(chatRtc as ChatRTC).createOffer(
(chatRtc as ChatRTC).callRemote(
props.nowChattingId,
decodeJWT(store.getState().authToken).username,
modal
Expand Down
12 changes: 10 additions & 2 deletions src/Components/ChatComponent/ChatRTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ChatRTC extends EventEmitter {
offerModal!: null | {
destroy: () => void;
};
candidateQueue!: Array<any>;
candidateQueue: Array<any>;
useSecurity: boolean;
security: string;

Expand All @@ -64,6 +64,7 @@ export class ChatRTC extends EventEmitter {
this.remoteStream = null;
this.useSecurity = false;
this.security = '[]';
this.candidateQueue = new Array();

this.socket.on('ON_PRIVATE_WEBRTC_REQUEST', (msg) => {
this.responseCall(msg);
Expand Down Expand Up @@ -109,6 +110,10 @@ export class ChatRTC extends EventEmitter {
this.createAnswer(msg.sdp);
});

this.socket.on('ON_PRIVATE_WEBRTC_ANSWER', (msg) => {
this.receiveAnswer(msg.sdp);
});

this.socket.on('ON_PRIVATE_WEBRTC_CANDIDATE', (msg) => {
if (msg.sender === this.sender && msg.receiver === this.receiver) {
this.handleCandidate(msg);
Expand Down Expand Up @@ -211,7 +216,7 @@ export class ChatRTC extends EventEmitter {
accept: PRIVATE_WEBRTC_ANSWER_TYPE.ACCEPT,
sender: this.sender,
receiver: this.receiver,
security: '[]',
security: '',
});
}

Expand Down Expand Up @@ -283,9 +288,11 @@ export class ChatRTC extends EventEmitter {
type: 'offer',
})
);

while (this.candidateQueue.length > 0) {
this.peer.addIceCandidate(this.candidateQueue.shift());
}

this.localStream = new MediaStream();
this.localStream.addTrack(
(await getDeviceStream(DEVICE_TYPE.VIDEO_DEVICE)).getVideoTracks()[0]
Expand Down Expand Up @@ -443,6 +450,7 @@ export class ChatRTC extends EventEmitter {
this.localStream = null;
this.remoteStream = null;
if (this.peer) this.peer.close();
this.candidateQueue = new Array();
store.dispatch(setCallStatus(CALL_STATUS_FREE));
}
}
8 changes: 8 additions & 0 deletions src/Utils/ChatSocket/ChatSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ export class ChatSocket extends EventEmitter {
store.dispatch(setMessageHistory(ADD_MESSAGE_HISTORY, msg.data.message));
this.emit('MESSAGE_SENDER_OK', msg.data.message.toId);
break;
case ChatWebSocketType.CHAT_PRIVATE_WEBRTC_REQUEST:
// NOTE: 接到私人视频通话请求
this.emit('ON_PRIVATE_WEBRTC_REQUEST', msg);
break;
case ChatWebSocketType.CHAT_PRIVATE_WEBRTC_RESPONSE:
// NOTE: 接到私人视频通话响应
this.emit('ON_PRIVATE_WEBRTC_RESPONSE', msg);
break;
case ChatWebSocketType.CHAT_PRIVATE_WEBRTC_OFFER:
// NOTE: 接到 OFFER 请求
this.emit('ON_PRIVATE_WEBRTC_OFFER', msg);
Expand Down

0 comments on commit 4061bdb

Please sign in to comment.