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

datachannel not working #1074

Open
maurosorrentino opened this issue Feb 24, 2024 · 6 comments
Open

datachannel not working #1074

maurosorrentino opened this issue Feb 24, 2024 · 6 comments
Labels

Comments

@maurosorrentino
Copy link

maurosorrentino commented Feb 24, 2024

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;

@ChristopheI
Copy link
Collaborator

Did you try "WebRTCGetStartedDataChannel" example ?

@maurosorrentino
Copy link
Author

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

@ris-work
Copy link

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
Copy link

ris-work commented Mar 20, 2024

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
Copy link

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.

@maurosorrentino
Copy link
Author

hi @ris-work , would you mind sharing your code on sorrentino.mauro95@gmail.com ? 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants