From 38cc869104584987d0a7f3b21be4da196bb3f390 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 17 Jun 2022 04:26:44 -0700 Subject: WIP WebSocket --- .../jsc/bindings/ScriptExecutionContext.cpp | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/javascript/jsc/bindings/ScriptExecutionContext.cpp (limited to 'src/javascript/jsc/bindings/ScriptExecutionContext.cpp') diff --git a/src/javascript/jsc/bindings/ScriptExecutionContext.cpp b/src/javascript/jsc/bindings/ScriptExecutionContext.cpp new file mode 100644 index 000000000..67dd30f6f --- /dev/null +++ b/src/javascript/jsc/bindings/ScriptExecutionContext.cpp @@ -0,0 +1,60 @@ + +#include "ScriptExecutionContext.h" +#include +#include + +extern "C" void Bun__startLoop(us_loop_t* loop); + +namespace WebCore { + +template +us_socket_context_t* webSocketContext() +{ + if constexpr (isSSL) { + if (!m_ssl_client_websockets_ctx) { + us_loop_t* loop = (us_loop_t*)uWs::Loop::get(); + us_socket_context_options_t opts; + memset(&opts, 0, sizeof(us_socket_context_t)); + this->m_ssl_client_websockets_ctx = us_create_socket_context(1, loop, sizeof(*ScriptExecutionContext), opts); + *us_socket_context_ext(m_ssl_client_websockets_ctx) = this; + WebSocketStream::registerHTTPContext(this, m_ssl_client_websockets_ctx, loop); + } + + return m_ssl_client_websockets_ctx; + } else { + if (!m_client_websockets_ctx) { + us_loop_t* loop = (us_loop_t*)uWs::Loop::get(); + us_socket_context_options_t opts; + memset(&opts, 0, sizeof(us_socket_context_t)); + this->m_client_websockets_ctx = us_create_socket_context(0, loop, sizeof(*ScriptExecutionContext), opts); + *us_socket_context_ext(m_client_websockets_ctx) = this; + SecureWebSocketStream::registerHTTPContext(this, m_client_websockets_ctx, loop); + } + + return m_client_websockets_ctx; + } +} + +template +uWS::WebSocketContext* +{ + if constexpr (isSSL) { + if (!m_connected_ssl_client_websockets_ctx) { + // should be the parent + RELEASE_ASSERT(m_ssl_client_websockets_ctx); + m_connected_client_websockets_ctx = SecureWebSocketStream::registerClientContext(this, webSocketContext(), loop); + } + + return m_connected_ssl_client_websockets_ctx; + } else { + if (!m_connected_client_websockets_ctx) { + // should be the parent + RELEASE_ASSERT(m_client_websockets_ctx); + m_connected_client_websockets_ctx = WebSocketStream::registerClientContext(this, webSocketContext(), loop); + } + + return m_connected_client_websockets_ctx; + } +} + +} \ No newline at end of file -- cgit v1.2.3