From 4061bdb5e434b9ed86a0a867eba7c828321ec7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=B7=E5=B8=83=E7=BD=97=E7=85=9C?= <1056317718@qq.com> Date: Tue, 31 May 2022 23:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84=E7=A7=81=E4=BA=BA=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E9=80=9A=E8=AF=9D=E9=80=BB=E8=BE=91=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87:white=5Fcheck=5Fmark:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatMainComponent/ChatInput/ChatInput.tsx | 2 +- src/Components/ChatComponent/ChatRTC.tsx | 12 ++++++++++-- src/Utils/ChatSocket/ChatSocket.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Components/ChatComponent/ChatMainComponent/ChatInput/ChatInput.tsx b/src/Components/ChatComponent/ChatMainComponent/ChatInput/ChatInput.tsx index 292db14..24661a4 100644 --- a/src/Components/ChatComponent/ChatMainComponent/ChatInput/ChatInput.tsx +++ b/src/Components/ChatComponent/ChatMainComponent/ChatInput/ChatInput.tsx @@ -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 diff --git a/src/Components/ChatComponent/ChatRTC.tsx b/src/Components/ChatComponent/ChatRTC.tsx index c39411a..34e08fd 100644 --- a/src/Components/ChatComponent/ChatRTC.tsx +++ b/src/Components/ChatComponent/ChatRTC.tsx @@ -49,7 +49,7 @@ export class ChatRTC extends EventEmitter { offerModal!: null | { destroy: () => void; }; - candidateQueue!: Array; + candidateQueue: Array; useSecurity: boolean; security: string; @@ -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); @@ -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); @@ -211,7 +216,7 @@ export class ChatRTC extends EventEmitter { accept: PRIVATE_WEBRTC_ANSWER_TYPE.ACCEPT, sender: this.sender, receiver: this.receiver, - security: '[]', + security: '', }); } @@ -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] @@ -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)); } } diff --git a/src/Utils/ChatSocket/ChatSocket.ts b/src/Utils/ChatSocket/ChatSocket.ts index 4bad56b..df6fb16 100644 --- a/src/Utils/ChatSocket/ChatSocket.ts +++ b/src/Utils/ChatSocket/ChatSocket.ts @@ -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);