ECMAScript icon indicating copy to clipboard operation
ECMAScript copied to clipboard

GDNative overridden modules issue (WebRTC)

Open lewiji opened this issue 4 years ago • 6 comments

Hi,

This is a bit of an obscure issue, I have a workaround, but I want to debug it. I'm not sure where to start looking.

I'm using the webrtc-native GDNativeLibrary from: https://github.com/godotengine/webrtc-native

To allow native webrtc on windows/linux.

I've compiled the library from source. This supplies Godot with a native program for doing WebRTC calls outside of HTML5 builds. It does so by supplying native binary implementations for the Godot WebRTCPeerConnection and WebRTCDataChannel objects, via WebRTCPeerConnectionGDNative and WebRTCDataChannelGDNative.

The method initialize(Dictionary options) on WebRTCPeerConnection fails when calling from ECMAScript with the following error:

const peer = new godot.WebRTCPeerConnection();
peer.initialize({});

Output:

E 0:00:02.059   initialize: Condition "interface == __null" is true. Returned: ERR_UNCONFIGURED
  <C++ Source>  modules/webrtc/webrtc_peer_connection_gdnative.cpp:74 @ initialize()

The interface variable is set in the godot/modules/webrtc/webrtc_peer_connection_gdnative.cpp class in the method set_native_webrtc_peer_connection, which is called by godot/modules/gdnative/net/webrtc_gdnative.cpp when a native implementation has been found, via a macro:

void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *p_impl) {
#ifdef WEBRTC_GDNATIVE_ENABLED
	((WebRTCPeerConnectionGDNative *)p_obj)->set_native_webrtc_peer_connection(p_impl);
#endif
}

Now the reason I think this is a bug in the ECMAScript module is that if I create a GDScript file webrtc_wrapper.gd:

extends Node

func initialize(options: Dictionary) -> WebRTCPeerConnection:
  var peer = WebRTCPeerConnection.new()
  peer.initialize(options)
  return peer

Set that GDscript as an Autoload singleton, and then call the following from my ECMAScript:

const webWrapper = this.get_node("/root/WebrtcWrapper");

const peer = webWrapper.call("initialize", {});

The initialize call executes correctly and I can continue to work with the returned peer object in ECMAScript.

So, for now, I have a workaround, but I'm puzzled why it's not working with ECMAScript, and wondered if someone could point me in the right direction, as I'm pretty new to GDNative and how it works. I wonder if for some reason the ECMAScript module is calling the unimplemented version of WebRTCPeerConnection rather than the GDNative version.

lewiji avatar Nov 20 '20 09:11 lewiji

I have added a minimum reproduction project here:

https://github.com/lewispollard/godot-ecmascript-webrtc-native-bug

I've included 64 bit Linux binaries via git LFS however if you're not on this platform or don't want to run my binaries for security reasons you'll have to create your own from: https://github.com/godotengine/webrtc-native

lewiji avatar Nov 20 '20 10:11 lewiji

the same problem for me ,the webrtc is not suported.

313364973 avatar Nov 21 '20 02:11 313364973

GDNative is not support directly as the the classes from gdnative is not accessible from godot's classdb so it is impossible to generate ecma class binding for that. You can make some tool to generate JavaScript class binding glue files from gdnative class configuration files (I think there should be something like this but not sure)

Geequlim avatar Nov 21 '20 03:11 Geequlim

OK, thanks, I will look into that! I did build the webrtc-native module using a new api.json file generated from my custom godot binary, using the instructions from the godot-cpp project. Do you know if that's related? I wondered if I could do a similar thing to generate an API data file for the webrtc-native project and feed that into the ECMAscript bindings somehow.

lewiji avatar Nov 21 '20 08:11 lewiji

do you build wbrtc-native to android or ios platform?

313364973 avatar Nov 21 '20 13:11 313364973

do you build wbrtc-native to android or ios platform?

Not yet, if you look at the pull requests on the webrtc-native repo there is a recent one that has android build config. I don't think IOS supports gdnative sadly.

lewiji avatar Nov 21 '20 14:11 lewiji