Add controls to pause or hang up a call

This commit is contained in:
Correl Roush 2024-12-22 02:22:49 -05:00
parent 8326c60e53
commit 332b95e435
2 changed files with 76 additions and 15 deletions

View file

@ -42,7 +42,7 @@
app.ports.newCallState.send("on call");
},
onCallHold: (held) => {
app.ports.newCallState.send("on hold");
app.ports.newCallState.send(held ? "on hold" : "on call");
},
onCallHangup: () => {
app.ports.newCallState.send(null);
@ -75,6 +75,12 @@
app.ports.dial.subscribe(function(address) {
simpleUser.call(address);
});
app.ports.hold.subscribe(function(hold) {
hold ? simpleUser.hold() : simpleUser.unhold();
});
app.ports.hangUp.subscribe(function() {
simpleUser.hangup();
});
</script>
</body>
</html>

View file

@ -68,6 +68,8 @@ type Msg
= NewConnectionState Json.Decode.Value
| NewCallState Json.Decode.Value
| ContactSelected Contact
| UpdateHold
| HangUp
decodeContact : Json.Decode.Decoder Contact
@ -168,6 +170,25 @@ update msg model =
_ ->
( model, Cmd.none )
UpdateHold ->
case model.call of
Just OnCall ->
( model, hold True )
Just OnHold ->
( model, hold False )
_ ->
( model, Cmd.none )
HangUp ->
case model.call of
Just call ->
( model, hangUp () )
Nothing ->
( model, Cmd.none )
view : Model -> E.Element Msg
view model =
@ -201,23 +222,51 @@ view model =
]
, case model.call of
Just call ->
E.el
let
button : Msg -> String -> E.Element Msg
button msg text =
E.el
[ E.padding 20
, Background.color <| E.rgb255 220 220 220
, Border.rounded 20
, E.pointer
, Events.onClick msg
]
<|
E.text text
in
E.column
[ E.centerX
, E.centerY
, Font.size 120
, Font.color <|
case call of
Ringing ->
E.rgb255 255 255 0
OnCall ->
E.rgb255 0 255 0
OnHold ->
E.rgb255 0 0 255
, E.spacing 20
]
[ E.el
[ E.centerX
, Font.size 120
, Font.color <|
case call of
Ringing ->
E.rgb255 255 255 0
OnCall ->
E.rgb255 0 255 0
OnHold ->
E.rgb255 0 0 255
]
<|
E.text ""
, E.row [ E.spacing 30 ]
[ button UpdateHold <|
case call of
OnHold ->
"Resume"
_ ->
"Hold"
, button HangUp "Hang Up"
]
]
<|
E.text ""
Nothing ->
E.column [ E.width E.fill ] <| List.map viewContact model.configuration.contacts
@ -238,6 +287,12 @@ port connect : Configuration -> Cmd msg
port dial : String -> Cmd msg
port hold : Bool -> Cmd msg
port hangUp : () -> Cmd msg
port newConnectionState : (Json.Decode.Value -> msg) -> Sub msg