Question

I have created the plugin which is based on the Firebreath Framework. Implemented the Events to achieve the proper functionality of the Plugin.

Firebreath Events get fired asynchronously from JSAPIAuto.cpp class of the below method :

void FB::JSAPIAuto::fireAsyncEvent( const std::string& eventName, const std::vector<variant>& args )

I also used the same .but I want to get an acknowledgement of the same event when it is fired in the JSAPIAuto.cpp via some callback or anything .. So that I can handle my next functionality in the PluginAPI.cpp based on the same result.

Any help would be appreciated !!!

Was it helpful?

Solution

If you read the text of the function, you'll see that the word "async" appears in it =] As that suggests, firing an even like this in FireBreath is asynchronous and does not allow you to give it a return value in any way. Because of the way events are implemented on some browsers there is no reasonable way to change that.

That said, you can do your own thing by having a function that you pass in a FB::JSObjectPtr to be stored and used as a callback; if you call that callback using Invoke with "" as the method name it will call the javascript function and return the value, like so:

bool MyScriptingAPI::setCallback(const FB::JSObjectPtr& callback) {
    FB::variant res = callback->Invoke("", FB::variant_list_of("some")(3)("arguments"));
    return res.convert_cast<bool>();
}

This will call your callback, cast the result to bool (true/false) and return the result to javascript. Obviously if something that can't cast to a bool is returned, an exception will be thrown, but you should get the general idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top