diff options
author | Clombrong <cromblong@egregore.fun> | 2025-06-27 09:02:31 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-06-27 09:54:35 +0200 |
commit | a808e8a486ba3e08bc62cc77c7a0724fb8173b81 (patch) | |
tree | 18852f376ffd21f362b730354ee53d5ecbd59d92 /lib/stream.ml | |
parent | 13273777453522c4b73083207b3ba50ea3ca6bd0 (diff) |
feat(stream): add function initiate
Diffstat (limited to 'lib/stream.ml')
-rw-r--r-- | lib/stream.ml | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/stream.ml b/lib/stream.ml index 01d6a55..ee33575 100644 --- a/lib/stream.ml +++ b/lib/stream.ml @@ -47,3 +47,20 @@ let negotiate (domain : string) (portal : Portal.t) : features Lwt.t = let* _id = Portal.header domain portal in let+ features = Wire.get portal.stream >|= parse_features in features + +(** [initiate domain] initiates a stream with the XMPP server [domain]. + + Once [None] is pushed into the stream, the receiving stream is drained and the + socket is closed. *) +let initiate (domain : string) : (Portal.t * features) Lwt.t = + let open Portal in + let* p = connect domain + in let push = function + | Some n -> p.push (Some n) + | None -> + p.push (Some close); + (* Empty the stream completely, then close the socket. *) + Lwt.async (fun () -> let+ () = Markup_lwt.drain p.stream in p.push None) + in let portal = {p with push} in + let+ features = negotiate domain portal + in (portal, features) |