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.
On Tuesday, 15 July 2025 at 3:58:02 pm UTC+10 Craig Mitchell wrote:
> *Elemental2 (not Element2 🙂). Ie: https://github.com/google/elemental2
>
> On Tuesday, 15 July 2025 at 3:55:58 pm UTC+10 Craig Mitchell wrote:
>
>> 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?
>>
>
--
You received this message because you are subscribed to the Google Groups "GWT
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/google-web-toolkit/31bbaeb7-babd-4100-8004-11d8ffded992n%40googlegroups.com.