diff options
author | Clombrong <clombrong@egregore.fun> | 2025-05-08 21:20:53 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-05-08 21:20:53 +0200 |
commit | e2314545ef44b8b703692eb2471c3a2649e95cc1 (patch) | |
tree | d0799ac57de9fbfcabd8d034e418888618f5e394 | |
parent | 18c45a66888c4cefad677e2f9545fd5ee46d2acb (diff) |
feat: add staging buffer to send frame
-rw-r--r-- | portal/lib/portal_ws.ml | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/portal/lib/portal_ws.ml b/portal/lib/portal_ws.ml index b808733..cadbf41 100644 --- a/portal/lib/portal_ws.ml +++ b/portal/lib/portal_ws.ml @@ -92,4 +92,14 @@ let connect domain = let open Lwt_stream in let+ stream, ws_push = ws_endpoint domain >|= ws_stream in let _streamed_stanzas, _push = create () in + let open Stdlib.Buffer in + let buf = create 1024 in (* NOTE: placeholder, ideally this should be the ~size of an XMPP stanza *) + let _send_frame () = + (* We create a buffer a single time, and clear it for every generated WebSocket frame. *) + Some (contents buf) |> ws_push; + clear buf + and _close_stream () = + Some stanza_close |> ws_push; + ws_push None; + in stream, ws_push |