libpeer icon indicating copy to clipboard operation
libpeer copied to clipboard

recording example receives/records nothing

Open AleXoundOS opened this issue 3 years ago • 10 comments

Browser asks to select screencast capture source, I choose one to share. In console it prints just:

Listening 0.0.0.0:8000

No file gets created in the directory of executable (CWD). Tested both with google-chrome and chromium with the same result.

AleXoundOS avatar Nov 24 '21 17:11 AleXoundOS

Do you connect with internet? Because the default STUN server is 18.191.223.12

sepfy avatar Nov 25 '21 02:11 sepfy

Yes. I tracked down the problem and here is the workaround diff which makes example work (record.h264 gets saved):

--- a/examples/recording/index_html.h
+++ b/examples/recording/index_html.h
@@ -13,6 +13,7 @@ const char index_html[] = " \
   <body> \n \
     <video style='display:block; margin: 0 auto;' id='localVideo' autoplay muted></video> \n \
     <script> \n \
+      var counter=0; \n \
       function jsonRpc(payload, cb) { \n \
         var xhttp = new XMLHttpRequest(); \n \
         xhttp.onreadystatechange = function() { \n \
@@ -45,7 +46,14 @@ console.log(JSON.parse(atob(sdp))); \n\
         } \n \
       } \n \
       pc.onicecandidate = event => { \n \
-        if (event.candidate === null) { \n \
+        counter++; \n \
+        console.log(\"counter = \" + String(counter)); \n \
+        console.log(event); \n \
+        if (event.candidate === null || event.candidate.address.length > 15) { \n \
+          console.log(\"ignoring this event\") \n \
+        } \n \
+        else \n \
+        { \n \
           let sdp = pc.localDescription.sdp; \n \
           var payload = {\"jsonrpc\": \"2.0\", \"method\": \"call\", \"params\": btoa(sdp)}; \n \
           jsonRpc(payload, jsonRpcHandle); \n \

(counter is used only for debugging.)

AleXoundOS avatar Nov 25 '21 07:11 AleXoundOS

OK, Thanks!

sepfy avatar Nov 25 '21 12:11 sepfy

I have no experience with javascript and the workaround was found just empirically. It definitely needs a more correct approach.

AleXoundOS avatar Nov 25 '21 13:11 AleXoundOS

I see you ignoring the ice candidate which the length of address is larger than 15. I guess it is a mDNS address. I tried to remove it and transfer to a ipv4 address, but it still seems to have some problems. I will check that.

sepfy avatar Nov 26 '21 04:11 sepfy

I'm not only ignoring candidates which are not IPs basically, but since there is only one IP candidate, jsonRpc is called only once. Otherwise, setRemoteDescription was called 2 times what caused an error. Without my changes jsonRpc was not called at all, because the condition for calling was event.candidate === null (now it's the opposite).

AleXoundOS avatar Nov 26 '21 14:11 AleXoundOS

I used chrome://webrtc-internals for debugging.

AleXoundOS avatar Nov 26 '21 14:11 AleXoundOS

According to the onicecanidate API, if the event's candidate property is null, ICE gathering has finished. It should be waited until all candidates are obtained, then send the offer. So you don't get event with null candidate property?

sepfy avatar Nov 29 '21 05:11 sepfy

So you don't get event with null candidate property?

It seems the browser does not get event with null candidate property. Log without workaround:

11/29/2021, 2:07:23 PM	transceiverAdded
11/29/2021, 2:07:23 PM	createOffer
11/29/2021, 2:07:23 PM	negotiationneeded
11/29/2021, 2:07:23 PM	createOfferOnSuccess (type: "offer", 2 sections)
11/29/2021, 2:07:23 PM	setLocalDescription (type: "offer", 2 sections)
11/29/2021, 2:07:23 PM	setLocalDescriptionOnSuccess
11/29/2021, 2:07:23 PM	signalingstatechange
11/29/2021, 2:07:23 PM	transceiverModified
11/29/2021, 2:07:23 PM	icegatheringstatechange
11/29/2021, 2:07:23 PM	icecandidate (host)
11/29/2021, 2:07:23 PM	icecandidate (srflx)

When workaround is in use the log continues further with setRemoteDescription (type: "answer", 2 sections).

AleXoundOS avatar Nov 29 '21 11:11 AleXoundOS

After getting null candidate, the browser should call jsonRpc function to send the offer to recording program. When recording program accepts the offer and response an answer, browser should be callback to jsonRpcHandle and setRemoteDescription. I think the recording program doesn't response the answer, because mDNS parse failed or it need more time to resolve.

I created a branch to disable mDNS resolver. If possible, please try again. Thanks.

sepfy avatar Jan 02 '22 08:01 sepfy

This example is no longer supported

sepfy avatar Oct 22 '23 08:10 sepfy