For those interested, the solution is as such:
// event name is the name of the event I want to subscribe to
// callback is a static function with the 'JSObjectCallAsFunctionCallback' prototype
JSObjectRef callbackObject = JSObjectMakeFunctionWithCallback(ctx, JSStringRef(), callback);
JSValue js_cb[3] = {
toJS(state, (const JSValueRef)JSValueMakeString (ctx, JSStringCreateWithUTF8CString(eventName))),
toJS(state, (const JSValueRef)callbackObject),
toJS(state, (const JSValueRef)JSValueMakeBoolean(ctx, false))
};
ArgList args(js_cb, 3);
return invokeMethod("addEventListener", args);
With this code, whenever my plugin object broadcasts an event, I see the code landing in my callback
static function.
Now I just have to find a way to pass the private data I need so that I can modify runtime values from this static function.