Skip to content

Commit

Permalink
chore: fix web version of SDK (import paths) and implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-Zimmerman committed Feb 9, 2025
1 parent 1e7e608 commit b8c706a
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 250 deletions.
7 changes: 4 additions & 3 deletions .idea/libraries/Flutter_Plugins.xml

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

2 changes: 1 addition & 1 deletion .idea/modules.xml

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

82 changes: 0 additions & 82 deletions .idea/telnyx-webrtc-flutter.iml

This file was deleted.

30 changes: 30 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
base_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
- platform: web
create_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668
base_revision: dec2ee5c1f98f8e84a7d5380c05eb8a3d0a81668

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
17 changes: 17 additions & 0 deletions flutter_voice_sdk.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
12 changes: 8 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import 'package:telnyx_webrtc/model/socket_method.dart';
import 'package:telnyx_flutter_webrtc/utils/theme.dart';
import 'package:telnyx_webrtc/config/telnyx_config.dart';

import 'firebase_options.dart';

final logger = Logger();
final txClientViewModel = TelnyxClientViewModel();
const MOCK_USER = '<MOCK_USER>';
Expand Down Expand Up @@ -136,13 +138,13 @@ class AppInitializer {
}

/// Firebase
await Firebase.initializeApp();
if (Platform.isAndroid) {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
if (!kIsWeb && Platform.isAndroid) {
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler,
);
} else {
logger.i('iOS - Skipping Firebase Messaging onBackgroundMessage');
logger.i('Web or iOS - Skipping Firebase Messaging onBackgroundMessage');
}

