I am researching on the Chromium PPAPI. After looking through all APIs from the official reference here: https://developer.chrome.com/native-client/cpp-api-dev, I seldom found any APIs that could be used by, or communicate with JS directly. In my opinion, a plugin process will set up a PP::instance and all functions within this instance would be loaded. Take video_capture.cc as an example, you could find it under /ppapi/examples/video_capture in chromium source codes. In this example, a customized PP::instance called VCDemoInstance registered some methods, yet I found only HandleMessage() could communicate with JS layer. From JS, you might use postMessage() to pass something to HandleMessage() above.
So here is my key question: Is there a way to create or define a method in PP::instance that could be used by or communicated with JS layer directly? Is it possible to register a JS object and call PPAPI like obj.apiFromPlugin? At lease I knew in Opera JSPP framework, it could be done.
Please correct me if anything is wrong. You're appreciated.
After digging into PPAPI, I couldn't find a way to create an JS object in plugin. I finally switched to Chromium Embed Framework which can port content API to JS. Using CefV8Handler may solve my question absolutely.
Related
I have a pure javascript library that users can install via npm. I want to add/create an Angular "wrapper" to this library so that it can be used seamlessly within Angular projects but I am not sure how to do this. I am using Angular-cli v6.
This is very similar to How does one go about creating an Angular library wrapper for an existing Javascript library?, however the only response is a link to ng-packagr. I have done a few tutorials on creating a library with ng-packagr, however they don't describe (and I can't find examples elsewhere) of how to create a wrapper around a non-Angular JS library.
Any help is greatly appreciated! :)
An old question but I love it. There's no one simple answer to it, so here's how I did it:
Short version
Read about the internals and how I wrapped the Google Maps Javascript API library
Long version
The following is very abstract, but this is an abstract question, so here goes...
The basic things you probably need to implement are:
Detecting changes in your Angular library and delegating them to the native library.
Detecting native events and bubbling them into your Angular library.
Switching execution in and out of Angular using NgZone.
Other considerations might be performance, scalability, adding new tools over the existing ones, etc. No matter what library you're dealing with, you'll probably end up wrapping a function with a function, a class with a class, a module with a module, etc.
The question arises: "Am I supposed to manually write all that code? Am I seriously going to write a method for each native method?? What happens when the native library changes implementation? I would have to change my code everywhere... 🤔"
To simplify and make your wrapping library scalable, you could automate the wrapping mechanism (one way is using a Javascript Proxy) object.
Combine it with TypeScript's utility types and extension interfaces, and you can create a class that automatically delegates calls to the relevant native object/function, AND you'll get intellisense (for methods that you didn't need to manually implement in your wrapper!).
Here's a more detailed explanation with examples
For events delegation, you could create a mechanism that generates observables (or EventEmitters) for your native events.
In some cases you should consider using NgZone.runOutsideAngular() to prevent unnecessary change detection runs for code that is executed in the native library. On the other hand, you should consider using NgZone.run() to bring execution into Angular's zone when running native code that should enter and affect change detection cycles.
My Angular Google Maps library is open source and you can have a look. I have implemented some very interesting architectural mechanisms in it.
Anyone running into this post and wants more details or help is welcome to contact me.
Cheers 🥂
I'm aware that there is (or was?) a JS library for WDDX (wddx.js) somewhere but I couldn't find it anymore since both www.openwddx.org and wddx.org don't seem to be active now. Can anyone give me info? I'm trying out WDDX (ie. create a packet) on a jsp page and thinking of using those js functions cause it seems like a simpler approach.
It may have been asked already but resource on Javascript and WDDX are so limited so I appreciate any help.
Thanks!
You can find them here: http://www.finwin.com/Dev/wddxsdk/2__Software_Libraries/Installation.html
http://rightworker.comoj.com/2__Software_Libraries/Installation.html
It says:
This is the current distribution of the WDDX libraries available for the various platforms that support WDDX at this time. Please check back at Wddx.org often for updates.
Please refer to the corresponding portions of the Building Apps With WDDX and References sections of this SDK for documentation, suggestions, examples, and usage.
But be aware, the JS code is from 1999. I'm using it to deserialize wddxPackets comming from PHP and it works for me. I don't know if there are any other JS implementations and/or newer ones releases of the one above.
In Google's JavaScript API's, what's the difference between gapi.load() and gapi.client.load()? How interchangeable are they and when should I use one versus the other? I see both are used in the Google Drive Realtime API sample code.
As indicated by the CORS documentation, the gapi.load function is used to dynamically load specific JavaScript libraries.
As documented in the description of the gapi.client.load function (which is provided by the "client" JS library), gapi.client.load is used to build a JavaScript interface for accessing specific HTTP(S) APIs; you can also do this sort of thing yourself using API discovery (search for it to find docs) and sending API requests directly with gapi.client.request or CORS.
Edit: added clarification based on Brian Slesinsky's follow-up comment and made minor wording changes.
After researching this, here's my simple take:
gapi.load() loads the JavaScript client library. That is to say, it's loading gapi. Without this gapi won't work.
gapi.client.load() is for loading an interface for one of the many Google APIs. The loaded API interface will then be in the form gapi.client.api.collection.method. For example, the Moderator API would create methods like gapi.client.moderator.series.list.
You most likley need both.
how can i communicate with Mega.co.nz? They claim that they are using a open source java-script project that we (developers) can use to communicate with their server. But how does someone begin? I would really appreciate if i can get some tips on this.
API's are mostly designed for third-party developers' use so they usually provide documentations on how to connect to it (e.g. which URL's to call, what parameters to pass and what is the expected response.) Most of the time, you can find it on their website, if not, you should ask them for it.
As it states on the mega.co.nz developer page the API specification has not been documented yet. You would have to reverse engineer the HTML and javascript on the site to learn how to use it. Or wait until full documentation is available.
I have some C++ code that I want to expose to client side of a web app. Ideally, I want to write Javascript wrapper objects for my C++ classes so that I can use them clientside.
Has this been done before?. Does anyone have a link to show how this may be achieved?
There is a library to convert C++ code to javascript, it might help:
emscripten
Libjspp C++ template based wrapper for embedding and extending Javascript engine spidermonkey 1 . 8 . 5 and more
SpiderMonkey? is Mozilla Project's Javascript/ECMAScript engine.
Libjspp allows C++ developers to embed SpiderMonkey? simply and easily into their applications. Libjspp allows to run multiple Javascript Engines within same process which suits one engine per thread para dime which is helpful in achieving true parallisim. Also Libjspp no way stops user from running multiple threads within engine.
http://code.google.com/p/libjspp/
I guess that RPC is what you want. You'll need to wrap your functions on the server side using some sort of framework. I've not yet used it, but this one looks promising.
On the client side you use proxy objects to dispatch the function calls. The communication is handled usually either via XML-RPC or JSON-RPC. I used this client side framework and was quite content but I'm sure you'll find many others.
This is an old topi, however, I was in the exact situation right now, and all of the solutions I found on the net complicated or outdated.
Recently, I ran across a library which supports V8 engine (including the new isolation API, which makes 90% of the libraries I found outdated) and provides great exposure and interaction API.
https://github.com/QuartzTechnologies/v8bridge
I hope that my solution will help anybody.
There's a relatively new library for doing this called nbind. Maybe that would suit you? It looks very good to me, and I'm just about to start using it.
I think you want a C++ JSON parser. You should be able to find one here http://www.json.org/. It may not do all you want because it just serializes and deserializes C++ objects without any behavior, but it should be good enough. See https://stackoverflow.com/questions/245973/whats-the-best-c-json-parser for some discussion.
If the C++ code has to be on the client, then there is no simple way to do this for a web app. A solution may involve coding plugins for the browsers you want to support, which may then be accessed from javascript code.
If, for example, you need this for a client application, that is another case. Such a thing has been done and involves linking your application to (or running from outside) with for example chromium library, or any other javascript execution engine. That way you can create bindings to C++ classes and use such objects from javascript and vice-versa. Note that this is also not a trivial solution and may be a big effort to implement (also requires additional resources).
You could for example wrap the C++ classes in PHP or Python, and then implement an API over HTTP to access the required functions.
Or if you insist on exposing the functions as JavaScript you could try using Node.js, and create an C++ add-on to wrap you classes. See the Node.js documentation here: http://nodejs.org/api/addons.html#addons_wrapping_c_objects
But either way, I don't think avoid creating some sort of API (HTTP SOAP, XML RPC) to access the functions on your server.
Though QML is not exactly Javascript, Qt is not plain C++, but what they do together seem just like what you need