stop using a hardcoded websocket address in ws_client

This commit is contained in:
pena 2023-01-03 23:53:05 +01:00 committed by Swrup
parent cafba23610
commit 461d648ac9

View file

@ -5,8 +5,14 @@ open Shared
let ws =
Format.printf "create websocket@\n";
let ws_url =
(* TODO fix hostname *)
Jstr.of_string "ws://localhost:3696/island/ws"
let location = Window.location G.window in
let host = Uri.host location |> Jstr.to_string in
let port =
Option.fold ~none:""
~some:(fun port -> Format.sprintf ":%d" port)
(Uri.port location)
in
Jstr.of_string @@ Format.sprintf "ws://%s%s/island/ws" host port
in
Websocket.create ws_url