diff --git a/android/build.gradle b/android/build.gradle index 32e4174..2acec38 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply plugin: 'org.jetbrains.kotlin.android.extensions' android { - compileSdkVersion 28 + compileSdkVersion 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -48,4 +48,4 @@ dependencies { implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.google.code.gson:gson:2.8.6' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' -} +} \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 01a286e..fe73cae 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Wed Jul 19 13:11:43 EEST 2023 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallBroadcastReceiver.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallBroadcastReceiver.kt index c9abbe3..dc37d1a 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallBroadcastReceiver.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallBroadcastReceiver.kt @@ -3,10 +3,12 @@ package com.github.alezhka.flutter_incoming_call import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.util.Log class CallBroadcastReceiver: BroadcastReceiver() { companion object { + private const val TAG = "CallBroadcastReceiver" private const val ACTION_STARTED = "ACTION_STARTED" private const val ACTION_DISMISS = "ACTION_DISMISS" private const val ACTION_ACCEPT = "ACTION_ACCEPT" @@ -64,11 +66,13 @@ class CallBroadcastReceiver: BroadcastReceiver() { callNotification.clearNotification(callData.notificationId) Utils.backToForeground(context, FlutterIncomingCallPlugin.activity) + Log.d(TAG, "onReceive: EVENT_CALL_ACCEPT") sendCallEvent(EVENT_CALL_ACCEPT, callData) } ACTION_DISMISS -> { FlutterIncomingCallPlugin.ringtonePlayer?.stop() callNotification.clearNotification(callData.notificationId) + Log.d(TAG, "onReceive: EVENT_CALL_DECLINE") sendCallEvent(EVENT_CALL_DECLINE, callData) } ACTION_TIMEOUT -> { @@ -79,6 +83,7 @@ class CallBroadcastReceiver: BroadcastReceiver() { } private fun sendCallEvent(event: String, callData: CallData) { + Log.d(TAG, "sendCallEvent $event; callData: $callData") val actionData = mapOf( "uuid" to callData.uuid, "name" to callData.name, @@ -89,5 +94,4 @@ class CallBroadcastReceiver: BroadcastReceiver() { ) FlutterIncomingCallPlugin.eventHandler.send(event, actionData) } - } \ No newline at end of file diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallNotification.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallNotification.kt index 935be91..9125f71 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallNotification.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/CallNotification.kt @@ -5,12 +5,10 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.content.Context -import android.content.Intent import android.media.AudioAttributes import android.media.RingtoneManager import android.net.Uri import android.os.Build -import android.util.Log import androidx.core.app.NotificationCompat @@ -26,22 +24,28 @@ class CallNotification(private val context: Context) { } else { Notification.PRIORITY_MAX } + + private val pendingIntentFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) (PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) else PendingIntent.FLAG_UPDATE_CURRENT } fun showCallNotification(callData: CallData, config: PluginConfig) { - if(FlutterIncomingCallPlugin.ringtonePlayer == null) { - FlutterIncomingCallPlugin.ringtonePlayer = CallPlayer(context, config) - } + if (config.ringtone) { + if(FlutterIncomingCallPlugin.ringtonePlayer == null) { + FlutterIncomingCallPlugin.ringtonePlayer = CallPlayer(context, config) + } - FlutterIncomingCallPlugin.ringtonePlayer?.let { - if(!it.isPlaying()) it.play(callData) + FlutterIncomingCallPlugin.ringtonePlayer?.let { + if(!it.isPlaying()) it.play(callData) + } } val notificationID = callData.notificationId val declineIntent = CallBroadcastReceiver.declineIntent(context, callData) val acceptIntent = CallBroadcastReceiver.acceptIntent(context, callData) - val declinePi = PendingIntent.getBroadcast(context, 0, declineIntent, PendingIntent.FLAG_UPDATE_CURRENT) - val acceptPi = PendingIntent.getBroadcast(context, 0, acceptIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val declinePi = PendingIntent.getBroadcast(context, 0, declineIntent, pendingIntentFlag) + val acceptPi = PendingIntent.getBroadcast(context, 0, acceptIntent, pendingIntentFlag) + + val soundUri: Uri = Uri.parse("android.resource://${context.packageName}/${R.raw.nosound}") val notification: Notification = NotificationCompat.Builder(context, config.channelId) .setAutoCancel(true) @@ -113,7 +117,7 @@ class CallNotification(private val context: Context) { private fun getCallerActivityPendingIntent(notificationID: Int, callData: CallData): PendingIntent? { val intent = IncomingCallActivity.start(callData) - return PendingIntent.getActivity(context, notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getActivity(context, notificationID, intent, pendingIntentFlag) } private fun createNotificationChannel(manager: NotificationManager, soundUri: Uri?) { diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/FlutterIncomingCallPlugin.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/FlutterIncomingCallPlugin.kt index 554427e..2bc69c8 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/FlutterIncomingCallPlugin.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/FlutterIncomingCallPlugin.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.os.Handler import android.os.Looper +import android.util.Log import androidx.annotation.NonNull; import io.flutter.embedding.engine.plugins.FlutterPlugin @@ -19,6 +20,7 @@ import io.flutter.plugin.common.MethodChannel.Result class FlutterIncomingCallPlugin: FlutterPlugin, MethodCallHandler, ActivityAware { companion object { + val TAG = "FlutterIncomingCallPlug" var activity: Activity? = null val eventHandler = EventStreamHandler() var ringtonePlayer: CallPlayer? = null @@ -60,19 +62,20 @@ class FlutterIncomingCallPlugin: FlutterPlugin, MethodCallHandler, ActivityAware } "displayIncomingCall" -> { if(!isConfigured) { + android.util.Log.e(TAG, "onMethodCall displayIncomingCall: Not Configured") result.error("not_configured", "Not configured", null) return } - + val callData = FactoryModels.parseCallData(call) + android.util.Log.d(TAG, "onMethodCall displayIncomingCall callData: $callData") context?.let { - if(Utils.isDeviceScreenLocked(it)) { - activity?.startActivity(IncomingCallActivity.start(callData)) - } else { - notificationCall?.showCallNotification(callData, config!!) - } + Log.d(TAG, "onMethodCall displayIncomingCall") + notificationCall?.showCallNotification(callData, config!!) it.sendBroadcast(CallBroadcastReceiver.startedIntent(it, callData)) + } ?: run { + android.util.Log.e(TAG, "onMethodCall displayIncomingCall: context is null") } result.success(null) @@ -105,7 +108,7 @@ class FlutterIncomingCallPlugin: FlutterPlugin, MethodCallHandler, ActivityAware override fun onAttachedToActivity(binding: ActivityPluginBinding) { activity = binding.activity context = binding.activity - notificationCall = CallNotification(context!!) + notificationCall = CallNotification(binding.activity) callPrefs = CallPreferences(binding.activity) } @@ -120,7 +123,7 @@ class FlutterIncomingCallPlugin: FlutterPlugin, MethodCallHandler, ActivityAware activity = binding.activity context = binding.activity callPrefs = CallPreferences(binding.activity) - notificationCall = CallNotification(context!!) + notificationCall = CallNotification(binding.activity) } override fun onDetachedFromActivity() { diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/IncomingCallActivity.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/IncomingCallActivity.kt index f76d6b1..563ff3f 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/IncomingCallActivity.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/IncomingCallActivity.kt @@ -49,6 +49,8 @@ class IncomingCallActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O_MR1) { + setTurnScreenOn(true) + setShowWhenLocked(true) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } else { @@ -60,9 +62,6 @@ class IncomingCallActivity : AppCompatActivity() { super.onCreate(savedInstanceState) if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O_MR1) { - setTurnScreenOn(true) - setShowWhenLocked(true) - val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager keyguardManager.requestDismissKeyguard(this, null) } diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/Utils.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/Utils.kt index 680d245..8db62c0 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/Utils.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/Utils.kt @@ -9,64 +9,13 @@ import android.content.Intent import android.os.Build import android.provider.Settings import android.telephony.TelephonyManager +import android.os.PowerManager -object Utils { - fun isDeviceScreenLocked(context: Context): Boolean { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - isDeviceLocked(context) - } else { - isPatternSet(context) || isPassOrPinSet(context) - } - } - /** - * @return true if pattern set, false if not (or if an issue when checking) - */ - private fun isPatternSet(context: Context): Boolean { - val cr: ContentResolver = context.contentResolver - return try { - val lockPatternEnable: Int = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED) - lockPatternEnable == 1 - } catch (e: Settings.SettingNotFoundException) { - false - } - } - /** - * @return true if pass or pin set - */ - private fun isPassOrPinSet(context: Context): Boolean { - val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager //api 16+ - return keyguardManager.isKeyguardSecure - } - - /** - * @return true if pass or pin or pattern locks screen - */ - @TargetApi(Build.VERSION_CODES.M) - private fun isDeviceLocked(context: Context): Boolean { - val telMgr = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager - val simState = telMgr.simState - val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager //api 23+ - return keyguardManager.isDeviceSecure && simState != TelephonyManager.SIM_STATE_ABSENT - } - - /** - * @return Main activity class. - */ - fun getMainActivityClass(context: Context): Class<*>? { - val packageName = context.packageName - val launchIntent = context.packageManager.getLaunchIntentForPackage(packageName) - val className = launchIntent?.component?.className - return try { - className?.let{ Class.forName(it) } - } catch (e: ClassNotFoundException) { - e.printStackTrace() - null - } - } +object Utils { /** * Back main activity to foreground. diff --git a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/models.kt b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/models.kt index 6b15f5a..3b8841d 100644 --- a/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/models.kt +++ b/android/src/main/kotlin/com/github/alezhka/flutter_incoming_call/models.kt @@ -10,6 +10,7 @@ data class PluginConfig( val channelName: String, val channelDescription: String, val vibration: Boolean, + val ringtone: Boolean, val ringtonePath: String?, val duration: Long ) @@ -46,10 +47,11 @@ object FactoryModels { val channelId = call.argument("channelId") as String? ?: "" val channelName = call.argument("channelName") as String? ?: "" val channelDescription = call.argument("channelDescription") as String? ?: "" - val duration = (call.argument("duration") as Int? ?: 30000).toLong() val vibration = call.argument("vibration") as Boolean? ?: false + val ringtone = call.argument("ringtone") as Boolean? ?: false val ringtonePath = call.argument("ringtonePath") as String? - return PluginConfig(appName, channelId, channelName, channelDescription, vibration, ringtonePath, duration) + val duration = (call.argument("duration") as Int? ?: 30000).toLong() + return PluginConfig(appName, channelId, channelName, channelDescription, vibration, ringtone, ringtonePath, duration) } fun defaultConfig(): PluginConfig { @@ -59,7 +61,8 @@ object FactoryModels { val channelDescription = "Call channel" val duration = 30000L val vibration = false + val ringtone = true val ringtonePath = "default" - return PluginConfig(appName, channelId, channelName, channelDescription, vibration, ringtonePath, duration) + return PluginConfig(appName, channelId, channelName, channelDescription, vibration, ringtone, ringtonePath, duration) } } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 26e2b4e..e17145a 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -55,6 +55,7 @@ android:name="com.github.alezhka.flutter_incoming_call.IncomingCallActivity" android:theme="@style/AppCompatTheme" android:screenOrientation="portrait" + android:launchMode="singleTop" android:showOnLockScreen="true"> diff --git a/example/pubspec.lock b/example/pubspec.lock index 6fd90c6..b51a1f3 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -94,7 +94,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -148,7 +148,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.2" typed_data: dependency: transitive description: diff --git a/ios/Classes/SwiftFlutterIncomingCallPlugin.swift b/ios/Classes/SwiftFlutterIncomingCallPlugin.swift index 18d5a64..df687a7 100644 --- a/ios/Classes/SwiftFlutterIncomingCallPlugin.swift +++ b/ios/Classes/SwiftFlutterIncomingCallPlugin.swift @@ -335,11 +335,9 @@ public class SwiftFlutterIncomingCallPlugin: NSObject, FlutterPlugin, CXProvider if let callData = callsData[uuidString] { sendEvent(SwiftFlutterIncomingCallPlugin.EVENT_CALL_DECLINE, callData.toMap()) + callsAttended[uuidString] = true } - - callsAttended.removeValue(forKey: uuidString) - callsData.removeValue(forKey: uuidString) - + action.fulfill() } @@ -390,5 +388,4 @@ public class SwiftFlutterIncomingCallPlugin: NSObject, FlutterPlugin, CXProvider let audiosessionData = ToggleAudiosessionData(false) sendEvent(SwiftFlutterIncomingCallPlugin.EVENT_TOGGLE_AUDIOSESSION, audiosessionData.toMap()) } - } diff --git a/lib/config.dart b/lib/config.dart index 52547b9..dd501b0 100644 --- a/lib/config.dart +++ b/lib/config.dart @@ -1,11 +1,9 @@ -import 'package:flutter/foundation.dart'; - class ConfigAndroid { - final String channelId; final String channelName; final String channelDescription; final String ringtonePath; + final bool ringtone; final bool vibration; ConfigAndroid({ @@ -14,19 +12,20 @@ class ConfigAndroid { required this.channelDescription, this.ringtonePath = "default", this.vibration = false, + this.ringtone = true, }); Map toMap() => { - 'channelId': channelId, - 'channelName': channelName, - 'channelDescription': channelDescription, - 'ringtonePath': ringtonePath, - 'vibration': vibration, - }; + 'channelId': channelId, + 'channelName': channelName, + 'channelDescription': channelDescription, + 'ringtonePath': ringtonePath, + 'vibration': vibration, + 'ringtone': ringtone, + }; } class ConfigIOS { - final bool supportsVideo; final bool includesCallsInRecents; final int maximumCallGroups; @@ -39,31 +38,30 @@ class ConfigIOS { final bool avSessionSetPreferredIOBufferDuration; final bool avSessionSetActive; - ConfigIOS({ - required this.supportsVideo, - required this.includesCallsInRecents, - required this.maximumCallGroups, - required this.maximumCallsPerCallGroup, - required this.iconName, - this.ringtonePath, - this.avSessionSetActive = true, - this.avSessionSetCategory = true, - this.avSessionSetMode = true, - this.avSessionSetPreferredIOBufferDuration = true, - this.avSessionSetPreferredSampleRate = true - }); + ConfigIOS( + {required this.supportsVideo, + required this.includesCallsInRecents, + required this.maximumCallGroups, + required this.maximumCallsPerCallGroup, + required this.iconName, + this.ringtonePath, + this.avSessionSetActive = true, + this.avSessionSetCategory = true, + this.avSessionSetMode = true, + this.avSessionSetPreferredIOBufferDuration = true, + this.avSessionSetPreferredSampleRate = true}); Map toMap() => { - 'supportsVideo': supportsVideo, - 'includesCallsInRecents': includesCallsInRecents, - 'maximumCallGroups': maximumCallGroups, - 'maximumCallsPerCallGroup': maximumCallsPerCallGroup, - 'ringtonePath': ringtonePath, - 'iconName': iconName, - 'avSessionSetActive': avSessionSetActive, - 'avSessionSetCategory': avSessionSetCategory, - 'avSessionSetMode': avSessionSetMode, - 'avSessionSetPreferredIOBufferDuration': avSessionSetPreferredIOBufferDuration, - 'avSessionSetPreferredSampleRate': avSessionSetPreferredSampleRate - }; -} \ No newline at end of file + 'supportsVideo': supportsVideo, + 'includesCallsInRecents': includesCallsInRecents, + 'maximumCallGroups': maximumCallGroups, + 'maximumCallsPerCallGroup': maximumCallsPerCallGroup, + 'ringtonePath': ringtonePath, + 'iconName': iconName, + 'avSessionSetActive': avSessionSetActive, + 'avSessionSetCategory': avSessionSetCategory, + 'avSessionSetMode': avSessionSetMode, + 'avSessionSetPreferredIOBufferDuration': avSessionSetPreferredIOBufferDuration, + 'avSessionSetPreferredSampleRate': avSessionSetPreferredSampleRate + }; +} diff --git a/lib/flutter_incoming_call.dart b/lib/flutter_incoming_call.dart index 7ac0ba3..20c5394 100644 --- a/lib/flutter_incoming_call.dart +++ b/lib/flutter_incoming_call.dart @@ -1,14 +1,14 @@ import 'dart:async'; import 'dart:io'; -import 'package:flutter/services.dart'; import 'package:flutter/foundation.dart' show describeEnum; +import 'package:flutter/services.dart'; -import 'models.dart'; import 'config.dart'; +import 'models.dart'; -export 'models.dart'; export 'config.dart'; +export 'models.dart'; enum HandleType { generic, @@ -17,12 +17,10 @@ enum HandleType { } class FlutterIncomingCall { - static const MethodChannel _channel = const MethodChannel('flutter_incoming_call'); static const EventChannel _eventChannel = const EventChannel('flutter_incoming_call_events'); - static Stream get onEvent => - _eventChannel.receiveBroadcastStream().map(_toCallEvent); + static Stream get onEvent => _eventChannel.receiveBroadcastStream().map(_toCallEvent); static Future configure({ required String appName, @@ -30,25 +28,23 @@ class FlutterIncomingCall { ConfigAndroid? android, ConfigIOS? ios, }) async { - await _channel.invokeMethod('configure', { + await _channel.invokeMethod('configure', { 'appName': appName, 'duration': duration, - if(Platform.isAndroid && android != null) ...android.toMap(), - if(Platform.isIOS && ios != null) ...ios.toMap(), + if (Platform.isAndroid && android != null) ...android.toMap(), + if (Platform.isIOS && ios != null) ...ios.toMap(), }); } static Future displayIncomingCallAdvanced(String uuid, String name, - { String? avatar = null, - String? handle = null, - HandleType? handleType = null, - bool hasVideo = false, - bool supportsDTMF = false, - bool supportsHolding = false, - bool supportsGrouping = false, - bool supportsUngrouping = false - }) - async { + {String? avatar = null, + String? handle = null, + HandleType? handleType = null, + bool hasVideo = false, + bool supportsDTMF = false, + bool supportsHolding = false, + bool supportsGrouping = false, + bool supportsUngrouping = false}) async { await _channel.invokeMethod('displayIncomingCall', { 'uuid': uuid, 'name': name, @@ -63,7 +59,8 @@ class FlutterIncomingCall { }); } - static Future displayIncomingCall(String uuid, String name, String avatar, String handle, HandleType handleType, bool hasVideo) async { + static Future displayIncomingCall( + String uuid, String name, String avatar, String handle, HandleType handleType, bool hasVideo) async { await _channel.invokeMethod('displayIncomingCall', { 'uuid': uuid, 'name': name, @@ -93,7 +90,7 @@ class FlutterIncomingCall { final event = data['event']; final body = Map.from(data['body']); - switch(event) { + switch (event) { case kEventCallAccept: return CallEvent.fromMap(CallAction.accept, body); case kEventCallDecline: @@ -114,6 +111,4 @@ class FlutterIncomingCall { } throw Exception('Undefined event!'); } - - -} \ No newline at end of file +} diff --git a/lib/models.dart b/lib/models.dart index 3ef2c68..1506e6a 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -1,6 +1,3 @@ - - - const kEventCallStarted = "call_started"; const kEventCallAccept = "call_accept"; const kEventCallDecline = "call_decline"; @@ -12,49 +9,37 @@ const kEventToggleAudioSession = "toggle_audiosession"; enum CallAction { started, accept, decline, missed } -abstract class BaseCallEvent { -} +abstract class BaseCallEvent {} class CallEvent extends BaseCallEvent { - final CallAction action; final String uuid; final String name; final String handleType; final String avatar; - CallEvent({ - required this.action, - required this.uuid, - required this.name, - required this.handleType, - required this.avatar - }); + CallEvent( + {required this.action, required this.uuid, required this.name, required this.handleType, required this.avatar}); factory CallEvent.fromMap(CallAction action, Map body) { return CallEvent( - action: action, - uuid: body['uuid'], - name: body['name'], - handleType: body['handleType'], - avatar: body['avatar'], + action: action, + uuid: body['uuid'], + name: body['name'], + handleType: body['handleType'] ?? '', + avatar: body['avatar'] ?? '', ); } @override - String toString() => - 'CallEvent { uuid: $uuid, name: $name, handleType: $handleType, avatar: $avatar }'; + String toString() => 'CallEvent { uuid: $uuid, name: $name, handleType: $handleType, avatar: $avatar }'; } class HoldEvent extends BaseCallEvent { - final String uuid; final bool hold; - HoldEvent({ - required this.uuid, - required this.hold - }); + HoldEvent({required this.uuid, required this.hold}); factory HoldEvent.fromMap(Map body) { return HoldEvent( @@ -64,20 +49,14 @@ class HoldEvent extends BaseCallEvent { } @override - String toString() => - 'HoldEvent { uuid: $uuid, hold: $hold }'; - + String toString() => 'HoldEvent { uuid: $uuid, hold: $hold }'; } class MuteEvent extends BaseCallEvent { - final String uuid; final bool mute; - MuteEvent({ - required this.uuid, - required this.mute - }); + MuteEvent({required this.uuid, required this.mute}); factory MuteEvent.fromMap(Map body) { return MuteEvent( @@ -87,21 +66,14 @@ class MuteEvent extends BaseCallEvent { } @override - String toString() => - 'MuteEvent { uuid: $uuid, mute: $mute }'; - + String toString() => 'MuteEvent { uuid: $uuid, mute: $mute }'; } - class DmtfEvent extends BaseCallEvent { - final String uuid; final String digits; - DmtfEvent({ - required this.uuid, - required this.digits - }); + DmtfEvent({required this.uuid, required this.digits}); factory DmtfEvent.fromMap(Map body) { return DmtfEvent( @@ -111,18 +83,13 @@ class DmtfEvent extends BaseCallEvent { } @override - String toString() => - 'DmtfEvent { uuid: $uuid, digits: $digits }'; - + String toString() => 'DmtfEvent { uuid: $uuid, digits: $digits }'; } class AudioSessionEvent extends BaseCallEvent { - final bool activate; - AudioSessionEvent({ - required this.activate - }); + AudioSessionEvent({required this.activate}); factory AudioSessionEvent.fromMap(Map body) { return AudioSessionEvent( @@ -131,7 +98,5 @@ class AudioSessionEvent extends BaseCallEvent { } @override - String toString() => - 'AudioSessionEvent { activate: $activate }'; - -} \ No newline at end of file + String toString() => 'AudioSessionEvent { activate: $activate }'; +} diff --git a/pubspec.lock b/pubspec.lock index a8b24d7..bb1449b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -73,7 +73,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -127,7 +127,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.2" typed_data: dependency: transitive description: