SocketBridge.cpp 825 B

1234567891011121314151617181920212223242526272829303132
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_JAVASCRIPT
  3. #include "os/SocketBridge.h"
  4. #ifdef __EMSCRIPTEN_PTHREADS__
  5. #include <emscripten/threading.h>
  6. #include <emscripten/posix_socket.h>
  7. #endif // __EMSCRIPTEN_PTHREADS__
  8. namespace il2cpp
  9. {
  10. namespace os
  11. {
  12. void SocketBridge::WaitForInitialization()
  13. {
  14. #ifdef __EMSCRIPTEN_PTHREADS__
  15. EMSCRIPTEN_WEBSOCKET_T bridgeSocket = emscripten_init_websocket_to_posix_socket_bridge("ws://localhost:6690");
  16. // Synchronously wait until connection has been established
  17. uint16_t readyState = 0;
  18. do
  19. {
  20. emscripten_websocket_get_ready_state(bridgeSocket, &readyState);
  21. emscripten_thread_sleep(100);
  22. }
  23. while (readyState == 0);
  24. #endif // __EMSCRIPTEN_PTHREADS__
  25. }
  26. }
  27. }
  28. #endif // IL2CPP_TARGET_JAVASCRIPT