-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Add CameraFeed support for Web #106784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add CameraFeed support for Web #106784
Conversation
140bdef
to
f939c20
Compare
I've tried enabling Asyncify as follows, which I believe should fix it, but the build is still failing. diff --git a/platform/web/SCsub b/platform/web/SCsub
index cf872e65ff..5bb105e1cd 100644
--- a/platform/web/SCsub
+++ b/platform/web/SCsub
@@ -106,6 +106,8 @@ else:
sys_env.Append(LIBS=["idbfs.js"])
build = sys_env.add_program(build_targets, web_files + ["web_runtime.cpp"])
+sys_env.Append(LINKFLAGS=["-sASYNCIFY=1"])
+
sys_env.Depends(build[0], sys_env["JS_LIBS"])
sys_env.Depends(build[0], sys_env["JS_PRE"])
sys_env.Depends(build[0], sys_env["JS_POST"])
|
Asyncify makes binaries a lot larger, so we need to be able to use it selectively only for functions that need it. cc @adamscott |
a6e548e
to
9354b30
Compare
be89cda
to
706e8d0
Compare
Ready for review. Demo site: https://shiena.github.io/GodotCameraFeedSample/ |
706e8d0
to
6854b08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The demo site requires Chrome 137+ due to its use of JSPI.
I wanted to useASYNCIFY=1
in SCsub but ran into errors, so I'm currently usingASYNCIFY=2
for JSPI.
This means it can't be merged, we at least want support the latest version of Chrome, Firefox and iOS (and we also try to support the latest version of Firefox ESR, but that has been on and off in the past).
That said, it should be possible to implement the API by relying on callbacks instead of requiring asyncify.
EM_ASYNC_JS(void, godot_js_camera_get_cameras, (void *context, CameraLibrary_OnGetCamerasCallback p_callback_ptr), { | ||
await GodotCamera.api.getCameras(context, p_callback_ptr); | ||
}); | ||
|
||
EM_ASYNC_JS(void, godot_js_camera_get_capabilities, (void *context, const char *p_device_id_ptr, CameraLibrary_OnGetCapabilitiesCallback p_callback_ptr), { | ||
await GodotCamera.api.getCameraCapabilities(p_device_id_ptr, context, p_callback_ptr); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use the EM_*_JS
functions, as they break dynamic linking.
I'm trying to get a list of However, both of these methods return a JavaScript Promise, which makes using callbacks inherently slow. |
fixed: godotengine/godot-proposals#12493
Current Limitation:
Theplatform/web/js/libs/library_godot_camera.js
library includes certain functionalities that are inherently asynchronous. We are currently investigating how to execute these functions synchronously, as this is a requirement for our project, but haven't yet found a solution.I was able to build with JSPI and call asynchronous functions synchronously in Chrome. However, JSPI only works in Chrome and Edge 137.
https://webassembly.org/features/
https://learn.microsoft.com/en-us/microsoft-edge/web-platform/release-notes/137#javascript-promise-integration-jspi-in-webassembly