Open zbozo opened 6 years ago
Hi, this project is pretty much dead. I've added C++ -> javascript integration to use in another project and that was pretty much it. It sets a javascript object from C++ side so you can access the variables in javascript.
is a great project, awesomium has been unavailable for a long time, I ended up finding your project, apparently it is very light because it is an old version of cef, it is good for games I'm going to use it, how should I call the variables in js for
Cef3DJsValue test("test", "my string"); this->CreateJsObject(test);
That would be window.test
in javascript. Here is a sample project where i did use those stuff.
https://github.com/arkenthera/cef3d/tree/develop/Demos/MMD_Nowplaying
It's what I tested, it's giving undefined, I thought it would be another way :(
When are you calling CreateJsObject
? Can you post your full code?
Cef3DRenderer::OnProcessMessageReceived http://prntscr.com/ko9ysr (i received all msgbox)
SampleBrowser::OnAfterCreated http://prntscr.com/koa1j0 (i received the messagebox)
My html code:
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener('load', function() {
var myelement = document.getElementById("xx");
myelement.innerHTML = window.test;
})
</script>
</head>
<div id="xx">???</div>
</body>
</html>
Is there any way to send javascript values to the client like in awesomium? http://prntscr.com/koa7va
The only way I found it was using V8::Execute in the subprocess, however, it does not have access to client variables to return the requested values in javascript It would also be a more dynamic form because whenever requested will take the current value of the variable instead of the fixed value
Yes, though that is a little more complicated. In the video below i was using a color picker from html side to send color values to c++. I will do a write-up when i have time(sometime today) about how you can do that.
oh ok, thank you very much :P
So, here I will try to explain but bear with me since its been few years since I last worked on this.
To be able to call C++ code from Javascript, first you need an "extension".
The extension is a javascript code which will be uploaded by renderer process. Internally, when this javascript code is called on the client, it will call V8Handler::Execute
, we will catch this and create an IPC message to let the Browser process know that an event has occured. In the Browser process, we catch this IPC message with the data and forward it to the listeners and do whatever you want with it.
Note that all javascript stuff happens in Renderer process so you need to do IPC messaging to communicate with it. Below I will list sample code step by step so you can inspect it and implement yourself.
Here is a sample extension code. Attention to the native
keyword, as it is required by extensions. This code will be loaded in renderer process which then you will call CefRegisterExtension
when Webkit is initialized.
When, for example, native function SendDomEvent
is called on Javascript side, it will invoke V8Handler::Execute
here and we will create an IPC to let the browser know.
Then in browser process, we catch this IPC and after that its up to you to whatever you want with it.
Here is an example of turning a check box on and off, and letting the C++ side know about it.
Cef3D.SendDomEvent(this.onSendDomEvent,$(element.target).attr("id"),"InputChecked","" + $(element.target).is(':checked') + "");
This will then be catched here.
I hope this helps!
I am very grateful for the explanation and the codes shown -- removed oh, sorry, I got it fixed, I was running the wrong javascript, after hours I realized 👍
I finally managed to make interaction
I am not really sure what's happening there. Maybe check if Cef3DRendererApp::OnContextReleased
is called or not to understand maybe something is causing that context to be invalid, thus crashing on Enter()
?
Just saw your edit, nice!
Hello, i noticed that your branch develop has some functions but I did not see any use of them, could you tell me what it does?
Cef3DBrowser::CreateJsObject
thank you