33 class ProgressClient :
public SchemePlugin::Client {
35 explicit ProgressClient(Callback on_progress)
36 : on_progress_(
MakeJsRef<Callback>(
std::move(on_progress))) {}
38 void OnProgress(
double time, uint64_t bytes, uint64_t remaining)
override {
39 RefPtr<Callback> progress = on_progress_;
40 auto cb = [=]() { (*progress)(time, bytes, remaining); };
45 RefPtr<Callback> on_progress_;
64 impl_->WaitUntilFinished();
68 auto run_future = impl_->RunScript(path)->future();
74 auto future = std::async(std::launch ::deferred,
79 return Error(
"Unknown script error");
82 return future.share();
87 auto js_scheme_plugin = [=](
const std::string& uri,
js::Request request,
89 std::shared_ptr<Request> pub_req(
new Request(std::move(request)));
90 std::shared_ptr<Response> resp(
new Response);
91 std::shared_ptr<SchemePlugin::Client> client(
92 new ProgressClient(std::move(on_progress)));
96 auto on_done = [pub_req, resp, client, ret]() {
105 return JsObjectWrapper::CallGlobalMethod<void>(
106 {
"shaka",
"net",
"NetworkingEngine",
"registerScheme"}, scheme,
107 std::move(js_scheme_plugin));
111 const std::string& scheme) {
112 return JsObjectWrapper::CallGlobalMethod<void>(
113 {
"shaka",
"net",
"NetworkingEngine",
"unregisterScheme"}, scheme);
AsyncResults< void > RunScript(const std::string &path)
virtual std::future< optional< Error > > OnNetworkRequest(const std::string &uri, RequestType type, const Request &request, Client *client, Response *response)=0
void HandleNetworkFuture(Promise promise, std::future< optional< Error >> future, std::function< void()> on_done)
void ResolveWith(Handle< JsValue > value, bool run_events=true)
std::shared_future< impl::RetOf< Func > > InvokeOrSchedule(Func &&callback)
JsManager & operator=(JsManager &&)
static JsManagerImpl * Instance()
AsyncResults< void > RegisterNetworkScheme(const std::string &scheme, SchemePlugin *plugin)
static Promise PendingPromise()
RefPtr< T > MakeJsRef(Args &&... args)
AsyncResults< void > UnregisterNetworkScheme(const std::string &scheme)
TaskRunner * MainThread()