team-telnyx / telnyx-webrtc-android

Telnyx Android WebRTC SDK - Enable real-time communication with WebRTC and Telnyx
MIT License
13 stars 2 forks source link

Improve CallState usage #303

Open Del-S opened 1 year ago

Del-S commented 1 year ago

SDK version used: 1.2.20-alpha.

So as I started to work with this lib I noticed CallState enum and I wanted to use it to update the states on the screen. Ex: CallState.Active call starts timer and shows controll buttons (mute, loud speaker and other). But as I noticed our calls contain SDP and thus I will never receive Active state just Connecting and that the call is in progress is send using SocketMethod.ANSWER.

Ok so then I thought I should listen to SocketMethod instead. But in this case when I as a user cancel the call I will only receive CallState.DONE and no SocketMethod. If the user on the other side cancels the call I will receive both CallState.DONE and SocketMethod.BYE.

So my question is. Why should I as a developer need to handle all these situations on my own? Why do I need to check SocketMethod aaand CallState + handle call states direcly? Wouldn't it be easier to just update CallState properly? If this were the case I would have 1 source of truth for call UI. I could connect the state to CallState and be done with it. In this case I cannot. :(

In this case I need to start a call: 1) When the app receives SocketMethod.ANSWER for outgoing calls. 2) When the user clicks accept call for incomming call.

In this case I need to cancel a call: 1) When user clicks declines incomming call. 2) When the app receives SocketMethod.BYE.

In the cancel case I noticed that CallState.DONE is received every time.

Del-S commented 1 year ago

I also noticed when I create a call. It goes to CallState.RINGING. I cancel the call then it goes to CallState.DONE. But when I create another call it is already in DONE state which makes no sense.

// First call
TEST: active calls {cf917080-0d21-42a9-b9b3-676b8b30a1b5=com.telnyx.webrtc.sdk.Call@5dba54a}
TEST: active state RINGING

// Second call
TEST: active calls {e2d98915-6308-4d8b-af6e-ae4b17aad390=com.telnyx.webrtc.sdk.Call@5dba54a}
TEST: active state DONE
Del-S commented 1 year ago

So the improvements from 1.2.21-alpha seem fine but I still do not receive CallState.RINGING in call state for outgoing call. So I had to manully send it when I receive SocketState.Ringing.