romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
493 stars 41 forks source link

How to create `NULL`? #343

Open chfritz opened 1 year ago

chfritz commented 1 year ago

I've found in various situations the need to pass NULL as a parameter but wasn't able to create it, e.g., to call https://gstreamer.freedesktop.org/documentation/webrtc/index.html?gi-language=javascript#webrtcbin::get-stats with a NULL pad. I've tried null but get:

TypeError: Cannot convert value "null" to type GstPad

If I try new Gst.Pad(null) instead I get:

** (node:10962): CRITICAL **: 12:35:13.471: gst_webrtc_bin_get_stats: assertion 'pad == NULL || GST_IS_WEBRTC_BIN_PAD (pad)' failed

So for some reason null in JS is not translated to NULL in C.

What's the correct way to set a parameter when the C documentation of the gtk method requires NULL?

Minimal example:

const gi = require('node-gtk');
const Gst = gi.require('Gst', '1.0');
const GObject = gi.require('GObject');
const GstWebRTC = gi.require('GstWebRTC');

gi.startLoop();
Gst.init();

const p = Gst.parseLaunch('fakesrc ! webrtcbin name=webrtc');
const w = p.getByName('webrtc');
w.emit('get-stats', null, Gst.Promise.newWithChangeFunc((promise) => 
  console.log('got stats', promise)));
// Uncaught TypeError: Cannot convert value "null" to type GstPad

(Move here from https://github.com/romgrk/node-gtk/issues/11#issuecomment-1442400894.)

romgrk commented 1 year ago

I've been trying to find the typing annotations for that function but couldn't find them, Gst is a particular module.

I'm not sure if the annotations are wrong or if we should be allowing null in general for pointer types, but if it's the later then we'll need to update the conversion functions to accept null pointers:

But I don't have enough time to implement the changes myself these days. PR welcome.