Joe
Joe

Reputation: 1

How to use RTCPeerConnection to create an offer to share between peers for video calling

I would like to know where I can find documentation about the Agora RTCPeerConnection. I have written the following code to create and share offer between two peers:

  peerConnection = new RTCPeerConnection(servers);

      let offer= peerConnection.createOffer();
      peerConnection.setLocalDescription(offer);
      console.log("Offer: ",offer)

When I print the offer to the console, it shows:

   Offer:  Promise {<pending>}[[Prototype]]: Promise[[PromiseState]]: "fulfilled"[[PromiseResult]]: RTCSessionDescription

But I don't know how to just print the value of the offer (the sdp)

But I don't know how to just print the value of the offer (the sdp) I want to share the offer (its value) to the other peer

Upvotes: 0

Views: 523

Answers (1)

The KNVB
The KNVB

Reputation: 3844

To answer the first question, replace the following statement :

 let offer= peerConnection.createOffer();

with

  let offer=await peerConnection.createOffer();

To solve the second problem, you have to write a server-side program to act as a signal server to forward the offer to other peers. You can use the web socket to connect to the server-side program to send the offer to a remote peer and receive the offer from a remote peer.

By the way, you have better use the below link to use the new API to establish the connection.

https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Perfect_negotiation

Upvotes: 0

Related Questions