open Lwt.Syntax exception ClosedStream exception InvalidStanza of string let get stream = (** [get stream] returns a promise containing an element of [stream]. If [stream] is closed, it throws a ClosedStream Lwt exception. *) let* stanza = Lwt_stream.get stream in match stanza with | Some stanza -> Lwt.return stanza | None -> Lwt.fail ClosedStream let start domain : Portal.t Lwt.t = (** [start domain] is a promise containing a Portal (stream * push) connected to the XMPP server [domain]. Currently, it doesn't handle anything except the initial [] stanza. *) let* stream, _push = Portal.connect domain in let push = function | None -> _push (Some Portal.stanza_close); _push None; | anything -> _push anything in Some (Portal.stanza_open domain) |> push; (* TODO: check this is a good stanza *) let+ _ = get stream in stream, push