if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down Expand Up @@ -390,8 +392,10 @@ class _MyAppState extends State<MyApp> {
logger.d('getPushData : No data');
}
});
} else if (Platform.isIOS && !txClientViewModel.callFromPush) {
} else if (!kIsWeb && Platform.isIOS && !txClientViewModel.callFromPush) {
logger.i('iOS :: connect');
} else {
logger.i('Web :: connect');
}
} catch (e) {
logger.e('Error: $e');
Expand Down
8 changes: 7 additions & 1 deletion lib/model/profile_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
import 'package:telnyx_flutter_webrtc/firebase_options.dart';
import 'package:telnyx_webrtc/config/telnyx_config.dart';

class Profile {
Expand Down Expand Up @@ -51,10 +52,15 @@ class Profile {

Future<String?> getNotificationTokenForPlatform() async {
var token;

if (kIsWeb) {
return null;
}

if (defaultTargetPlatform == TargetPlatform.android) {
// If no apps are initialized, initialize one now.
if (Firebase.apps.isEmpty) {
await Firebase.initializeApp();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
token = (await FirebaseMessaging.instance.getToken())!;
} else if (Platform.isIOS) {
Expand Down
13 changes: 9 additions & 4 deletions lib/view/screen/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
import 'package:permission_handler/permission_handler.dart';
Expand All @@ -23,10 +24,14 @@ class _HomeScreenState extends State<HomeScreen> {
}

Future<void> askForNotificationPermission() async {
await FlutterCallkitIncoming.requestNotificationPermission('notification');
final status = await Permission.notification.status;
if (status.isDenied) {
await Permission.notification.request();
if (!kIsWeb) {
await FlutterCallkitIncoming.requestNotificationPermission(
'notification',
);
final status = await Permission.notification.status;
if (status.isDenied) {
await Permission.notification.request();
}
}
}

Expand Down
42 changes: 30 additions & 12 deletions lib/view/telnyx_client_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:telnyx_flutter_webrtc/file_logger.dart';
import 'package:telnyx_flutter_webrtc/main.dart';
import 'package:telnyx_flutter_webrtc/utils/background_detector.dart';
import 'package:telnyx_flutter_webrtc/utils/theme.dart';
import 'package:telnyx_webrtc/call.dart';
import 'package:telnyx_webrtc/config/telnyx_config.dart';
import 'package:telnyx_webrtc/model/socket_method.dart';
Expand Down Expand Up @@ -130,7 +130,7 @@ class TelnyxClientViewModel with ChangeNotifier {
logger.i('current call is Active');
_callState = CallStateStatus.ongoingCall;
notifyListeners();
if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
// only for iOS
FlutterCallkitIncoming.setCallConnected(_incomingInvite!.callID!);
}
Expand All @@ -140,7 +140,9 @@ class TelnyxClientViewModel with ChangeNotifier {
logger.i('Held');
break;
case CallState.done:
FlutterCallkitIncoming.endCall(currentCall?.callId ?? '');
if (!kIsWeb) {
FlutterCallkitIncoming.endCall(currentCall?.callId ?? '');
}
// TODO: Handle this case.
break;
case CallState.error:
Expand Down Expand Up @@ -233,7 +235,7 @@ class TelnyxClientViewModel with ChangeNotifier {
{
callState = CallStateStatus.idle;

if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
if (callFromPush) {
_endCallFromPush(true);
} else {
Expand All @@ -247,8 +249,11 @@ class TelnyxClientViewModel with ChangeNotifier {
}
}
notifyListeners();
final messageLogger = await FileLogger.getInstance();
await messageLogger.writeLog(message.toString());

if (!kIsWeb) {
final messageLogger = await FileLogger.getInstance();
await messageLogger.writeLog(message.toString());
}
}

// Observe Socket Error Messages
Expand Down Expand Up @@ -286,7 +291,7 @@ class TelnyxClientViewModel with ChangeNotifier {
}

void _endCallFromPush(bool fromBye) {
if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
// end Call for Callkit on iOS
FlutterCallkitIncoming.endCall(
currentCall?.callId ?? _incomingInvite!.callID!,
Expand Down Expand Up @@ -382,7 +387,7 @@ class TelnyxClientViewModel with ChangeNotifier {
debug: true,
);
} else {
return null;
return null;
}
}

Expand Down Expand Up @@ -418,13 +423,13 @@ class TelnyxClientViewModel with ChangeNotifier {
'State',
);

if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
// only for iOS
await FlutterCallkitIncoming.setCallConnected(_incomingInvite!.callID!);
}

// Hide if not already hidden
if (Platform.isAndroid && !acceptFromNotification) {
if (!kIsWeb && Platform.isAndroid && !acceptFromNotification) {
final CallKitParams callKitParams = CallKitParams(
id: _incomingInvite!.callID,
nameCaller: _incomingInvite!.callerIdName,
Expand Down Expand Up @@ -459,6 +464,9 @@ class TelnyxClientViewModel with ChangeNotifier {
}

Future<void> showNotification(IncomingInviteParams message) async {
if (kIsWeb) {
return;
}
// Temporarily ignore lifecycle events during notification to avoid actions being done while app is in background and notification in foreground.
BackgroundDetector.ignore = true;
final CallKitParams callKitParams = CallKitParams(
Expand Down Expand Up @@ -490,7 +498,7 @@ class TelnyxClientViewModel with ChangeNotifier {
logger.i('Current Call is not null');
}

if (Platform.isIOS) {
if (!kIsWeb && Platform.isIOS) {
/* when end call from CallScreen we need to tell Callkit to end the call as well
*/
if (endfromCallScreen && callFromPush) {
Expand All @@ -502,7 +510,7 @@ class TelnyxClientViewModel with ChangeNotifier {
// end Call normlly on iOS
currentCall?.endCall();
}
} else if (Platform.isAndroid || kIsWeb) {
} else if (kIsWeb || Platform.isAndroid) {
currentCall?.endCall();
}

Expand All @@ -527,6 +535,16 @@ class TelnyxClientViewModel with ChangeNotifier {
}

void toggleSpeakerPhone() {
if (kIsWeb) {
Fluttertoast.showToast(
msg: 'Toggling loud speaker is disabled on the web client',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: telnyx_green,
);
return;
}
_speakerPhone = !_speakerPhone;
currentCall?.enableSpeakerPhone(_speakerPhone);
notifyListeners();
Expand Down
2 changes: 1 addition & 1 deletion packages/telnyx_webrtc/lib/call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:telnyx_webrtc/model/verto/send/info_dtmf_message_body.dart';
import 'package:telnyx_webrtc/model/verto/send/invite_answer_message_body.dart';
import 'package:telnyx_webrtc/model/verto/send/modify_message_body.dart';
import 'package:telnyx_webrtc/peer/peer.dart'
if (dart.library.html) '/web/peer.dart';
if (dart.library.html) 'package:telnyx_webrtc/peer/web/peer.dart';
import 'package:telnyx_webrtc/tx_socket.dart'
if (dart.library.js) 'package:telnyx_webrtc/tx_socket_web.dart';
import 'package:uuid/uuid.dart';
Expand Down
Loading

0 comments on commit b8c706a

Please sign in to comment.