node-gtk
node-gtk copied to clipboard
How to create `NULL`?
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.)
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:
- https://github.com/romgrk/node-gtk/blob/4ade9703d1c1a61777f1b3045dcc1281b430e0a8/src/value.cc#L1370
- https://github.com/romgrk/node-gtk/blob/4ade9703d1c1a61777f1b3045dcc1281b430e0a8/src/value.cc#L1421
- https://github.com/romgrk/node-gtk/blob/4ade9703d1c1a61777f1b3045dcc1281b430e0a8/src/boxed.cc#L441
But I don't have enough time to implement the changes myself these days. PR welcome.