diff --git a/video_call/android/app/build.gradle b/video_call/android/app/build.gradle index ac230a0..0255996 100644 --- a/video_call/android/app/build.gradle +++ b/video_call/android/app/build.gradle @@ -37,7 +37,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.voximplant.flutter.videocall" // set minSdk to 21 since multidex is enabled by default since this version - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/video_call/ios/Podfile.lock b/video_call/ios/Podfile.lock index 237088a..52a817d 100644 --- a/video_call/ios/Podfile.lock +++ b/video_call/ios/Podfile.lock @@ -15,9 +15,9 @@ PODS: - FirebaseCoreInternal (~> 10.0) - GoogleUtilities/Environment (~> 7.8) - GoogleUtilities/Logger (~> 7.8) - - FirebaseCoreInternal (10.13.0): + - FirebaseCoreInternal (10.25.0): - "GoogleUtilities/NSData+zlib (~> 7.8)" - - FirebaseInstallations (10.13.0): + - FirebaseInstallations (10.25.0): - FirebaseCore (~> 10.0) - GoogleUtilities/Environment (~> 7.8) - GoogleUtilities/UserDefaults (~> 7.8) @@ -36,46 +36,52 @@ PODS: - Flutter - flutter_local_notifications (0.0.1): - Flutter - - flutter_voximplant (3.8.1): + - flutter_voximplant (3.11.1): - Flutter - - VoxImplantSDK (= 2.46.12) - - GoogleDataTransport (9.2.5): + - VoxImplantSDK (= 2.52.0) + - GoogleDataTransport (9.4.1): - GoogleUtilities/Environment (~> 7.7) - - nanopb (< 2.30910.0, >= 2.30908.0) + - nanopb (< 2.30911.0, >= 2.30908.0) - PromisesObjC (< 3.0, >= 1.2) - - GoogleUtilities/AppDelegateSwizzler (7.11.5): + - GoogleUtilities/AppDelegateSwizzler (7.13.3): - GoogleUtilities/Environment - GoogleUtilities/Logger - GoogleUtilities/Network - - GoogleUtilities/Environment (7.11.5): + - GoogleUtilities/Privacy + - GoogleUtilities/Environment (7.13.3): + - GoogleUtilities/Privacy - PromisesObjC (< 3.0, >= 1.2) - - GoogleUtilities/Logger (7.11.5): + - GoogleUtilities/Logger (7.13.3): - GoogleUtilities/Environment - - GoogleUtilities/Network (7.11.5): + - GoogleUtilities/Privacy + - GoogleUtilities/Network (7.13.3): - GoogleUtilities/Logger - "GoogleUtilities/NSData+zlib" + - GoogleUtilities/Privacy - GoogleUtilities/Reachability - - "GoogleUtilities/NSData+zlib (7.11.5)" - - GoogleUtilities/Reachability (7.11.5): + - "GoogleUtilities/NSData+zlib (7.13.3)": + - GoogleUtilities/Privacy + - GoogleUtilities/Privacy (7.13.3) + - GoogleUtilities/Reachability (7.13.3): - GoogleUtilities/Logger - - GoogleUtilities/UserDefaults (7.11.5): + - GoogleUtilities/Privacy + - GoogleUtilities/UserDefaults (7.13.3): - GoogleUtilities/Logger - - nanopb (2.30909.0): - - nanopb/decode (= 2.30909.0) - - nanopb/encode (= 2.30909.0) - - nanopb/decode (2.30909.0) - - nanopb/encode (2.30909.0) + - GoogleUtilities/Privacy + - nanopb (2.30909.1): + - nanopb/decode (= 2.30909.1) + - nanopb/encode (= 2.30909.1) + - nanopb/decode (2.30909.1) + - nanopb/encode (2.30909.1) - permission_handler_apple (9.1.1): - Flutter - - PromisesObjC (2.3.1) + - PromisesObjC (2.4.0) - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS - - VoxImplantSDK (2.46.12): - - VoxImplantSDK/Core (= 2.46.12) - - VoxImplantSDK/Core (2.46.12): - - VoxImplantWebRTC (= 93.0.0) - - VoxImplantWebRTC (93.0.0) + - VoxImplantSDK (2.52.0): + - VoxImplantWebRTC (= 112.0.0) + - VoxImplantWebRTC (112.0.0) DEPENDENCIES: - firebase_core (from `.symlinks/plugins/firebase_core/ios`) @@ -124,22 +130,22 @@ SPEC CHECKSUMS: firebase_core: 58542d7399889ebdbb034baa72d081e54c5c814d firebase_messaging: 01a8db2962f81ea190d08db767aba2e7e805e647 FirebaseCore: fa80ad16a62d52f67274b5b88304c3a318bbf9a4 - FirebaseCoreInternal: b342e37cd4f5b4454ec34308f073420e7920858e - FirebaseInstallations: b28af1b9f997f1a799efe818c94695a3728c352f + FirebaseCoreInternal: 910a81992c33715fec9263ca7381d59ab3a750b7 + FirebaseInstallations: 91950fe859846fff0fbd296180909dd273103b09 FirebaseMessaging: fd93783258c53ae5cdb9b41bf0c51606a677f2d5 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_callkit_voximplant: 9e1128135757ea8a21ae7bbc06ff4a37e906ccc5 flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743 - flutter_voximplant: 3a9f36552a8fdd6a6708e4027629bf49a807b7ee - GoogleDataTransport: 54dee9d48d14580407f8f5fbf2f496e92437a2f2 - GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084 - nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 + flutter_voximplant: f8a0e7ce1af495fe6ecd53233640df972952f43d + GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a + GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15 + nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 - PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4 + PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 shared_preferences_foundation: e2dae3258e06f44cc55f49d42024fd8dd03c590c - VoxImplantSDK: 577259786bc3da6ed3cf3d4ee1a8e08245c19ce6 - VoxImplantWebRTC: 8ddd8a63d0c20afa604fec22a2552c32b0371974 + VoxImplantSDK: fbc3bfc64cedc98545758717c8395a64edc091bf + VoxImplantWebRTC: 2256a8b9157cc46e1a4c8e0ed5816c5c672d7d5d PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 -COCOAPODS: 1.15.0 +COCOAPODS: 1.15.2 diff --git a/video_call/ios/Runner.xcodeproj/project.pbxproj b/video_call/ios/Runner.xcodeproj/project.pbxproj index 628cf57..6e20cc7 100644 --- a/video_call/ios/Runner.xcodeproj/project.pbxproj +++ b/video_call/ios/Runner.xcodeproj/project.pbxproj @@ -203,7 +203,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin\n"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -218,7 +218,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/video_call/lib/screens/login/bloc/login_bloc.dart b/video_call/lib/screens/login/bloc/login_bloc.dart index 006603d..4496528 100644 --- a/video_call/lib/screens/login/bloc/login_bloc.dart +++ b/video_call/lib/screens/login/bloc/login_bloc.dart @@ -1,5 +1,4 @@ /// Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved. -import 'dart:io'; import 'package:video_call/screens/login/login.dart'; import 'package:video_call/services/auth_service.dart'; @@ -42,8 +41,10 @@ class LoginBloc extends Bloc { Future _loginWithPassword( LoginWithPassword event, Emitter emit) async { emit(LoginInProgress()); + VINode node = VINode.values.byName(event.node); try { await _authService.loginWithPassword( + node, '${event.username}.voximplant.com', event.password, ); diff --git a/video_call/lib/screens/login/bloc/login_event.dart b/video_call/lib/screens/login/bloc/login_event.dart index b99a2e5..09f3d15 100644 --- a/video_call/lib/screens/login/bloc/login_event.dart +++ b/video_call/lib/screens/login/bloc/login_event.dart @@ -14,11 +14,13 @@ class LoadLastUser extends LoginEvent {} class LoginWithPassword extends LoginEvent { final String username; final String password; + final String node; - const LoginWithPassword({required this.username, required this.password}); + const LoginWithPassword( + {required this.username, required this.password, required this.node}); @override - List get props => [username, password]; + List get props => [username, password, node]; @override String toString() => 'LoginWithPassword: ' diff --git a/video_call/lib/screens/login/login_page.dart b/video_call/lib/screens/login/login_page.dart index fe57c8c..4b7b6b9 100644 --- a/video_call/lib/screens/login/login_page.dart +++ b/video_call/lib/screens/login/login_page.dart @@ -6,6 +6,19 @@ import 'package:video_call/theme/voximplant_theme.dart'; import 'package:video_call/utils/navigation_helper.dart'; import 'package:video_call/widgets/widgets.dart'; +const List nodes = [ + 'Node1', + 'Node2', + 'Node3', + 'Node4', + 'Node5', + 'Node6', + 'Node7', + 'Node8', + 'Node9', + 'Node10' +]; + class LoginPage extends StatefulWidget { static const routeName = '/login'; @@ -22,6 +35,8 @@ class _LoginPageState extends State { bool _isUsernameValid = true; bool _isPasswordValid = true; + bool _isNodeSelected = false; + String? _node; @override void initState() { @@ -38,9 +53,18 @@ class _LoginPageState extends State { @override Widget build(BuildContext context) { - void _login() => _bloc.add(LoginWithPassword( - username: _usernameController.text, - password: _passwordController.text)); + void _login() { + final node = _node; + if (node != null) { + _bloc.add( + LoginWithPassword( + username: _usernameController.text, + password: _passwordController.text, + node: node, + ), + ); + } + } void _handleLoginFailed(String errorCode, String errorDescription) { if (errorCode == 'ERROR_INVALID_USERNAME') { @@ -89,6 +113,25 @@ class _LoginPageState extends State { validator: (_) => _isPasswordValid ? null : 'Invalid password', ), + _isNodeSelected + ? Container() + : const Padding( + padding: EdgeInsets.only(top: 5, left: 20), + child: Align( + alignment: Alignment.centerLeft, + child: Text( + "Connection Node is required", + style: TextStyle(color: VoximplantColors.red), + ))), + Widgets.dropdown( + items: nodes, + onChange: (String? node) { + setState(() { + _isNodeSelected = true; + _node = node; + }); + }, + value: _node), Widgets.maxWidthRaisedButton( text: 'Log in', onPressed: _login, diff --git a/video_call/lib/screens/main/bloc/main_bloc.dart b/video_call/lib/screens/main/bloc/main_bloc.dart index 95b872d..0aa2860 100644 --- a/video_call/lib/screens/main/bloc/main_bloc.dart +++ b/video_call/lib/screens/main/bloc/main_bloc.dart @@ -18,6 +18,7 @@ class MainBloc extends Bloc { final CallKitService? _callKitService = Platform.isIOS ? CallKitService() : null; + bool _logoutRequested = false; late StreamSubscription _callStateSubscription; MainBloc() @@ -52,13 +53,16 @@ class MainBloc extends Bloc { } Future _logout(LogOut event, Emitter emit) async { + _logoutRequested = true; await _authService.logout(); emit(const LoggedOut(networkIssues: false)); } Future _connectionClosed( ConnectionClosed event, Emitter emit) async { - emit(const LoggedOut(networkIssues: true)); + if (!_logoutRequested) { + emit(const LoggedOut(networkIssues: true)); + } } void _receivedIncomingCall( diff --git a/video_call/lib/services/auth_service.dart b/video_call/lib/services/auth_service.dart index f37c7d8..a51540f 100644 --- a/video_call/lib/services/auth_service.dart +++ b/video_call/lib/services/auth_service.dart @@ -42,7 +42,8 @@ class AuthService { }); } - Future loginWithPassword(String username, String password) async { + Future loginWithPassword( + VINode node, String username, String password) async { _log('loginWithPassword'); VIClientState clientState = await _client.getClientState(); if (clientState == VIClientState.LoggedIn) { @@ -52,7 +53,7 @@ class AuthService { } } if (clientState == VIClientState.Disconnected) { - await _client.connect(); + await _client.connect(node: node); } VIAuthResult authResult = await _client.login(username, password); if (_voipToken != null) { @@ -61,28 +62,34 @@ class AuthService { await _client.registerForPushNotifications(voipToken); } } - await _saveAuthDetails(username, authResult.loginTokens); + await _saveAuthDetails(username, authResult.loginTokens, node); _displayName = authResult.displayName; return _displayName ?? "Unknown user"; } Future loginWithAccessToken() async { VIClientState clientState = await _client.getClientState(); + SharedPreferences prefs = await SharedPreferences.getInstance(); if (clientState == VIClientState.LoggedIn) { return _displayName; } else if (clientState == VIClientState.Connecting || clientState == VIClientState.LoggingIn) { return null; } else if (clientState == VIClientState.Disconnected) { - await _client.connect(); + final node = _getNode(prefs); + if (node != null) { + await _client.connect(node: node); + } else { + throw Exception("Node is unknown"); + } } _log('loginWithAccessToken'); - SharedPreferences prefs = await SharedPreferences.getInstance(); final loginTokens = _getAuthDetails(prefs); String? user = prefs.getString('username'); if (user != null && loginTokens != null) { - VIAuthResult authResult = await _client.loginWithAccessToken(user, loginTokens.accessToken); - await _saveAuthDetails(user, authResult.loginTokens); + VIAuthResult authResult = + await _client.loginWithAccessToken(user, loginTokens.accessToken); + await _saveAuthDetails(user, authResult.loginTokens, null); _displayName = authResult.displayName; } final voipToken = _voipToken; @@ -96,6 +103,7 @@ class AuthService { _log('logout'); await _client.disconnect(); final SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.remove("node"); prefs.remove('username'); prefs.remove('accessToken'); prefs.remove('refreshToken'); @@ -114,11 +122,14 @@ class AuthService { } Future _saveAuthDetails( - String username, VILoginTokens? loginTokens) async { + String username, VILoginTokens? loginTokens, VINode? node) async { if (loginTokens == null) { return; } final SharedPreferences prefs = await SharedPreferences.getInstance(); + if (node != null) { + prefs.setString('node', node.name); + } prefs.setString('username', username); prefs.setString('accessToken', loginTokens.accessToken); prefs.setString('refreshToken', loginTokens.refreshToken); @@ -126,18 +137,28 @@ class AuthService { prefs.setInt('refreshExpire', loginTokens.refreshExpire); } + VINode? _getNode(SharedPreferences prefs) { + final node = prefs.getString('node'); + if (node != null) { + return VINode.values.byName(node); + } + return null; + } + VILoginTokens? _getAuthDetails(SharedPreferences prefs) { final accessToken = prefs.getString('accessToken'); final refreshToken = prefs.getString('refreshToken'); final refreshExpire = prefs.getInt('refreshExpire'); final accessExpire = prefs.getInt('accessExpire'); - if (accessToken != null && refreshToken != null && refreshExpire != null && accessExpire != null) { + if (accessToken != null && + refreshToken != null && + refreshExpire != null && + accessExpire != null) { VILoginTokens loginTokens = VILoginTokens( accessToken: accessToken, refreshToken: refreshToken, accessExpire: accessExpire, - refreshExpire: refreshExpire - ); + refreshExpire: refreshExpire); return loginTokens; } return null; @@ -152,4 +173,3 @@ class AuthService { log('AuthService($hashCode): ${message.toString()}'); } } - diff --git a/video_call/lib/widgets/widgets.dart b/video_call/lib/widgets/widgets.dart index af910a8..dbfe1f8 100644 --- a/video_call/lib/widgets/widgets.dart +++ b/video_call/lib/widgets/widgets.dart @@ -21,11 +21,11 @@ class Widgets { child: Theme( data: ThemeData( primaryColor: - darkBackground ? VoximplantColors.white : VoximplantColors.button, + darkBackground ? VoximplantColors.white : VoximplantColors.button, // cursorColor: // darkBackground ? VoximplantColors.white : VoximplantColors.button, hintColor: - darkBackground ? VoximplantColors.white : VoximplantColors.button, + darkBackground ? VoximplantColors.white : VoximplantColors.button, ), child: TextFormField( decoration: InputDecoration( @@ -72,7 +72,8 @@ class Widgets { width: double.infinity, height: 50, child: ElevatedButton( - style: ElevatedButton.styleFrom(textStyle: const TextStyle(color: VoximplantColors.white)), + style: ElevatedButton.styleFrom( + textStyle: const TextStyle(color: VoximplantColors.white)), onPressed: onPressed, child: Text(text), ), @@ -124,4 +125,50 @@ class Widgets { ), ); } + + static Widget dropdown( + {required List items, + required ValueChanged onChange, + String? value}) { + return Padding( + padding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 20, + ), + child: Container( + decoration: const ShapeDecoration( + shape: RoundedRectangleBorder( + side: BorderSide( + width: 1.0, + style: BorderStyle.solid, + color: VoximplantColors.white), + borderRadius: BorderRadius.all(Radius.circular(5.0)), + ), + // color: VoximplantColors.white, + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10, + ), + child: DropdownButton( + value: value, + style: const TextStyle(color: VoximplantColors.white), + hint: const Text( + 'Connection node', + style: TextStyle(color: VoximplantColors.white), + ), + isExpanded: true, + dropdownColor: VoximplantColors.primary, + borderRadius: const BorderRadius.all(Radius.circular(4)), + alignment: AlignmentDirectional.center, + onChanged: (String? node) { + onChange(node); + }, + items: items.map>((String item) { + return DropdownMenuItem(value: item, child: Text(item)); + }).toList(), + ), + )), + ); + } } diff --git a/video_call/pubspec.lock b/video_call/pubspec.lock index abf44e6..e76e486 100644 --- a/video_call/pubspec.lock +++ b/video_call/pubspec.lock @@ -223,10 +223,10 @@ packages: dependency: "direct main" description: name: flutter_voximplant - sha256: "6d57d456b176189c79dd2e6adcf294bdb3cd2bdeee101ba94cc8ac2e9cabe86f" + sha256: f83ba01d70ce779427ae50d99744f5376d55ffadcb1f4cca2fcba342b280d169 url: "https://pub.dev" source: hosted - version: "3.8.1" + version: "3.12.0" flutter_web_plugins: dependency: transitive description: flutter diff --git a/video_call/pubspec.yaml b/video_call/pubspec.yaml index f0731d2..2519b38 100644 --- a/video_call/pubspec.yaml +++ b/video_call/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: sdk: flutter flutter_lints: ^2.0.0 flutter_bloc: 8.1.2 - flutter_voximplant: 3.8.1 + flutter_voximplant: 3.12.0 flutter_callkit_voximplant: 2.1.0 uuid: 3.0.7 flutter_local_notifications: 13.0.0