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

- Connect to Same instance when call is from PushNotification #62

Merged
merged 2 commits into from
Aug 1, 2024
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
66 changes: 33 additions & 33 deletions .flutter-plugins
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# This is a generated file; do not edit or check into version control.
assets_audio_player=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\assets_audio_player-3.1.1\\
assets_audio_player_web=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\assets_audio_player_web-3.1.1\\
audioplayers=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers-5.2.1\\
audioplayers_android=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers_android-4.0.3\\
audioplayers_darwin=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers_darwin-5.0.2\\
audioplayers_linux=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers_linux-3.1.0\\
audioplayers_web=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers_web-4.1.0\\
audioplayers_windows=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\audioplayers_windows-3.1.0\\
firebase_core=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_core-3.2.0\\
firebase_core_web=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_core_web-2.17.3\\
firebase_messaging=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_messaging-15.0.3\\
firebase_messaging_web=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\firebase_messaging_web-3.8.11\\
flutter_callkit_incoming=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_callkit_incoming-2.0.4+1\\
flutter_local_notifications=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_local_notifications-16.3.3\\
flutter_local_notifications_linux=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_local_notifications_linux-4.0.1\\
flutter_webrtc=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_webrtc-0.11.5\\
fluttertoast=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\fluttertoast-8.2.6\\
path_provider=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider-2.1.3\\
path_provider_android=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_android-2.2.7\\
path_provider_foundation=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_foundation-2.4.0\\
path_provider_linux=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_linux-2.2.1\\
path_provider_windows=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\path_provider_windows-2.3.0\\
permission_handler=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler-11.3.1\\
permission_handler_android=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_android-12.0.7\\
permission_handler_apple=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_apple-9.4.5\\
permission_handler_html=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_html-0.1.2\\
permission_handler_windows=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_windows-0.2.1\\
shared_preferences=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences-2.2.3\\
shared_preferences_android=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_android-2.2.3\\
shared_preferences_foundation=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_foundation-2.4.0\\
shared_preferences_linux=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_linux-2.3.2\\
shared_preferences_web=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_web-2.3.0\\
shared_preferences_windows=C:\\Users\\isaac\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\shared_preferences_windows-2.3.2\\
assets_audio_player=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player-3.1.1/
assets_audio_player_web=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player_web-3.1.1/
audioplayers=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers-5.2.1/
audioplayers_android=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_android-4.0.3/
audioplayers_darwin=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_darwin-5.0.2/
audioplayers_linux=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_linux-3.1.0/
audioplayers_web=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_web-4.1.0/
audioplayers_windows=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_windows-3.1.0/
firebase_core=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-3.3.0/
firebase_core_web=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core_web-2.17.4/
firebase_messaging=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-15.0.4/
firebase_messaging_web=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging_web-3.8.12/
flutter_callkit_incoming=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.4+1/
flutter_local_notifications=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.3.3/
flutter_local_notifications_linux=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications_linux-4.0.1/
flutter_webrtc=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/
fluttertoast=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.6/
path_provider=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider-2.1.4/
path_provider_android=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_android-2.2.9/
path_provider_foundation=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/
path_provider_linux=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/
path_provider_windows=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_windows-2.3.0/
permission_handler=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler-11.3.1/
permission_handler_android=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.7/
permission_handler_apple=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.5/
permission_handler_html=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.2/
permission_handler_windows=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/
shared_preferences=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences-2.3.0/
shared_preferences_android=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_android-2.3.0/
shared_preferences_foundation=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.5.0/
shared_preferences_linux=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.4.0/
shared_preferences_web=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_web-2.4.0/
shared_preferences_windows=/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.4.0/
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions .lh/packages/telnyx_webrtc/lib/tx_socket.dart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"sourceFile": "packages/telnyx_webrtc/lib/tx_socket.dart",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 1,
"patches": [
{
"date": 1722541750187,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1722542818509,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -15,9 +15,9 @@\n late OnOpenCallback onOpen;\n late OnMessageCallback onMessage;\n late OnCloseCallback onClose;\n \n- Future<void> connect() async {\n+ void connect() async {\n try {\n print(\"TxSocket :: connect : $hostAddress\");\n _socket = await WebSocket.connect(hostAddress);\n _logger.i('Connecting to $hostAddress');\n"
}
],
"date": 1722541750187,
"name": "Commit-0",
"content": "import 'dart:io';\nimport 'package:logger/logger.dart';\n\ntypedef OnMessageCallback = void Function(dynamic msg);\ntypedef OnCloseCallback = void Function(int code, String reason);\ntypedef OnOpenCallback = void Function();\n\nclass TxSocket {\n TxSocket(this.hostAddress);\n\n String hostAddress;\n final _logger = Logger();\n\n late WebSocket _socket;\n late OnOpenCallback onOpen;\n late OnMessageCallback onMessage;\n late OnCloseCallback onClose;\n\n Future<void> connect() async {\n try {\n print(\"TxSocket :: connect : $hostAddress\");\n _socket = await WebSocket.connect(hostAddress);\n _logger.i('Connecting to $hostAddress');\n _socket.pingInterval = const Duration(seconds: 10);\n _socket.timeout(const Duration(seconds: 30));\n onOpen.call();\n _socket.listen((dynamic data) {\n onMessage.call(data);\n }, onDone: () {\n onClose.call(_socket.closeCode ?? 0,\n _socket.closeReason ?? \"Closed for unknown reason\");\n });\n } catch (e) {\n onClose.call(500, e.toString());\n }\n }\n\n void send(dynamic data) {\n _socket.add(data);\n _logger.i('TxSocket :: send : \\n\\n$data');\n }\n\n void close() {\n _socket.close();\n }\n}\n"
}
]
}
37 changes: 21 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'package:telnyx_webrtc/model/socket_method.dart';
final logger = Logger();
final mainViewModel = MainViewModel();
const MOCK_USER = "<UserName>";
const MOCK_PASSWORD = "<Password>";
const MOCK_PASSWORD = "Password";
// Android Only - Push Notifications
@pragma('vm:entry-point')
Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
Expand Down Expand Up @@ -86,7 +86,7 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {

logger.i("iOS notification token :: $token");
}
var credentialConfig = CredentialConfig(MOCK_USER,MOCK_PASSWORD,
var credentialConfig = CredentialConfig(MOCK_USER, MOCK_PASSWORD,
"<caller_id>", "<caller_number>", token, true, "", "");
telnyxClient.handlePushNotification(
pushMetaData, credentialConfig, null);
Expand Down Expand Up @@ -218,7 +218,6 @@ Future<void> main() async {
}

Future<void> askForNotificationPermission() async {

FlutterCallkitIncoming.requestNotificationPermission("notification");
var status = await Permission.notification.status;
if (status.isDenied) {
Expand All @@ -230,10 +229,11 @@ Future<void> askForNotificationPermission() async {
if (await Permission.location.isRestricted) {
// The OS restricts access, for example, because of parental controls.
}

}

Future<void> handlePush(Map<dynamic, dynamic> data) async {
mainViewModel.callFromPush = true;

logger.i("Handle Push Init");
String? token;

Expand All @@ -249,7 +249,6 @@ Future<void> handlePush(Map<dynamic, dynamic> data) async {
}
var credentialConfig = CredentialConfig(MOCK_USER, MOCK_PASSWORD,
"<caller_id>", "<caller_number>", token, true, "", "");
mainViewModel.callFromPush = true;
mainViewModel.handlePushNotification(pushMetaData!, credentialConfig, null);
mainViewModel.observeResponses();
logger.i('actionCallIncoming :: Received Incoming Call! Handle Push');
Expand Down Expand Up @@ -280,17 +279,23 @@ class _MyAppState extends State<MyApp> {
});
}

// Handle Push when app comes from background :: Only for Android
TelnyxClient.getPushData().then((data) {
// whenever you open the app from the terminate state by clicking on Notification message,
if (data != null) {
handlePush(data);
print("getPushData : getInitialMessage :: Notification Message: $data");
} else {
mainViewModel.connect();
print("getPushData : No data");
}
});
if (Platform.isAndroid) {
// Handle Push when app comes from background :: Only for Android
TelnyxClient.getPushData().then((data) {
// whenever you open the app from the terminate state by clicking on Notification message,
if (data != null) {
handlePush(data);
print(
"getPushData : getInitialMessage :: Notification Message: $data");
} else {
mainViewModel.connect();
print("getPushData : No data");
}
});
} else if (Platform.isIOS && !mainViewModel.callFromPush) {
logger.i("iOS :: connect");
mainViewModel.connect();
}
}

// This widget is the root of your application.
Expand Down
6 changes: 3 additions & 3 deletions lib/main_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ class MainViewModel with ChangeNotifier {
case SocketMethod.CLIENT_READY:
{
_registered = true;
logger.i("Registered :: $_registered");
break;
}
case SocketMethod.INVITE:
{

observeCurrentCall();

_incomingInvite = message.message.inviteParams;
Expand Down Expand Up @@ -196,7 +196,7 @@ class MainViewModel with ChangeNotifier {
notifyListeners();
}

void login(CredentialConfig credentialConfig) {
void login(CredentialConfig credentialConfig) async {
_localName = credentialConfig.sipCallerIDName;
_localNumber = credentialConfig.sipCallerIDNumber;
_telnyxClient.credentialLogin(credentialConfig);
Expand Down Expand Up @@ -232,7 +232,7 @@ class MainViewModel with ChangeNotifier {
}

// Hide if not already hidden
if(Platform.isAndroid && !acceptFromNotification) {
if (Platform.isAndroid && !acceptFromNotification) {
CallKitParams callKitParams = CallKitParams(
id: _incomingInvite!.callID,
nameCaller: _incomingInvite!.callerIdName,
Expand Down
1 change: 0 additions & 1 deletion lib/view/screen/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class _LoginScreenState extends State<LoginScreen> with WidgetsBindingObserver {
Widget build(BuildContext context) {
Provider.of<MainViewModel>(context, listen: true).observeResponses();


bool registered =
Provider.of<MainViewModel>(context, listen: true).registered;
if (registered) {
Expand Down
Loading
Loading