diff options
author | Clombrong <clombrong@egregore.fun> | 2025-04-22 14:35:23 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-04-22 14:35:23 +0200 |
commit | 3c935560874956d1b2d92024d09544b749a707b2 (patch) | |
tree | e58bd4af3b45f626ae1b2024a9a25ebcc5d345a2 /test | |
parent | ca9611cef50cf81c47fcac3b1a8ef972b2d3dbf5 (diff) |
feat: new module flesh_websockets.
Create flesh_websockets module.
Add lwt_ws function.
Diffstat (limited to 'test')
-rw-r--r-- | test/js/dune | 5 | ||||
-rw-r--r-- | test/js/websockets_hello.ml | 20 |
2 files changed, 25 insertions, 0 deletions
diff --git a/test/js/dune b/test/js/dune new file mode 100644 index 0000000..d919a1e --- /dev/null +++ b/test/js/dune @@ -0,0 +1,5 @@ +(test + (name websockets_hello) + (libraries portal_ws lwt js_of_ocaml) + (modes js) + (preprocess (pps js_of_ocaml-ppx))) diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml new file mode 100644 index 0000000..41487b7 --- /dev/null +++ b/test/js/websockets_hello.ml @@ -0,0 +1,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 + |