vbmithr / ocaml-websocket

Websocket library for OCaml
ISC License
161 stars 44 forks source link

cohttp_lwt: may be pass frames_out_fn into incoming_handler? #113

Open NightBlues opened 4 years ago

NightBlues commented 4 years ago

May be pass frames_out_fn into incoming_handler? https://github.com/vbmithr/ocaml-websocket/blob/master/lwt/websocket_cohttp_lwt.ml#L40 Without frames_out_fn its hard to use incoming_handler to react to messages. You have to do something like

let out_fn = ref (fun _ -> ()) in
let on_message frame =
  (* TODO: parse frame *)
  !out_fn @@ Some (Frame.create ~opcode:Close ())
in
let%lwt resp, fr_out_fn = Websocket_cohttp_lwt.upgrade_connection req on_message in
out_fn := fr_out_fn

Or may be it should be done other way?

vbmithr commented 4 years ago

I'm not using this piece of code anymore, and I have not looked closely but you're probably right. Feel free to submit a patch! By the way, sorry for your other patch, merged now, I haven't look here for a long time.