Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call State as Connecting until RTCIceConnectionState.RTCIceConnectionStateConnected #107

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion lib/view/telnyx_client_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class TelnyxClientViewModel with ChangeNotifier {
}

void updateCallFromPush(bool value) {
callState = CallStateStatus.connectingToCall;
callFromPush = value;
notifyListeners();
}
Expand All @@ -123,6 +124,10 @@ class TelnyxClientViewModel with ChangeNotifier {
notifyListeners();
break;
case CallState.ringing:
if (_callState == CallStateStatus.connectingToCall) {
// Ringing state as a result of an invitation after a push notification reaction - ignore invitation as we should be connecting and auto answering
return;
}
_callState = CallStateStatus.ongoingInvitation;
notifyListeners();
break;
Expand Down Expand Up @@ -342,9 +347,13 @@ class TelnyxClientViewModel with ChangeNotifier {
}

void loginWithToken(TokenConfig tokenConfig) {
_loggingIn = true;
notifyListeners();

_localName = tokenConfig.sipCallerIDName;
_localNumber = tokenConfig.sipCallerIDNumber;
_telnyxClient.connectWithToken(tokenConfig);
observeResponses();
}

void call(String destination) {
Expand Down Expand Up @@ -451,7 +460,7 @@ class TelnyxClientViewModel with ChangeNotifier {
headers: <String, dynamic>{'platform': 'flutter'},
);

_callState = CallStateStatus.ongoingCall;
_callState = CallStateStatus.connectingToCall;
notifyListeners();

// Hide notification when call is accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ReceivedMessage {
? ReattachedParams.fromJson(json['params'])
: null;
stateParams =
json['params'] != null ? StateParams.fromJson(json['params']) : null;
json['params'] != null ? StateParams.fromJson(json['params']) : null;
inviteParams = json['params'] != null
? IncomingInviteParams.fromJson(json['params'])
: null;
Expand Down Expand Up @@ -93,7 +93,7 @@ class ReceivedResult {
jsonrpc = json['jsonrpc'];
id = json['id'];
resultParams =
json['result'] != null ? ResultParams.fromJson(json['result']) : null;
json['result'] != null ? ResultParams.fromJson(json['result']) : null;
sessId = json['sessid'];
error = json['error'] != null
? TelnyxSocketError.fromJson(json['error'])
Expand Down Expand Up @@ -152,7 +152,7 @@ class ResultParams {

ResultParams.fromJson(Map<String, dynamic> json) {
stateParams =
json['params'] != null ? StateParams.fromJson(json['params']) : null;
json['params'] != null ? StateParams.fromJson(json['params']) : null;
}

Map<String, dynamic> toJson() {
Expand Down Expand Up @@ -307,4 +307,4 @@ class Variables {
data['Event-Sequence'] = eventSequence;
return data;
}
}
}
4 changes: 4 additions & 0 deletions packages/telnyx_webrtc/lib/peer/peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ class Peer {
peerConnection?.onIceConnectionState = (state) {
_logger.i('Peer :: ICE Connection State change :: $state');
switch (state) {
case RTCIceConnectionState.RTCIceConnectionStateConnected:
final Call? currentCall = _txClient.calls[callId];
currentCall?.callHandler.changeState(CallState.active, currentCall);
onCallStateChange?.call(newSession, CallState.active);
case RTCIceConnectionState.RTCIceConnectionStateFailed:
peerConnection?.restartIce();
return;
Expand Down
19 changes: 8 additions & 11 deletions packages/telnyx_webrtc/lib/telnyx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ class TelnyxClient {
CredentialConfig? credentialConfig,
TokenConfig? tokenConfig,
) {
print(jsonEncode(pushMetaData));
_logger.i(jsonEncode(pushMetaData));
_isCallFromPush = true;

if (pushMetaData.isAnswer == true) {
print('_pendingAnswerFromPush true');
_logger.i('_pendingAnswerFromPush true');
_pendingAnswerFromPush = true;
} else {
print('_pendingAnswerFromPush false');
_logger.i('_pendingAnswerFromPush false');
}

if (pushMetaData.isDecline == true) {
Expand Down Expand Up @@ -262,7 +262,6 @@ class TelnyxClient {
_logger.i(
'Connecting to WebSocket with voice_sdk_id :: ${_pushMetaData?.voiceSdkId}',
);
print('Connecting to WebSocket :: ${txSocket.hostAddress}');
} else {
txSocket.hostAddress = _storedHostAddress;
_logger.i('connecting to WebSocket $_storedHostAddress');
Expand Down Expand Up @@ -345,7 +344,6 @@ class TelnyxClient {
_logger.i(
'Connecting to WebSocket with voice_sdk_id :: ${_pushMetaData?.voiceSdkId}',
);
print('Connecting to WebSocket :: ${txSocket.hostAddress}');
} else {
txSocket.hostAddress = _storedHostAddress;
_logger.i('connecting to WebSocket $_storedHostAddress');
Expand Down Expand Up @@ -586,7 +584,7 @@ class TelnyxClient {
..callId = invite.callID
..sessionCallerName = callerName
..sessionCallerNumber = callerNumber
..callState = CallState.active
..callState = CallState.connecting
..sessionDestinationNumber = invite.callerIdNumber ?? '-1'
..sessionClientState = clientState;

Expand All @@ -603,7 +601,7 @@ class TelnyxClient {
customHeaders,
isAttach,
);
answerCall.callHandler.changeState(CallState.active, answerCall);
answerCall.callHandler.changeState(CallState.connecting, answerCall);
answerCall.stopAudio();
if (answerCall.callId != null) {
updateCall(answerCall);
Expand Down Expand Up @@ -754,7 +752,7 @@ class TelnyxClient {
),
jsonrpc: '2.0',
);
print(
_logger.i(
'attachCallMessage :: ${attachCallMessage.toJson()}',
);
txSocket.send(jsonEncode(attachCallMessage));
Expand Down Expand Up @@ -806,7 +804,6 @@ class TelnyxClient {
}
default:
{
//ToDo(Oli): messaging has changed, we need to look at this again so that we don't get a bunch of default cases for some messages
_logger.i(
'$stateMessage',
);
Expand Down Expand Up @@ -904,7 +901,7 @@ class TelnyxClient {
onSocketMessageReceived.call(message);

offerCall.callHandler
.changeState(CallState.connecting, offerCall);
.changeState(CallState.ringing, offerCall);
if (!_pendingAnswerFromPush) {
offerCall.playRingtone(ringtonePath);
offerCall.callHandler
Expand All @@ -918,7 +915,7 @@ class TelnyxClient {
);
_pendingAnswerFromPush = false;
offerCall.callHandler
.changeState(CallState.active, offerCall);
.changeState(CallState.connecting, offerCall);
}
if (_pendingDeclineFromPush) {
offerCall.endCall();
Expand Down
Loading