You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Persuant to #923. I added the following code to my fork of webview to check the C++ side of things is all OK.
// another overload of bind() with user data
// using statement means we can overload cleanly
using sync_binding_arg_t = std::function<std::string(std::string, void*)>;
// invoked with user data
void bind(const std::string &name, sync_binding_arg_t fn, void* arg) {
auto wrapper = [this, fn](const std::string &seq, const std::string &req,
void * arg) { resolve(seq, 0, fn(req,arg)); };
bind(name, wrapper, arg);
}
Example use therefor:
// invoked with instance data, so JS -> C++ -> JS
std::string callout2(const std::string& arg, void* data)
{
webview::webview* pwv = reinterpret_cast<webview::webview*>(data);
std::string ret = std::string("{ \"status\": true, \"data\": \"JSONpacket\" }");
std::printf("%s (%p) => %s\n", arg.c_str(), pwv, ret.c_str());
// JSON status message
return ret;
}
// example usage
webview::webview w(true, nullptr);
w.bind("callout2", callout2, &w);
This works, with the promise completing as expected:
callit: callout2 ƒ () {
var seq = RPC.nextSeq++;
var promise = new Promise(function(resolve, reject) {
RPC[seq] = {
resolve: resolve,
reject: reject,
};
…
index.html:61 ret => Promise {<pending>}
index.html:36 success: {status: true, data: 'JSONpacket'}
If interested I can submit a PR.
Thanks for listening.
The text was updated successfully, but these errors were encountered:
Persuant to #923. I added the following code to my fork of webview to check the C++ side of things is all OK.
Example use therefor:
This works, with the promise completing as expected:
If interested I can submit a PR.
Thanks for listening.
The text was updated successfully, but these errors were encountered: