0

I want to use the Kurento WebRTC javascript client in my Java web application.

But I even cant manage to call a simple javascript function in my Java application. What am I missing?

var connector = this;

connector.test = function() {
    alert('Hello world!');
}

Here comes the Java Code:

import com.vaadin.ui.AbstractJavaScriptComponent;


@JavaScript({"rtc.js", "jquery-1.12.3.min.js"})
public class VideoCall extends AbstractJavaScriptComponent {

    public VideoCall() {

    }

    public void testMethod() {
        callFunction("test");
        //Page.getCurrent().getJavaScript().execute("alert('Hello world!')");
        System.out.println("testMethod executed!");
    }

}

When I uncommend

Page.getCurrent().getJavaScript().execute("alert('Hello world!')");

I get a window with the message "Hello world!". When I change test to foo as argument in callFunction I dont get an error message, although foo doesnt exist as function. Why does the code not work?

1 Answer 1

1

I assume the first code snippet you've shown there is the rtc.js file that you include using @JavaScript. What's missing from that file is that it should register itself as a connector for that particular Java class.

The file should look like this:

window.java_package_name_VideoCall = function() {
  var connector = this;

  connector.test = function() {
    alert('Hello world!');
  }
}

where java_package_name is the the package name of the VideoCall class with . replaced with _.

Sign up to request clarification or add additional context in comments.

2 Comments

Thx Leif, but still not working. Something else must be missing.
Really hard to help debug anything without further details. I would recommend that you check for errors in the Console or Network sections in the browser's developer tools, and in Vaadin's debug window that is opened if you add ?debug to the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.