Skip to content

Commit

Permalink
Revert "Reconnection Logic Impl"
Browse files Browse the repository at this point in the history
This reverts commit ee94e60.
  • Loading branch information
isaacakakpo1 committed Sep 23, 2024
1 parent ee94e60 commit 6976ad8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
switch (message.socketMethod) {
case SocketMethod.BYE:
{
// make sure to disconnect the telnyxclient on Bye for Decline
//make sure to disconnect the telnyxclient on Bye for Decline
// Only disconnect the socket when the call was ended from push notifications
print("telnyxClient disconnected");
telnyxClient.disconnect();
Expand Down
4 changes: 2 additions & 2 deletions packages/telnyx_webrtc/lib/model/push_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class PushNotification {
}

class PushMetaData {
PushMetaData(
{this.caller_name, this.caller_number, this.call_id, this.voice_sdk_id});
PushMetaData({this.caller_name, this.caller_number, this.call_id});

String? caller_name;
String? caller_number;
Expand All @@ -19,6 +18,7 @@ class PushMetaData {
bool? isAnswer;
bool? isDecline;


PushMetaData.fromJson(Map<dynamic, dynamic> json) {
caller_name = json['caller_name'];
caller_number = json['caller_number'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class ReceivedMessage {
StateParams? stateParams;
IncomingInviteParams? inviteParams;
DialogParams? dialogParams;
String? voiceSdkId;

ReceivedMessage(
{this.jsonrpc,
Expand All @@ -19,8 +18,8 @@ class ReceivedMessage {
this.reattachedParams,
this.stateParams,
this.inviteParams,
this.dialogParams,
this.voiceSdkId});
this.dialogParams
});

ReceivedMessage.fromJson(Map<String, dynamic> json) {
jsonrpc = json['jsonrpc'];
Expand All @@ -34,14 +33,9 @@ class ReceivedMessage {
inviteParams = json['params'] != null
? IncomingInviteParams.fromJson(json['params'])
: null;
if (json['params']['dialogParams'] != null) {
if(json['params']['dialogParams'] != null){
dialogParams = DialogParams.fromJson(json['params']['dialogParams']);
}

if (json['params']['voice_sdk_id'] != null) {
voiceSdkId = json['params']['voice_sdk_id'];
Logger().i('Voice SDK ID: $voiceSdkId');
}
}

Map<String, dynamic> toJson() {
Expand Down Expand Up @@ -77,13 +71,16 @@ class ReceivedResult {
String? sessId;
TelnyxSocketError? error;

ReceivedResult({this.jsonrpc, this.id, this.resultParams});
ReceivedResult(
{this.jsonrpc,
this.id,
this.resultParams});

ReceivedResult.fromJson(Map<String, dynamic> json) {
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 All @@ -107,6 +104,7 @@ class ReceivedResult {
}
}


class ReattachedParams {
List<dynamic>? reattachedSessions;

Expand Down Expand Up @@ -138,11 +136,12 @@ class ReattachedParams {
class ResultParams {
StateParams? stateParams;

ResultParams({this.stateParams});
ResultParams(
{this.stateParams});

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 All @@ -153,7 +152,6 @@ class ResultParams {
return data;
}
}

class StateParams {
String? state;

Expand Down
40 changes: 6 additions & 34 deletions packages/telnyx_webrtc/lib/telnyx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'dart:async';
import 'dart:convert';
import 'dart:ffi';
import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telnyx_webrtc/model/verto/send/attach_call_message.dart';
Expand All @@ -24,7 +25,6 @@ import 'model/call_state.dart';
import 'model/jsonrpc.dart';
import 'model/push_notification.dart';
import 'model/verto/send/pong_message_body.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';

typedef OnSocketMessageReceived = void Function(TelnyxMessage message);
typedef OnSocketErrorReceived = void Function(TelnyxSocketError message);
Expand Down Expand Up @@ -87,26 +87,6 @@ class TelnyxClient {
String ringtonePath = "";
String ringBackpath = "";
PushMetaData? _pushMetaData;
StreamSubscription<InternetConnectionStatus>? _connectionCheckerSubscription;

final connectionChecker = InternetConnectionChecker();

void checkReconnection() {
final _connectionCheckerSubscription =
connectionChecker.onStatusChange.listen(
(InternetConnectionStatus status) {
if (status == InternetConnectionStatus.connected) {
if (activeCalls().isNotEmpty) {
_reconnectToSocket();
}
} else {
//
}
},
);

// Remember to cancel the subscription when it's no longer needed
}

TelnyxClient() {
// Default implementation of onSocketMessageReceived
Expand Down Expand Up @@ -229,7 +209,6 @@ class TelnyxClient {
void _connectWithCallBack(
PushMetaData? pushMetaData, OnOpenCallback openCallback) {
_logger.i('connect() ${pushMetaData?.toJson()}');
_pushMetaData = pushMetaData;
try {
if (pushMetaData?.voice_sdk_id != null) {
txSocket.hostAddress =
Expand All @@ -241,7 +220,6 @@ class TelnyxClient {
txSocket.hostAddress = _storedHostAddress;
_logger.i('connecting to WebSocket $_storedHostAddress');
}

txSocket.connect();

txSocket.onOpen = () {
Expand All @@ -250,7 +228,6 @@ class TelnyxClient {
_logger.i('Web Socket is now connected');
_onOpen();
openCallback.call();
_connectionCheckerSubscription?.cancel();
};

txSocket.onMessage = (dynamic data) {
Expand Down Expand Up @@ -602,7 +579,11 @@ class TelnyxClient {
}

void updateCall(Call call) {
calls[call.callId!] = call;
if (calls.containsKey(call.callId)) {
calls[call.callId!] = call;
} else {
calls[call.callId!] = call;
}
}

/// Closes the socket connection, effectively logging the user out.
Expand Down Expand Up @@ -630,8 +611,6 @@ class TelnyxClient {
}

/// Closes the socket connection, effectively logging the user out.
/// You must recconnect to the socket connection to continue using the SDK or may result in
/// Unhandled Exception: Bad state: StreamSink is closed
void disconnect() {
_invalidateGatewayResponseTimer();
_resetGatewayCounters();
Expand Down Expand Up @@ -852,13 +831,6 @@ class TelnyxClient {
Call offerCall = _createCall();
offerCall.callId = invite.inviteParams?.callID;
updateCall(offerCall);

//set voice_sdk_id
_pushMetaData = PushMetaData(
caller_number: null,
caller_name: null,
voice_sdk_id: message.message.voiceSdkId);

onSocketMessageReceived.call(message);

offerCall.callHandler
Expand Down
1 change: 0 additions & 1 deletion packages/telnyx_webrtc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies:
audioplayers: ^5.2.1
assets_audio_player: ^3.1.1
shared_preferences: ^2.2.3
internet_connection_checker: ^2.0.0

dev_dependencies:
flutter_test:
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ dependencies:
flutter_callkit_incoming: ^2.0.4+1
shared_preferences: ^2.2.3
permission_handler: ^11.3.1
internet_connection_checker: ^2.0.0


dev_dependencies:
Expand Down

0 comments on commit 6976ad8

Please sign in to comment.