aboutsummaryrefslogtreecommitdiff
path: root/test/js/websockets_hello.ml
blob: 41487b7e1e77b6ad41792c8f386dd11ce9dd6474 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
open Lwt.Syntax

let () =
  (* Echo is a websocket that... echoes you stuff. *)
  let stream, push = Portal_ws.lwt_ws "wss://echo.websocket.org" in
  push (Some "great text");
  push (Some "other text");
  push (Some "yet another text");
  push (Some "BYE");
  Lwt.async @@
    fun () ->
    let+ s = Lwt_stream.iter
               (fun greetings ->
                 match greetings with
                 (* When the websocket sends "BYE", we close. *)
                 | "BYE" -> print_endline "CLOSING BYE"; push None
                 | hello -> print_endline ("> " ^ hello))
               stream
    in s