mirror of
https://github.com/correl/riichi.git
synced 2024-11-14 11:09:36 +00:00
Dynamically configure websocket host
This commit is contained in:
parent
91c04ba43b
commit
a0858ca4ed
3 changed files with 20 additions and 11 deletions
|
@ -7,6 +7,10 @@
|
|||
<link rel="stylesheet" href="/css/riichi.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">Elm.Riichi.fullscreen()</script>
|
||||
<script type="text/javascript">
|
||||
Elm.Riichi.fullscreen({
|
||||
"websocket": "ws://" + window.location.host + "/websocket"
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -11,7 +11,8 @@ import WebSocket
|
|||
|
||||
|
||||
type alias Model =
|
||||
{ game : Maybe Game
|
||||
{ url : String
|
||||
, game : Maybe Game
|
||||
, choice : Maybe (List Action)
|
||||
, log : List String
|
||||
}
|
||||
|
@ -25,9 +26,10 @@ type Msg
|
|||
| NewState Game
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
{ game = Nothing
|
||||
init : String -> Model
|
||||
init url =
|
||||
{ url = url
|
||||
, game = Nothing
|
||||
, choice = Nothing
|
||||
, log = []
|
||||
}
|
||||
|
@ -95,7 +97,7 @@ socketMsg message =
|
|||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
WebSocket.listen "ws://localhost:8080/websocket" Receive
|
||||
WebSocket.listen model.url Receive
|
||||
|
||||
|
||||
view : Model -> Html msg
|
||||
|
|
|
@ -17,16 +17,19 @@ type alias Model =
|
|||
, client : Client.Model
|
||||
}
|
||||
|
||||
type alias Flags =
|
||||
{ websocket : String }
|
||||
|
||||
|
||||
type Msg
|
||||
= SetTileset S.Tileset
|
||||
| ClientMsg Client.Msg
|
||||
|
||||
|
||||
init : ( Model, Cmd Msg )
|
||||
init =
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
( { tileset = S.White
|
||||
, client = Client.init
|
||||
, client = Client.init flags.websocket
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
@ -50,9 +53,9 @@ update msg model =
|
|||
)
|
||||
|
||||
|
||||
main : Program Never Model Msg
|
||||
main : Program Flags Model Msg
|
||||
main =
|
||||
program
|
||||
programWithFlags
|
||||
{ init = init
|
||||
, update = update
|
||||
, view = view
|
||||
|
|
Loading…
Reference in a new issue