From cdd46850bfa1f232dadfb6d9c478174834f6d039 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Tue, 3 Jan 2023 23:53:05 +0100 Subject: [PATCH] stop using a hardcoded websocket address in ws_client --- src/ws_client.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ws_client.ml b/src/ws_client.ml index 8f7102b..41649a0 100644 --- a/src/ws_client.ml +++ b/src/ws_client.ml @@ -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