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 Label in Janus.js #462

Closed
oscarvadillog opened this issue Feb 10, 2020 · 9 comments
Closed

Datachannel Label in Janus.js #462

oscarvadillog opened this issue Feb 10, 2020 · 9 comments
Assignees
Labels
Milestone

Comments

@oscarvadillog
Copy link

oscarvadillog commented Feb 10, 2020

Observerd behavior

I'm using the plugin with the latest version of janus.js and I've detected a problem when receiving messages through the datachannel.

It seems that the data channel is opened properly and the plugin receives the messages, even the method emitReceivedMessage(...) is executed.

However, in janus.js we always expect to receive the label name of the datachannel (check here), and it seems that the plugin doesn't send it, so there is a crash in the janus.js file.

Do you think the plugin should send the label value or not? Must be something to fix at janus.js?

Platform information

  • Plugin version: 6.0.5
  • iOS version: 13
  • Xcode version: latest
@hthetiot
Copy link
Contributor

Yet another Janus related issue.... Last time was all streamId named "janus"...

so there is a crash in the janus.js file.

@oscarvadillog Can you give me more details about the "crash in the janus.js" if you could give a sample script to reproduce.

Note: Don't take my first phrase personaly, personaly I don't like of use Janus that why :)

@hthetiot hthetiot added the bug label Feb 11, 2020
@hthetiot hthetiot self-assigned this Feb 11, 2020
@hthetiot hthetiot added this to the 6.0.7 milestone Feb 11, 2020
@oscarvadillog
Copy link
Author

oscarvadillog commented Feb 12, 2020

The issue is when receiving a message via the Datachannel and the janus.js tries to evaluate event.target.label

var onDataChannelMessage = function(event) {
	Janus.log('Received message on data channel:', event);
	var label = event.target.label;
	pluginHandle.ondata(event.data, label);
}

@hthetiot please try to use the following script to reproduce the issue:

(function() {
    var script = document.createElement('script');
    script.onload = function () {
        var script = document.createElement('script');
        script.onload = function () {
            var server = "https://janus.conf.meetecho.com/janus";
            var janus = null;
            var echotest = null;
            var opaqueId = "echotest-"+Janus.randomString(12);
            Janus.init({debug: "all", callback: function() {
                janus = new Janus(
                    {
                        server: server,
                        success: function() {
                            janus.attach(
                                {
                                    plugin: "janus.plugin.echotest",
                                    opaqueId: opaqueId,
                                    success: function(pluginHandle) {
                                        echotest = pluginHandle;
                                        Janus.log("Plugin attached! (" + echotest.getPlugin() + ", id=" + echotest.getId() + ")");
                                        // Negotiate WebRTC
                                        var body = { "audio": true, "video": true };
                                        echotest.send({"message": body});
                                        Janus.debug("Trying a createOffer too (audio/video sendrecv)");
                                        echotest.createOffer(
                                            {
                                                media: { data: true },	// Let's negotiate data channels as well
                                                success: function(jsep) {
                                                    Janus.debug("Got SDP!");
                                                    Janus.debug(jsep);
                                                    echotest.send({"message": body, "jsep": jsep});

                                                    setInterval(function() {
                                                        echotest.data({
                                                            text: 'Sending msg via Datachannel...',
                                                            error: function(reason) { console.log(reason) },
                                                            success: function() {},
                                                        });
                                                    }, 5000);

                                                },
                                                error: function(error) {
                                                    Janus.error("WebRTC error:", error);
                                                }
                                            });
                                    },
                                    error: function(error) {
                                        console.error("  -- Error attaching plugin...", error);
                                    },
                                    onmessage: function(msg, jsep) {
                                        Janus.debug(" ::: Got a message :::");
                                        Janus.debug(msg);
                                        if(jsep !== undefined && jsep !== null) {
                                            Janus.debug("Handling SDP as well...");
                                            Janus.debug(jsep);
                                            echotest.handleRemoteJsep({jsep: jsep});
                                        }
                                        var result = msg["result"];
                                        if(result !== null && result !== undefined) {
                                            if(result === "done") {
                                                // The plugin closed the echo test
                                                return;
                                            }
                                        }
                                    },
                                    onlocalstream: function(stream) {
                                        Janus.debug(" ::: Got a local stream :::");
                                        Janus.debug(stream);
                                    },
                                    onremotestream: function(stream) {
                                        Janus.debug(" ::: Got a remote stream :::");
                                        Janus.debug(stream);
                                    },
                                    ondataopen: function(data) {
                                        Janus.log("The DataChannel is available!");
                                    },
                                    ondata: function(data) {
                                        Janus.debug("We got data from the DataChannel! " + data);
                                    },
                                    oncleanup: function() {
                                        Janus.log(" ::: Got a cleanup notification :::");
                                    }
                                });
                        },
                        error: function(error) {
                            Janus.error(error);
                        }
                    });
            }});
        };
        script.src = 'https://janus.conf.meetecho.com/janus.js';
        document.head.appendChild(script);
    };
    script.src = 'https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/6.4.0/adapter.min.js';
    document.head.appendChild(script);
})();

@hthetiot
Copy link
Contributor

hthetiot commented Feb 12, 2020

Thank you @oscarvadillog I will look into it when I have a moment, there is other active member is the community that will may also looks into it.

Keep you posted.

@hthetiot
Copy link
Contributor

event.target is not defined.
Screen Shot 2020-02-17 at 3 39 20 PM

@hthetiot
Copy link
Contributor

Here is a funny one event.target is readonly.

Screen Shot 2020-02-17 at 4 58 48 PM

@hthetiot
Copy link
Contributor

Screen Shot 2020-02-17 at 5 03 16 PM

Ok I have a fix I will make PR now.

@hthetiot
Copy link
Contributor

@oscarvadillog Can you test this PR (see instructions)

@hthetiot
Copy link
Contributor

@oscarvadillog Will be released on 6.0.7 once you confirm the fix.
Thank you.

@oscarvadillog
Copy link
Author

oscarvadillog commented Feb 17, 2020

It works like a charm - you rock @hthetiot ❤️

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

2 participants