muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.71k stars 3.95k forks source link

RTCMultiConnection 1.5 - WebRTC DataChannel insists it is always sent as JSON #136

Open RoundSparrow opened 10 years ago

RoundSparrow commented 10 years ago

Hi,

The library has logic that seems to always JSON encode to send normal messages over a DataChannel.

This isn't how other WebRTC libraries work.

            onmessage: function(e) {
                if (!e.data.size)
                    e.data = JSON.parse(e.data);

This code here basically says: if it isn't a fire transfer (no .size parameter), JSON.parse it. Similar logic is followed in incoming DataChannel messages.

This makes the library difficult to interface with other libraries (such as one written in C# or Python / Java / etc).. For my purpose, I edit out library to modify the behavior.

I think really this should be a setting that is exposed instead of hard-coded assumption that JSON is always used or involved. The WebRTC DataChannel does not require JSON....

Thanks for the library.

muaz-khan commented 10 years ago

It is planned to be fixed with SCTP data channels, very soon. AFAIK, chrome RTP-datachannels accepts only string data; that's why it is JSON-stringified all the time!

RoundSparrow commented 10 years ago

ok - but it DOES support string data... it's nto a requirement to JSON encode it. f I'm using a different WebRTC library on the receiver - it causes issues.

I suggest a Boolean that determines if the JSON ecoding is done or not... that way it's more like a library and I'm not having to go into the library code and rewrite the internals ;)

Happy new Year.

onyii5119 commented 10 years ago

RoundSparrow, all the languages you mentioned (C# or Python / Java / etc) support JSON notation. That is why in my own opinion JSON is best suited for that purpose.

Thanks.