aboutsummaryrefslogtreecommitdiff
path: root/portal/lib
diff options
context:
space:
mode:
Diffstat (limited to 'portal/lib')
-rw-r--r--portal/lib/portal_ws.ml24
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