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);