문제

I'm using the Webkit plugin facility to implement the <video> tag in an embedded environment. (for those interested, I was inspired by this)

I successfully connected my plugin's methods and properties to map the ones that the HTML5 tag should expose in the MediaPlayerPrivate class of Webkit (I know how to query properties and to invoke simple methods), but I'm now wondering how my plugin can pass back data to the MediaPlayer interface.

My plugin implements the addEventListener() interface in JavaScript, so I figured I could use it to register the MediaPlayer client as an EventListener, but I can't figure how.

What I would like to do is like this:

  Plugin                    WebKit
+--------------+         +-----------------------------+
|              |         |                             |
|          <-------------|-+addEventListener(callback) |
|              |         |                             |
|+----------+  |         |                             |
||          |  |         |                             |
|| onEvent  |  |         |                             |
|+----------+--------------> callback( EventData )     |
|              |         |                             |
+--------------+         +-----------------------------+

What I don't know, is how I can call the method addEventListener of my plugin and pass it a JSObject that refers to a static callback in my C++.

Do you have any idea on how to do that?

(ASCII drawings thanks to Asciiflow)

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top