Elemental2 WebRTC createOffer and createAnswer are incorrect

119 views
Skip to first unread message

Craig Mitchell

unread,
Jul 15, 2025, 1:55:58 AMJul 15
to GWT Users
I'm trying to use Element2 to create a WebRTC connection.

In the elemental2.dom.RTCPeerConnection class, there are a bunch of createOffer and createAnswer methods that all return Promise<RTCSessionDescription>.

If I try to use them, I get a ClassCastException.  This is because GWT is trying to create the RTCSessionDescription from the JS object, and it can't.

I believe all these createOffer and createAnswer methods should be returning Promise<RTCSessionDescriptionInit> instead.

For reference, this is the Element2 RTCSessionDescription:
package elemental2.dom;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class RTCSessionDescription {
  public String sdp;
  public String type;
  public RTCSessionDescription() {}
  public RTCSessionDescription(RTCSessionDescriptionInit descriptionInitDict) {}
}

And this is the Element2 RTCSessionDescriptionInit:
package elemental2.dom;

import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsPropertyMap;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface RTCSessionDescriptionInit {
  @JsOverlay
  static RTCSessionDescriptionInit create() {
    return Js.uncheckedCast(JsPropertyMap.of());
  }

  @JsProperty
  String getSdp();

  @JsProperty
  String getType();

  @JsProperty
  void setSdp(String sdp);

  @JsProperty
  void setType(String type);
}

Is it somehow possible to fix up Elemental2 createOffer and createAnswer methods?

Craig Mitchell

unread,
Jul 15, 2025, 1:58:02 AMJul 15
to GWT Users
*Elemental2 (not Element2 🙂).  Ie:  https://github.com/google/elemental2

Craig Mitchell

unread,
Jul 15, 2025, 2:06:54 AMJul 15
to GWT Users
It's actually possible to work around the issue by casting.  So instead of:

peerConnection.createOffer()
  .then(sessionDesc -> {
    
// Use sessionDesc
    return null;
  })
  .catch_(error -> {
    DomGlobal.console.error("Error creating offer.", error);
    return null;
  });

I can do:

Promise<Any> promise = Js.cast(peerConnection.createOffer());
promise.then(result -> {
  RTCSessionDescriptionInit offerInit = Js.cast(result);
  RTCSessionDescription 
sessionDesc = new RTCSessionDescription(offerInit);
  // Use sessionDesc
  return null;
})
.catch_(error -> {
  DomGlobal.console.error("Error creating offer."error);
  return null;
});

And this works great.  But it would be nice to fix Elemental2.

Jens

unread,
Jul 15, 2025, 4:49:06 AMJul 15
to GWT Users
And this works great.  But it would be nice to fix Elemental2.

You have to file an issue against closure-compiler because elemental2 takes their definition: https://github.com/google/closure-compiler/blob/15c5dd492cbb9dcdfd24d01f75b64e3e9b2291eb/externs/browser/w3c_rtc.js#L3586C23-L3586C44

-- J. 

Craig Mitchell

unread,
Jul 15, 2025, 5:37:27 AMJul 15
to GWT Users

Craig Mitchell

unread,
Jul 19, 2025, 7:37:31 PMJul 19
to GWT Users
Now the good people at the closure-compiler have fixed the error ( https://github.com/google/closure-compiler/commit/5aadfa78592a2778ae4cac52613fb9238228b3e8 ), I see I can build a new version of Elemental2 locally ( https://github.com/google/elemental2?tab=readme-ov-file#build-gwt-compatible-maven-jar-files ).

It would be nice to get an offical Elemental2 build, and have it pushed to Maven.  It looks like one hasn't been done for 9 months, is there any offical Elemental2 release schedule?

Craig Mitchell

unread,
Aug 19, 2025, 7:40:32 PMAug 19
to GWT Users
Following up on my own comment:  A request for a new build with updated closure externs has been made:  https://github.com/google/elemental2/issues/175
Reply all
Reply to author
Forward
0 new messages