Open Danie0918 opened 1 month ago
Any update. @devchenyan
WebRTC (Web Real-Time Communication) is a technology that enables Web applications and sites to capture and optionally stream audio and/or video media, as well as to exchange arbitrary data between browsers without requiring an intermediary.
The main advantages of WebRTC are:
The set of standards that comprise WebRTC makes it possible to share data and perform teleconferencing peer-to-peer, without requiring that the user install plug-ins or any other third-party software.
Signaling Signaling uses an existing protocol, SDP (Session Description Protocol).
Connecting Uses STUN/TURN for connection and NAT traversal.
Securing Uses DTLS and SRTP to encrypt the transport layer.
Communicating Uses RTP and SCTP for peer-to-peer communication.
The process of establishing a connection through ICE in WebRTC:
Integrating WebRTC involves addressing two key issues:
In the same network environment, the signaling service can be integrated into Neuron, using Bluetooth as one of the communication channels.
https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API
In the same network environment, a STUN/TURN server is not required.
Implement WebRTC for establishing a connection and communication:
Create RTCPeerConnection:
const peerConnection = new RTCPeerConnection(configuration);
Set Up ICE Candidate Event:
peerConnection.onicecandidate = event => {
if (event.candidate) {
// Send candidate to remote peer
}
};
Create an Offer (Initiator) or Answer (Receiver):
peerConnection.createOffer().then(offer => {
return peerConnection.setLocalDescription(offer);
}).then(() => {
// Send the offer to the remote peer
});
peerConnection.setRemoteDescription(remoteOffer).then(() => {
return peerConnection.createAnswer();
}).then(answer => {
return peerConnection.setLocalDescription(answer);
}).then(() => {
// Send the answer to the remote peer
});
Exchange ICE Candidates:
Exchange the ICE candidates received from onicecandidate
event with the remote peer.
Data Communication:
For data transfer, use RTCDataChannel
:
const dataChannel = peerConnection.createDataChannel("myDataChannel");
dataChannel.onmessage = event => {
console.log("Data received:", event.data);
};
Protocol: https://github.com/Magickbase/neuron-public-issues/issues/349
Through the Webrtc protocol, Neuron can realize peer-to-peer real-time communication, which will greatly expand the scope of Neuron applications.