我希望你们一切都好
我是 webRTC 的初学者,如果我的问题感觉像菜鸟,我很抱歉,但我想知道是否有任何适当的方法可以关闭对等点之间的连接,尤其是使用 simple-peer.js,期待您的精彩回复
这是我的示例反应代码,
if (navigator.getUserMedia) {
navigator.getUserMedia({ audio: { echoCancellation: true }, video: true }, stream => {
let peer = new Peer({
initiator: this.props.isInitiator,
stream
});
this.localStream.current.srcObject = stream;
this.localStream.current.play();
peer.on('signal', (data) => {
socket.emit('offer', { data: JSON.stringify(data), conversation_id: this.props.conversation_id })
});
socket.on('offer', (data) => {
peer.signal(JSON.parse(data))
})
socket.on('DESTROY-VIDEO-CALL-SESSION', () => {
stream.getTracks().forEach(track => track.stop());
peer.removeAllListeners();
peer.destroy();
});
peer.on('stream', (streamData) => {
this.remoteStream.current.srcObject = streamData;
this.remoteStream.current.play();
});
this.setState({
endCall: () => {
socket.emit('VIDEO-CALL-ENDED', this.props.conversation_id);
}
})
}, error => {
alert('Please allow video and audio permission to make this call')
});
}