aboutsummaryrefslogtreecommitdiff
path: root/portal/ws
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-25 18:06:07 +0200
committerClombrong <cromblong@egregore.fun>2025-06-25 18:06:07 +0200
commit9b22f650dafeb8dc193dadd1a10182724382c6a7 (patch)
treed1d64e6b0fbef0c00273cd03f5c33efa90797ff9 /portal/ws
parent5f52ab70862cfa8332ec5bd9d1dc3d3f6af37d16 (diff)
chore: move comments to correct location
Diffstat (limited to 'portal/ws')
-rw-r--r--portal/ws/portal.ml61
1 files changed, 30 insertions, 31 deletions
diff --git a/portal/ws/portal.ml b/portal/ws/portal.ml
index 2916e66..916fd2f 100644
--- a/portal/ws/portal.ml
+++ b/portal/ws/portal.ml
@@ -13,11 +13,10 @@ let xmlns = "urn:ietf:params:xml:ns:xmpp-framing"
rules. *)
let well_known_of (domain : string) = "https://" ^ domain ^ "/.well-known/host-meta"
-let stanza_open ?from domain : (signal, sync) stream =
- (** [open_stanza domain] is an <open /> stanza for [domain].
+(** [open_stanza domain] is an <open /> stanza for [domain].
- If [from] is specified, the <open /> stanza has the from parameter.
- *)
+ If [from] is specified, the <open /> stanza has the from parameter. *)
+let stanza_open ?from domain : (signal, sync) stream =
let open Markup in
let stanza =
let attributes =
@@ -37,16 +36,16 @@ let stanza_close = {|<close xmlns="|} ^ xmlns ^ {|" />|} |> string |> parse_xml
exception MalformedStanza of Markup.location * Markup.Error.t
-let ws_endpoint (domain : string) : string Lwt.t =
- (** [ws_endpoint domain] is a promise containing the XMPP websocket endpoint
- associated with [domain], by using the domain's Web-host Metadata.
+(** [ws_endpoint domain] is a promise containing the XMPP websocket endpoint
+ associated with [domain], by using the domain's Web-host Metadata.
- This function uses XMLHttpRequest, so while it should work fine in the browser, in
- environments that don't provide this constructor (Node.js), there should be some
- sort of polyfill.
+ This function uses XMLHttpRequest, so while it should work fine in the browser, in
+ environments that don't provide this constructor (Node.js), there should be some
+ sort of polyfill.
- Lastly, if [domain] doesn't provide a well-formed Web-host Metadata file, the
- function throws an exception. *)
+ Lastly, if [domain] doesn't provide a well-formed Web-host Metadata file, the
+ function throws an exception. *)
+let ws_endpoint (domain : string) : string Lwt.t =
let open Markup in
(* This ugly function extracts the href element from a Link tag's attributes if it's a
websocket. *)
@@ -72,16 +71,16 @@ let ws_endpoint (domain : string) : string Lwt.t =
| Some x -> Lwt.return x
| None -> Lwt.fail_with (domain ^ ": no WebSocket endpoint in Web-host Metadata.")
-let ws_stream (url : string) =
- (** [ws_stream url] is a promise to a framed Lwt stream (and its push function)
- communicating with the websocket located at [url] using the XMPP protocol.
+(** [ws_stream url] is a promise to a framed Lwt stream (and its push function)
+ communicating with the websocket located at [url] using the XMPP protocol.
- Valid XMPP WebSocket subprotocol frames must be sent to the stream, because it
- directly exposes the websocket under.
+ Valid XMPP WebSocket subprotocol frames must be sent to the stream, because it
+ directly exposes the websocket under.
- Pushing [None] closes the websocket.
+ Pushing [None] closes the websocket.
- If the websocket is closed server-side, the stream closes. *)
+ If the websocket is closed server-side, the stream closes. *)
+let ws_stream (url : string) =
let open Lwt_stream in
let stream, message = create () in
let open Lwt_condition in
@@ -96,21 +95,21 @@ let ws_stream (url : string) =
ws##.onopen := Dom.handler (fun _ -> signal is_open (); Js._false);
let+ () = wait is_open in stream, push
-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.
+(** [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 Markup.ml
- signals and sends framed XML stanzas to the underlying socket, with exactly one
- stanza per frame, according to RFC 7935.
+ This function is a complex wrapper around ws_stream, that accepts Markup.ml
+ signals and sends framed XML stanzas to the underlying socket, with exactly one
+ stanza per frame, according to RFC 7935.
- In essence, it (tries to) expose an identical interface to the original XMPP
- streamed protocol.
+ 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 -> mu_stream -> to_frames -> ws_push -> \
- function user websocket
- \ <--- stream <--- markup_lwt <--- ws_stream <--- / *)
+ Here's an ASCII rendered flow of the data through the various streams.
+ / -> push -> mu_stream -> to_frames -> ws_push -> \
+ function user websocket
+ \ <--- stream <--- markup_lwt <--- ws_stream <--- / *)
+let connect domain =
let+ ws_stream, ws_push = ws_endpoint domain >>= ws_stream in
let open Markup_lwt in
(* When sending a malformed stanza (one that Markup.ml doesn't like), a