sipsorcery icon indicating copy to clipboard operation
sipsorcery copied to clipboard

datachannel not working

Open maurosorrentino opened this issue 11 months ago • 6 comments

can you please tell me how you made the datachannel work? I successfully exchanged everything needed (offer and answer have m=datachannel) and the connection state of peer connection is connected. I am only creating 1 datachannel before the offer, rdc.readyState is open but I'm not able to send messages for some reasons. if I look at rdc.negotiated in ondatachannel the answerer tells me it's false, how do I make it pass to true? offer and answer have both nm=application 9 UDP/DTLS/SCTP webrtc-datachannel and the state of peer connection is connected (I even tested it by closing the connection to the server and make a brand new peer connection and when that happens the other client says peer connection state is disconnected)

peerConnection.ondatachannel += (rdc) => { rdc.send("test"); Console.WriteLine($"dc state {rdc.readyState}"); // returns open Console.WriteLine($"datac state {rdc.negotiated}"); // returns false this.rdc = rdc; rdc.onopen += () => Console.WriteLine($"Data channel {rdc.label} open."); // not working rdc.onclose += () => Console.WriteLine($"Data channel {rdc.label} closed."); // the following never fires rdc.onmessage += (datachan, type, data) => { Console.WriteLine($"type {type}"); string msg = Encoding.UTF8.GetString(data); Console.WriteLine($"Data channel {datachan.label} message {type} received: {msg}."); // Do a string echo. rdc.send($"echo: {msg}"); }; }; return peerConnection;

maurosorrentino avatar Feb 24 '24 15:02 maurosorrentino

Did you try "WebRTCGetStartedDataChannel" example ?

ChristopheI avatar Mar 04 '24 09:03 ChristopheI

Hi, thank you for your answer. Yes, I took the code from there

maurosorrentino avatar Mar 04 '24 13:03 maurosorrentino

From what I've seen, the RTCDataChannel.onopen event does not fire. Can someone confirm whether this is the case for them too? onmessage fires properly whenever there is a message. It becomes difficult to start an action when the DC is open, now... Unfortunately, I had to move it to onmessage as a temp workaround.

All my code is based on the WebRTC DataChannel 'Getting Started'.

Thank you.

ris-work avatar Mar 20 '24 18:03 ris-work

A temporary workaround that works, but if you like living dangerously:

pc.ondatachannel += (rdc) =>
            { // Put it here
                rdc.onopen += () => logger.LogDebug($"Data channel {rdc.label} opened."); // Instead of here
                rdc.onclose += () => logger.LogDebug($"Data channel {rdc.label} closed.");
                rdc.onmessage += (datachan, type, data) =>
                {
                }
            }

ris-work avatar Mar 20 '24 18:03 ris-work

I can confirm that onopen at least fires, but at the wrong time, much later, at least on FreeBSD. SipSorcery works wonderfully (i.e. without major issues) on FreeBSD on dotnet 8 (pkg/latest) BTW. I think it has something to do with deadlocks or resource exhaustion. It takes minutes to fire and the performance is abysmal (nearly 25Mbps, megabits or 3.13MB/s (megabytes)) on a third generation intel. Since async is basically micro/lightweight state machines, I have also encountered similar issues on Rust and webrtc-rs where something blocks something else from happening.

ris-work avatar Mar 26 '24 11:03 ris-work

hi @ris-work , would you mind sharing your code on [email protected] ? to me also onmessage doesn't work and I don't understand why, I took the how to use code from their example. I didn't have much time this month to look into this though

maurosorrentino avatar Mar 31 '24 13:03 maurosorrentino