From e5e27270e3fdd77bf66d262148a5f25b61284b27 Mon Sep 17 00:00:00 2001 From: Isaac <134492608+isaacakakpo1@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:13:17 +0000 Subject: [PATCH 1/2] - Connect to Same instance when call is from PushNotification --- packages/telnyx_webrtc/lib/telnyx_client.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/telnyx_webrtc/lib/telnyx_client.dart b/packages/telnyx_webrtc/lib/telnyx_client.dart index 38d8561..4b50322 100644 --- a/packages/telnyx_webrtc/lib/telnyx_client.dart +++ b/packages/telnyx_webrtc/lib/telnyx_client.dart @@ -86,6 +86,7 @@ class TelnyxClient { late OnSocketErrorReceived onSocketErrorReceived; String ringtonePath = ""; String ringBackpath = ""; + PushMetaData? _pushMetaData; TelnyxClient() { // Default implementation of onSocketMessageReceived @@ -210,6 +211,7 @@ class TelnyxClient { if (pushMetaData?.voice_sdk_id != null) { txSocket.hostAddress = "$_storedHostAddress?voice_sdk_id=${pushMetaData?.voice_sdk_id}"; + _pushMetaData = pushMetaData; _logger.i( 'Connecting to WebSocket with voice_sdk_id :: ${pushMetaData?.voice_sdk_id}'); print("Connecting to WebSocket :: ${txSocket.hostAddress}"); @@ -252,6 +254,16 @@ class TelnyxClient { } _logger.i('connecting to WebSocket $_storedHostAddress'); try { + if(_pushMetaData != null){ + txSocket.hostAddress = + "$_storedHostAddress?voice_sdk_id=${_pushMetaData?.voice_sdk_id}"; + _logger.i( + 'Connecting to WebSocket with voice_sdk_id :: ${_pushMetaData?.voice_sdk_id}'); + print("Connecting to WebSocket :: ${txSocket.hostAddress}"); + } else { + txSocket.hostAddress = _storedHostAddress; + _logger.i('connecting to WebSocket $_storedHostAddress'); + } txSocket.onOpen = () { _closed = false; _connected = true; From 7327a38c6952b45496d6753c7120bceec1e7cf10 Mon Sep 17 00:00:00 2001 From: isaacakakpo1 Date: Thu, 1 Aug 2024 21:00:48 +0000 Subject: [PATCH 2/2] Update iOS Login Logic --- .flutter-plugins | 66 +++++------ .flutter-plugins-dependencies | 2 +- .../telnyx_webrtc/lib/tx_socket.dart.json | 22 ++++ lib/main.dart | 37 +++--- lib/main_view_model.dart | 6 +- lib/view/screen/login_screen.dart | 1 - packages/telnyx_webrtc/lib/telnyx_client.dart | 109 ++++++++++-------- 7 files changed, 140 insertions(+), 103 deletions(-) create mode 100644 .lh/packages/telnyx_webrtc/lib/tx_socket.dart.json diff --git a/.flutter-plugins b/.flutter-plugins index 3bbf8c6..f29c598 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -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/ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 32dc31a..423b8d3 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"assets_audio_player","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player-3.1.1\\\\","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player_web-3.1.1\\\\","native_build":true,"dependencies":[]},{"name":"audioplayers_darwin","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_darwin-5.0.2\\\\","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-3.2.0\\\\","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_messaging-15.0.3\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_callkit_incoming-2.0.4+1\\\\","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_local_notifications-16.3.3\\\\","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_webrtc-0.11.5\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.6\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_apple-9.4.5\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"assets_audio_player","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player-3.1.1\\\\","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player_web-3.1.1\\\\","native_build":true,"dependencies":[]},{"name":"audioplayers_android","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_android-4.0.3\\\\","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-3.2.0\\\\","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_messaging-15.0.3\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_callkit_incoming-2.0.4+1\\\\","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_local_notifications-16.3.3\\\\","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_webrtc-0.11.5\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.6\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.7\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_android-12.0.7\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.2.3\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"assets_audio_player","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player-3.1.1\\\\","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player_web-3.1.1\\\\","native_build":true,"dependencies":[]},{"name":"audioplayers_darwin","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_darwin-5.0.2\\\\","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-3.2.0\\\\","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_messaging-15.0.3\\\\","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_local_notifications","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_local_notifications-16.3.3\\\\","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_webrtc-0.11.5\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"audioplayers_linux","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_linux-3.1.0\\\\","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications_linux","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_local_notifications_linux-4.0.1\\\\","native_build":false,"dependencies":[]},{"name":"flutter_webrtc","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_webrtc-0.11.5\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.3.2\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"audioplayers_windows","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_windows-3.1.0\\\\","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core-3.2.0\\\\","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_webrtc-0.11.5\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.3.0\\\\","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_windows-0.2.1\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_windows","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.3.2\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"assets_audio_player_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\assets_audio_player_web-3.1.1\\\\","dependencies":[]},{"name":"audioplayers_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audioplayers_web-4.1.0\\\\","dependencies":[]},{"name":"firebase_core_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_core_web-2.17.3\\\\","dependencies":[]},{"name":"firebase_messaging_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\firebase_messaging_web-3.8.11\\\\","dependencies":["firebase_core_web"]},{"name":"fluttertoast","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.6\\\\","dependencies":[]},{"name":"permission_handler_html","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_html-0.1.2\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"C:\\\\Users\\\\isaac\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.3.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"assets_audio_player","dependencies":["path_provider","assets_audio_player_web"]},{"name":"assets_audio_player_web","dependencies":[]},{"name":"audioplayers","dependencies":["audioplayers_android","audioplayers_darwin","audioplayers_linux","audioplayers_web","audioplayers_windows","path_provider"]},{"name":"audioplayers_android","dependencies":[]},{"name":"audioplayers_darwin","dependencies":[]},{"name":"audioplayers_linux","dependencies":[]},{"name":"audioplayers_web","dependencies":[]},{"name":"audioplayers_windows","dependencies":[]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_messaging","dependencies":["firebase_core","firebase_messaging_web"]},{"name":"firebase_messaging_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"flutter_callkit_incoming","dependencies":[]},{"name":"flutter_local_notifications","dependencies":["flutter_local_notifications_linux"]},{"name":"flutter_local_notifications_linux","dependencies":[]},{"name":"flutter_webrtc","dependencies":["path_provider"]},{"name":"fluttertoast","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2024-07-31 23:33:24.076263","version":"3.22.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"assets_audio_player","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player-3.1.1/","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player_web-3.1.1/","native_build":true,"dependencies":[]},{"name":"audioplayers_darwin","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_darwin-5.0.2/","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-3.3.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-15.0.4/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.4+1/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.3.3/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.6/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_apple-9.4.5/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.5.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"assets_audio_player","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player-3.1.1/","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player_web-3.1.1/","native_build":true,"dependencies":[]},{"name":"audioplayers_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_android-4.0.3/","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-3.3.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-15.0.4/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.4+1/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.3.3/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.6/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_android-2.2.9/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.7/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_android-2.3.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"assets_audio_player","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player-3.1.1/","native_build":true,"dependencies":["assets_audio_player_web"]},{"name":"assets_audio_player_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player_web-3.1.1/","native_build":true,"dependencies":[]},{"name":"audioplayers_darwin","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_darwin-5.0.2/","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-3.3.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-15.0.4/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.3.3/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.5.0/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"audioplayers_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_linux-3.1.0/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications_linux-4.0.1/","native_build":false,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.4.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"audioplayers_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_windows-3.1.0/","native_build":true,"dependencies":[]},{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-3.3.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.11.5/","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_windows-2.3.0/","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.1/","native_build":true,"dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.4.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"assets_audio_player_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/assets_audio_player_web-3.1.1/","dependencies":[]},{"name":"audioplayers_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/audioplayers_web-4.1.0/","dependencies":[]},{"name":"firebase_core_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core_web-2.17.4/","dependencies":[]},{"name":"firebase_messaging_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging_web-3.8.12/","dependencies":["firebase_core_web"]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.6/","dependencies":[]},{"name":"permission_handler_html","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/shared_preferences_web-2.4.0/","dependencies":[]}]},"dependencyGraph":[{"name":"assets_audio_player","dependencies":["path_provider","assets_audio_player_web"]},{"name":"assets_audio_player_web","dependencies":[]},{"name":"audioplayers","dependencies":["audioplayers_android","audioplayers_darwin","audioplayers_linux","audioplayers_web","audioplayers_windows","path_provider"]},{"name":"audioplayers_android","dependencies":[]},{"name":"audioplayers_darwin","dependencies":[]},{"name":"audioplayers_linux","dependencies":[]},{"name":"audioplayers_web","dependencies":[]},{"name":"audioplayers_windows","dependencies":[]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_messaging","dependencies":["firebase_core","firebase_messaging_web"]},{"name":"firebase_messaging_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"flutter_callkit_incoming","dependencies":[]},{"name":"flutter_local_notifications","dependencies":["flutter_local_notifications_linux"]},{"name":"flutter_local_notifications_linux","dependencies":[]},{"name":"flutter_webrtc","dependencies":["path_provider"]},{"name":"fluttertoast","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2024-08-01 20:44:53.334284","version":"3.22.3"} \ No newline at end of file diff --git a/.lh/packages/telnyx_webrtc/lib/tx_socket.dart.json b/.lh/packages/telnyx_webrtc/lib/tx_socket.dart.json new file mode 100644 index 0000000..87de850 --- /dev/null +++ b/.lh/packages/telnyx_webrtc/lib/tx_socket.dart.json @@ -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 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 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" + } + ] +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index bcf4a17..3053199 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -24,7 +24,7 @@ import 'package:telnyx_webrtc/model/socket_method.dart'; final logger = Logger(); final mainViewModel = MainViewModel(); const MOCK_USER = ""; -const MOCK_PASSWORD = ""; +const MOCK_PASSWORD = "Password"; // Android Only - Push Notifications @pragma('vm:entry-point') Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { @@ -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, "", "", token, true, "", ""); telnyxClient.handlePushNotification( pushMetaData, credentialConfig, null); @@ -218,7 +218,6 @@ Future main() async { } Future askForNotificationPermission() async { - FlutterCallkitIncoming.requestNotificationPermission("notification"); var status = await Permission.notification.status; if (status.isDenied) { @@ -230,10 +229,11 @@ Future askForNotificationPermission() async { if (await Permission.location.isRestricted) { // The OS restricts access, for example, because of parental controls. } - } Future handlePush(Map data) async { + mainViewModel.callFromPush = true; + logger.i("Handle Push Init"); String? token; @@ -249,7 +249,6 @@ Future handlePush(Map data) async { } var credentialConfig = CredentialConfig(MOCK_USER, MOCK_PASSWORD, "", "", token, true, "", ""); - mainViewModel.callFromPush = true; mainViewModel.handlePushNotification(pushMetaData!, credentialConfig, null); mainViewModel.observeResponses(); logger.i('actionCallIncoming :: Received Incoming Call! Handle Push'); @@ -280,17 +279,23 @@ class _MyAppState extends State { }); } - // 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. diff --git a/lib/main_view_model.dart b/lib/main_view_model.dart index 87841c1..144ada8 100644 --- a/lib/main_view_model.dart +++ b/lib/main_view_model.dart @@ -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; @@ -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); @@ -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, diff --git a/lib/view/screen/login_screen.dart b/lib/view/screen/login_screen.dart index 0c463ca..e000146 100644 --- a/lib/view/screen/login_screen.dart +++ b/lib/view/screen/login_screen.dart @@ -94,7 +94,6 @@ class _LoginScreenState extends State with WidgetsBindingObserver { Widget build(BuildContext context) { Provider.of(context, listen: true).observeResponses(); - bool registered = Provider.of(context, listen: true).registered; if (registered) { diff --git a/packages/telnyx_webrtc/lib/telnyx_client.dart b/packages/telnyx_webrtc/lib/telnyx_client.dart index 4b50322..7acaee6 100644 --- a/packages/telnyx_webrtc/lib/telnyx_client.dart +++ b/packages/telnyx_webrtc/lib/telnyx_client.dart @@ -206,43 +206,40 @@ class TelnyxClient { void _connectWithCallBack( PushMetaData? pushMetaData, OnOpenCallback openCallback) { _logger.i('connect() ${pushMetaData?.toJson()}'); - if (pushMetaData?.voice_sdk_id != null) { - try { - if (pushMetaData?.voice_sdk_id != null) { - txSocket.hostAddress = - "$_storedHostAddress?voice_sdk_id=${pushMetaData?.voice_sdk_id}"; - _pushMetaData = pushMetaData; - _logger.i( - 'Connecting to WebSocket with voice_sdk_id :: ${pushMetaData?.voice_sdk_id}'); - print("Connecting to WebSocket :: ${txSocket.hostAddress}"); - } else { - txSocket.hostAddress = _storedHostAddress; - _logger.i('connecting to WebSocket $_storedHostAddress'); - } - txSocket.connect(); - - txSocket.onOpen = () { - _closed = false; - _connected = true; - _logger.i('Web Socket is now connected'); - _onOpen(); - openCallback.call(); - }; - - txSocket.onMessage = (dynamic data) { - _onMessage(data); - }; - - txSocket.onClose = (int closeCode, String closeReason) { - _logger.i('Closed [$closeCode, $closeReason]!'); - _connected = false; - _onClose(true, closeCode, closeReason); - }; - } catch (e, s) { - _logger.e(e.toString(), null, s); - _connected = false; - _logger.e('WebSocket $_storedHostAddress error: $e'); + try { + if (pushMetaData?.voice_sdk_id != null) { + txSocket.hostAddress = + "$_storedHostAddress?voice_sdk_id=${pushMetaData?.voice_sdk_id}"; + _logger.i( + 'Connecting to WebSocket with voice_sdk_id :: ${pushMetaData?.voice_sdk_id}'); + print("Connecting to WebSocket :: ${txSocket.hostAddress}"); + } else { + txSocket.hostAddress = _storedHostAddress; + _logger.i('connecting to WebSocket $_storedHostAddress'); } + txSocket.connect(); + + txSocket.onOpen = () { + _closed = false; + _connected = true; + _logger.i('Web Socket is now connected'); + _onOpen(); + openCallback.call(); + }; + + txSocket.onMessage = (dynamic data) { + _onMessage(data); + }; + + txSocket.onClose = (int closeCode, String closeReason) { + _logger.i('Closed [$closeCode, $closeReason]!'); + _connected = false; + _onClose(true, closeCode, closeReason); + }; + } catch (e, s) { + _logger.e(e.toString(), null, s); + _connected = false; + _logger.e('WebSocket $_storedHostAddress error: $e'); } } @@ -254,7 +251,7 @@ class TelnyxClient { } _logger.i('connecting to WebSocket $_storedHostAddress'); try { - if(_pushMetaData != null){ + if (_pushMetaData != null) { txSocket.hostAddress = "$_storedHostAddress?voice_sdk_id=${_pushMetaData?.voice_sdk_id}"; _logger.i( @@ -331,7 +328,7 @@ class TelnyxClient { /* * initialise this callback to handle call state changes on the client side * */ - print("Call state not overridden :Call State Changed to $state"); + print("Call state not overridden :Call State Changed to $state"); _logger.i('Call state not overridden :Call State Changed to $state'); }), _callEnded); return _call!; @@ -374,8 +371,13 @@ class TelnyxClient { jsonrpc: JsonRPCConstant.jsonrpc); String jsonLoginMessage = jsonEncode(loginMessage); - - txSocket.send(jsonLoginMessage); + if (isConnected()) { + txSocket.send(jsonLoginMessage); + } else { + _connectWithCallBack(null, () { + txSocket.send(jsonLoginMessage); + }); + } } /// Uses the provided [config] to send a token login message to the Telnyx backend. @@ -414,7 +416,13 @@ class TelnyxClient { String jsonLoginMessage = jsonEncode(loginMessage); _logger.i('Token Login Message $jsonLoginMessage'); - txSocket.send(jsonLoginMessage); + if (isConnected()) { + txSocket.send(jsonLoginMessage); + } else { + _connectWithCallBack(null, () { + txSocket.send(jsonLoginMessage); + }); + } } // Creates an invitation to send to a [destinationNumber] or SIP Destination @@ -487,7 +495,7 @@ class TelnyxClient { void updateCall(Call call) { if (calls.containsKey(call.callId)) { calls[call.callId!] = call; - }else{ + } else { calls[call.callId!] = call; } } @@ -604,18 +612,21 @@ class TelnyxClient { defaultTargetPlatform == TargetPlatform.android ? "android" : "ios"; - String pushEnvironment = kDebugMode ? "development" : "production"; + String pushEnvironment = + kDebugMode ? "development" : "production"; AttachCallMessage attachCallMessage = AttachCallMessage( method: SocketMethod.ATTACH_CALL, id: const Uuid().v4(), params: Params( - userVariables: { - "push_notification_environment": pushEnvironment, - "push_notification_provider": platform, - }, - ), + userVariables: { + "push_notification_environment": + pushEnvironment, + "push_notification_provider": platform, + }, + ), jsonrpc: "2.0"); - print("attachCallMessage :: ${attachCallMessage.toJson()}"); + print( + "attachCallMessage :: ${attachCallMessage.toJson()}"); txSocket.send(jsonEncode(attachCallMessage)); _isCallFromPush = false; }