open! Lwt.Syntax open! Lwt.Infix open! Flesh open! Session let main = let config : Stream.config = { starttls = {prefer = true}; sasl = { jid = Jid.of_string (Sys.getenv "FLESH_JID"); password = (Sys.getenv "FLESH_PASSWORD"); preferred_mechanisms = [Sasl.PLAIN] }; other = []; } in let state, update = Lwt_react.S.create Disconnected in Lwt_react.S.map (function | Disconnected -> print_endline "Disconnected" | Connecting -> print_endline "Connecting" | Connected (portal, _) -> portal.push None) state |> ignore; try%lwt connect config.sasl.jid.domainpart config >|= (fun (portal, state) -> update (Connected (portal, state))) with exn -> begin (* I suspect JavaScript's [wrap_callback] swallows the Exceptions thrown by OCaml, so... The next best thing is probably printing something. *) print_endline (match exn with | Xml.InvalidStanza stanza -> "Invalid stanza: " ^ stanza | Portal.MalformedStanza err -> "Server sent malformed stanza: " ^ (Markup.Error.to_string err) | _ -> "... and so I stumble back to bed."); Lwt.fail exn end