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