Magickbase / neuron-public-issues

Neuron Issues
4 stars 3 forks source link

Research on WebRTC #392

Open Danie0918 opened 1 month ago

Danie0918 commented 1 month ago

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

Danie0918 commented 2 weeks ago

Any update. @devchenyan

devchenyan commented 1 week ago

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.

image

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

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:

  1. Create RTCPeerConnection:

    const peerConnection = new RTCPeerConnection(configuration);
  2. Set Up ICE Candidate Event:

    peerConnection.onicecandidate = event => {
    if (event.candidate) {
    // Send candidate to remote peer
    }
    };
  3. Create an Offer (Initiator) or Answer (Receiver):

    • Offer:
      peerConnection.createOffer().then(offer => {
      return peerConnection.setLocalDescription(offer);
      }).then(() => {
      // Send the offer 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: https://github.com/Magickbase/neuron-public-issues/issues/349