diff options
author | Clombrong <clombrong@egregore.fun> | 2025-05-08 21:15:42 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-05-08 21:15:42 +0200 |
commit | 9e315fd0223d56347db74f0f03dc7f853dd44ce4 (patch) | |
tree | 5fadbe8aab4a517c22b7b3af37a684da7f8b07b5 /portal/lib | |
parent | dab49c354f6ff53c6c18eb7d659fb4c75f9c8164 (diff) |
feat(portal_ws): create connect function
Diffstat (limited to 'portal/lib')
-rw-r--r-- | portal/lib/portal_ws.ml | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/portal/lib/portal_ws.ml b/portal/lib/portal_ws.ml index 1921891..f8fb4a9 100644 --- a/portal/lib/portal_ws.ml +++ b/portal/lib/portal_ws.ml @@ -1,4 +1,5 @@ open Lwt.Syntax +open Lwt.Infix open Js_of_ocaml let jss = Js.string let sjs = Js.to_string @@ -59,6 +60,23 @@ let ws_stream (url : string) = Dom.handler (fun _ -> message None; Js._true); stream, push -(* let connect domain = *) -(* let+ url = server_ws domain *) -(* in ws_stream url *) + +let connect domain = + (** [connect domain] is an Lwt stream (and its push function) communicating with the XMPP server running at [domain] + via the Websocket subprotocol. + + This function is a complex wrapper around ws_stream, that accepts streamed XML and sends framed XML stanzas to + the underlying socket, with exactly one stanza per frame, according to RFC 7935. + + It also sends the <close/> stanza used by the WebSocket subprotocol to the underlying WebSocket. + + In essence, it (tries to) expose an identical interface to the original XMPP streamed protocol. + + Here's an ASCII rendered flow of the data through the various streams. + / -> push -> streamed_stanzas -> to_frames -> ws_push -> \ + function user websocket + \ <---- stream <---- filter_map <---- ws_stream <---- / *) + let open Lwt_stream in + let+ stream, ws_push = ws_endpoint domain >|= ws_stream in + let _streamed_stanzas, _push = create () in + stream, ws_push |