Skip to content

Instantly share code, notes, and snippets.

@jan-ivar
Created November 16, 2018 16:18
Show Gist options
  • Save jan-ivar/c6da408156da9f6172b3395a24a0105e to your computer and use it in GitHub Desktop.
Save jan-ivar/c6da408156da9f6172b3395a24a0105e to your computer and use it in GitHub Desktop.
already_AddRefed<Promise>
MediaDevices::GetUserMedia(const MediaStreamConstraints& aConstraints,
CallerType aCallerType,
ErrorResult &aRv)
{
RefPtr<Promise> p = Promise::Create(GetParentObject(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
MediaManager::Get()->GetUserMedia(GetOwner(), aConstraints, aCallerType)->Then(
GetCurrentThreadSerialEventTarget(), __func__,
[p](RefPtr<DOMMediaStream>&& aStream) mutable {
p->MaybeResolve(std::move(aStream));
},
[p](RefPtr<MediaStreamError>&& error) mutable {
--> p->MaybeReject(std::move(error));
}
);
return p.forget();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment