Skip to content

Commit

Permalink
server: add cloudid to connectioninfo
Browse files Browse the repository at this point in the history
  • Loading branch information
C0kkie committed Sep 16, 2023
1 parent 0894370 commit d9f0e6a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions server/src/bindings/ConnectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,40 @@ static void SetText(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::P
con->SetText(text);
}

static void RequestCloudID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
static std::list<v8::Global<v8::Promise::Resolver>> promises;

V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);

auto& persistent = promises.emplace_back(v8::Global<v8::Promise::Resolver>(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked()));

con->RequestCloudID(
[&persistent, resource](bool ok, const std::string& result)
{
resource->RunOnNextTick(
[=, &persistent]()
{
if(!resource->GetResource()->IsStarted())
{
promises.remove(persistent);
return;
}

auto isolate = resource->GetIsolate();
auto context = resource->GetContext();

if(ok) persistent.Get(isolate)->Resolve(context, V8Helpers::JSValue(result));
else
persistent.Get(isolate)->Reject(context, v8::Exception::Error(V8Helpers::JSValue(result)));
promises.remove(persistent);
});
});

V8_RETURN(persistent.Get(isolate)->GetPromise());
}

extern V8Class v8BaseObject;
extern V8Class v8ConnectionInfo("ConnectionInfo",
v8BaseObject,
Expand All @@ -190,6 +224,7 @@ extern V8Class v8ConnectionInfo("ConnectionInfo",

V8Helpers::SetMethod(isolate, tpl, "accept", &Accept);
V8Helpers::SetMethod(isolate, tpl, "decline", &Decline);
V8Helpers::SetMethod(isolate, tpl, "requestCloudID", &RequestCloudID);
V8Helpers::SetAccessor(isolate, tpl, "isAccepted", &IsAcceptedGetter);

V8Helpers::SetAccessor(isolate, tpl, "name", &NameGetter);
Expand Down

0 comments on commit d9f0e6a

Please sign in to comment.