Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research on WebRTC #392

Open
Danie0918 opened this issue May 27, 2024 · 5 comments
Open

Research on WebRTC #392

Danie0918 opened this issue May 27, 2024 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@Danie0918
Copy link
Contributor

Danie0918 commented May 27, 2024

Through the Webrtc protocol, Neuron can realize peer-to-peer real-time communication, which will greatly expand the scope of Neuron applications.

@Danie0918 Danie0918 added the documentation Improvements or additions to documentation label May 27, 2024
@Danie0918 Danie0918 added this to Neuron May 27, 2024
@Danie0918 Danie0918 moved this to 📫Hold On in Neuron May 27, 2024
@Danie0918 Danie0918 moved this from 📫Hold On to 🆕 New in Neuron May 27, 2024
@Danie0918 Danie0918 moved this from 🆕 New to 🏗 In Progress in Neuron Jun 3, 2024
@Danie0918
Copy link
Contributor Author

Any update. @devchenyan

@devchenyan
Copy link

devchenyan commented Jun 16, 2024

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:

  • Implementations are available for all platforms. As long as the browser supports WebRTC, standard-based applications can run on any OS.
  • Secure and encrypted DTLS and SRTP connections.
  • P2P = end-to-end encryption.
  • Open source.

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.

image

The process of establishing a connection through ICE in WebRTC:
image

Integrating WebRTC involves addressing two key issues:

  • Signaling Server
    A signaling service based on HTTPS or WebSocket needs to be implemented to handle signaling.

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

  • STUN/TURN Server
    A service needs to be implemented to obtain the public IP address of the WebRTC endpoint and to provide data relay services when NAT traversal fails.
    The currently popular STUN/TURN server is coturn, which is used to set up STUN/TURN services.

In the same network environment, a STUN/TURN server is not required.

Implement WebRTC for establishing a connection and communication:

  1. Create RTCPeerConnection:
const peerConnection = new RTCPeerConnection(configuration);
  1. Set Up ICE Candidate Event:
peerConnection.onicecandidate = event => {
  if (event.candidate) {
    // Send candidate to remote peer
  }
};
  1. Create an Offer (Initiator) or Answer (Receiver):
  • Offer:
peerConnection.createOffer().then(offer => {
  return peerConnection.setLocalDescription(offer);
}).then(() => {
  // Send the offer to the remote peer
});
  • Answer:
peerConnection.setRemoteDescription(remoteOffer).then(() => {
  return peerConnection.createAnswer();
}).then(answer => {
  return peerConnection.setLocalDescription(answer);
}).then(() => {
  // Send the answer to the remote peer
});
  1. Exchange ICE Candidates:
    Exchange the ICE candidates received from onicecandidate event with the remote peer.

  2. Data Communication:
    For data transfer, use RTCDataChannel:

const dataChannel = peerConnection.createDataChannel("myDataChannel");
dataChannel.onmessage = event => {
  console.log("Data received:", event.data);
};

Protocol: #349

@Danie0918
Copy link
Contributor Author

Any update? @devchenyan

@devchenyan
Copy link

Any update? @devchenyan

Feasibility has been verified. The demo will be uploaded shortly.

The communication protocol design will reference WalletConnect and be added to the documentation.

@devchenyan
Copy link

devchenyan commented Jul 11, 2024

Demo:

Screen-2024-07-11-180459.mp4

Neuron can establish communication with the DApp and reuse WalletConnect's communication protocol design for business implementation.
#148

This also reuses part of the previous WalletConnect design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: 📫Hold On
Development

No branches or pull requests

2 participants