Skip to content

Commit d36b4a6

Browse files
Merge pull request #15 from ConnectyCube/feature/extend_functionality
- release 0.1.0-dev1;
2 parents 96e508a + ba85326 commit d36b4a6

File tree

11 files changed

+542
-148
lines changed

11 files changed

+542
-148
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 0.1.0-dev.1
2+
3+
* New:
4+
- Implemented Dart [null-safety](https://dart.dev/null-safety) feature;
5+
- Added method `getCallData(String? sessionId)` for getting all provided data about the call;
6+
- Added method `clearCallData(String? sessionId)` which cleans all data related to the call;
7+
- Added method `getLastCallId()` which returns the id of the last displayed call. It is useful on starting app step for navigation to the call screen if the call was accepted;
8+
- Added static callback `onCallAcceptedWhenTerminated` which can be useful if need listen to events from the Call notification in the background or terminated state;
9+
10+
* Improvements:
11+
- Added new field `userInfo`, which can be used for exchanging with additional data between the Call notification and your app, you will get this data in callbacks `onCallAcceptedWhenTerminated`, `onCallAccepted`, `onCallRejectedWhenTerminated`, `onCallRejected` after setting it in method `showCallNotification`;
12+
13+
* Fixes:
14+
- Fixed the wrong calback naming `onCallAcceptedWhenTerminated` -> `onCallRejectedWhenTerminated`;
15+
116
## 0.0.1-dev.1
217

318
* Initial release.

android/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
android:excludeFromRecents="true"
99
android:noHistory="true"
1010
android:screenOrientation="sensorPortrait"
11+
android:showOnLockScreen="true"
12+
android:showWhenLocked="true"
1113
android:taskAffinity="com.connectycube.flutter.connectycube_flutter_call_kit.INCOMING_CALL_AFFINITY"
12-
android:theme="@android:style/Theme.Holo.NoActionBar" />
14+
android:theme="@android:style/Theme.Holo.NoActionBar"
15+
android:turnScreenOn="true" />
1316
</application>
1417
</manifest>

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/ConnectycubeFlutterCallKitPlugin.kt

Lines changed: 119 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import android.view.WindowManager
1212
import androidx.annotation.Keep
1313
import androidx.annotation.NonNull
1414
import androidx.localbroadcastmanager.content.LocalBroadcastManager
15-
import com.connectycube.flutter.connectycube_flutter_call_kit.utils.getString
16-
import com.connectycube.flutter.connectycube_flutter_call_kit.utils.putString
15+
import com.connectycube.flutter.connectycube_flutter_call_kit.utils.*
1716
import io.flutter.embedding.engine.plugins.FlutterPlugin
1817
import io.flutter.embedding.engine.plugins.activity.ActivityAware
1918
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
@@ -27,14 +26,18 @@ import io.flutter.plugin.common.PluginRegistry
2726

2827
/** ConnectycubeFlutterCallKitPlugin */
2928
@Keep
30-
class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, PluginRegistry.NewIntentListener, ActivityAware, BroadcastReceiver() {
29+
class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler,
30+
PluginRegistry.NewIntentListener, ActivityAware, BroadcastReceiver() {
3131
private var applicationContext: Context? = null
3232
private var mainActivity: Activity? = null
3333
private lateinit var channel: MethodChannel
3434
private lateinit var localBroadcastManager: LocalBroadcastManager
3535

3636
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
37-
onAttachedToEngine(flutterPluginBinding.applicationContext, flutterPluginBinding.binaryMessenger)
37+
onAttachedToEngine(
38+
flutterPluginBinding.applicationContext,
39+
flutterPluginBinding.binaryMessenger
40+
)
3841
registerCallStateReceiver()
3942
}
4043

@@ -48,7 +51,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
4851
when (call.method) {
4952
"showCallNotification" -> {
5053
try {
51-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
54+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
55+
call.arguments as Map<String, Any>
5256
val callId = arguments["session_id"] as String
5357

5458
if (CALL_STATE_UNKNOWN != getCallState(callId)) {
@@ -60,11 +64,23 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
6064
val callInitiatorId = arguments["caller_id"] as Int
6165
val callInitiatorName = arguments["caller_name"] as String
6266
val callOpponents = ArrayList((arguments["call_opponents"] as String)
63-
.split(',')
64-
.map { it.toInt() })
65-
showCallNotification(applicationContext!!, callId, callType, callInitiatorId, callInitiatorName, callOpponents)
67+
.split(',')
68+
.map { it.toInt() })
69+
val userInfo = arguments["user_info"] as String
70+
71+
showCallNotification(
72+
applicationContext!!,
73+
callId,
74+
callType,
75+
callInitiatorId,
76+
callInitiatorName,
77+
callOpponents,
78+
userInfo
79+
)
6680

6781
saveCallState(callId, CALL_STATE_PENDING)
82+
saveCallData(callId, arguments)
83+
saveCallId(callId)
6884

6985
result.success(null)
7086
} catch (e: Exception) {
@@ -74,7 +90,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
7490

7591
"reportCallAccepted" -> {
7692
try {
77-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
93+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
94+
call.arguments as Map<String, Any>
7895
val callId = arguments["session_id"] as String
7996
cancelCallNotification(applicationContext!!, callId)
8097

@@ -88,7 +105,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
88105

89106
"reportCallEnded" -> {
90107
try {
91-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
108+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
109+
call.arguments as Map<String, Any>
92110
val callId = arguments["session_id"] as String
93111

94112
processCallEnded(callId)
@@ -102,7 +120,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
102120

103121
"getCallState" -> {
104122
try {
105-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
123+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
124+
call.arguments as Map<String, Any>
106125
val callId = arguments["session_id"] as String
107126

108127
result.success(getCallState(callId))
@@ -113,7 +132,8 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
113132

114133
"setCallState" -> {
115134
try {
116-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
135+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
136+
call.arguments as Map<String, Any>
117137
val callId = arguments["session_id"] as String
118138
val callState = arguments["call_state"] as String
119139

@@ -125,9 +145,22 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
125145
}
126146
}
127147

148+
"getCallData" -> {
149+
try {
150+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
151+
call.arguments as Map<String, Any>
152+
val callId = arguments["session_id"] as String
153+
154+
result.success(getCallData(callId))
155+
} catch (e: Exception) {
156+
result.error("ERROR", e.message, "")
157+
}
158+
}
159+
128160
"setOnLockScreenVisibility" -> {
129161
try {
130-
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> = call.arguments as Map<String, Any>
162+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
163+
call.arguments as Map<String, Any>
131164
val isVisible = arguments["is_visible"] as Boolean
132165

133166
setOnLockScreenVisibility(isVisible)
@@ -137,6 +170,27 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
137170
}
138171
}
139172

173+
"clearCallData" -> {
174+
try {
175+
@Suppress("UNCHECKED_CAST") val arguments: Map<String, Any> =
176+
call.arguments as Map<String, Any>
177+
val callId = arguments["session_id"] as String
178+
179+
clearCallData(callId)
180+
result.success(null)
181+
} catch (e: Exception) {
182+
result.error("ERROR", e.message, "")
183+
}
184+
}
185+
186+
"getLastCallId" -> {
187+
try {
188+
result.success(getLastCallId())
189+
} catch (e: Exception) {
190+
result.error("ERROR", e.message, "")
191+
}
192+
}
193+
140194
else ->
141195
result.notImplemented()
142196

@@ -196,7 +250,9 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
196250
parameters["call_type"] = intent.getIntExtra(EXTRA_CALL_TYPE, -1)
197251
parameters["caller_id"] = intent.getIntExtra(EXTRA_CALL_INITIATOR_ID, -1)
198252
parameters["caller_name"] = intent.getStringExtra(EXTRA_CALL_INITIATOR_NAME)
199-
parameters["call_opponents"] = intent.getIntegerArrayListExtra(EXTRA_CALL_OPPONENTS)?.joinToString(separator = ",")
253+
parameters["call_opponents"] =
254+
intent.getIntegerArrayListExtra(EXTRA_CALL_OPPONENTS)?.joinToString(separator = ",")
255+
parameters["user_info"] = intent.getStringExtra(EXTRA_CALL_USER_INFO)
200256

201257
when (action) {
202258
ACTION_CALL_REJECT -> {
@@ -242,19 +298,66 @@ class ConnectycubeFlutterCallKitPlugin : FlutterPlugin, MethodCallHandler, Plugi
242298
private fun saveCallState(callId: String, callState: String) {
243299
if (applicationContext == null) return
244300

245-
putString(applicationContext!!, callId, callState)
301+
putString(applicationContext!!, callId + "_state", callState)
246302
}
247303

248304
private fun getCallState(callId: String): String {
249305
if (applicationContext == null) return CALL_STATE_UNKNOWN
250306

251-
val callState: String? = getString(applicationContext!!, callId)
307+
val callState: String? = getString(applicationContext!!, callId + "_state")
252308

253309
if (TextUtils.isEmpty(callState)) return CALL_STATE_UNKNOWN
254310

255311
return callState!!
256312
}
257313

314+
private fun getCallData(callId: String): Map<String, *>? {
315+
if (applicationContext == null) return null
316+
317+
val callDataString: String? = getString(applicationContext!!, callId + "_data")
318+
319+
if (TextUtils.isEmpty(callDataString)) return null
320+
321+
return getMapFromJsonString(callDataString!!)
322+
}
323+
324+
private fun saveCallData(callId: String, callData: Map<String, *>) {
325+
if (applicationContext == null) return
326+
327+
try {
328+
putString(applicationContext!!, callId + "_data", mapToJsonString(callData))
329+
} catch (e: Exception) {
330+
// ignore
331+
}
332+
}
333+
334+
private fun clearCallData(callId: String) {
335+
if (applicationContext == null) return
336+
337+
try {
338+
remove(applicationContext!!, callId + "_state")
339+
remove(applicationContext!!, callId + "_data")
340+
} catch (e: Exception) {
341+
// ignore
342+
}
343+
}
344+
345+
private fun saveCallId(callId: String) {
346+
if (applicationContext == null) return
347+
348+
try {
349+
putString(applicationContext!!, "last_call_id", callId)
350+
} catch (e: Exception) {
351+
// ignore
352+
}
353+
}
354+
355+
private fun getLastCallId(): String? {
356+
if (applicationContext == null) return null
357+
358+
return getString(applicationContext!!, "last_call_id")
359+
}
360+
258361
private fun processCallEnded(sessionId: String) {
259362
if (applicationContext == null) return
260363

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const val EXTRA_CALL_TYPE = "extra_call_type"
55
const val EXTRA_CALL_INITIATOR_ID = "extra_call_initiator_id"
66
const val EXTRA_CALL_INITIATOR_NAME = "extra_call_initiator_name"
77
const val EXTRA_CALL_OPPONENTS = "extra_call_opponents"
8+
const val EXTRA_CALL_USER_INFO = "extra_call_user_info"
89

910
const val ACTION_CALL_ACCEPT = "action_call_accept"
1011
const val ACTION_CALL_REJECT = "action_call_reject"

android/src/main/kotlin/com/connectycube/flutter/connectycube_flutter_call_kit/EventReceiver.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class EventReceiver : BroadcastReceiver() {
2424
val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID)
2525
val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME)
2626
val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS)
27+
val userInfo = extras?.getString(EXTRA_CALL_USER_INFO)
2728
Log.i(TAG, "NotificationReceiver onReceive Call REJECT, callId: $callId")
2829

2930
val broadcastIntent = Intent(ACTION_CALL_REJECT)
@@ -33,10 +34,11 @@ class EventReceiver : BroadcastReceiver() {
3334
bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!)
3435
bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName)
3536
bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents)
37+
bundle.putString(EXTRA_CALL_USER_INFO, userInfo)
3638
broadcastIntent.putExtras(bundle)
3739

3840
LocalBroadcastManager.getInstance(context.applicationContext)
39-
.sendBroadcast(broadcastIntent)
41+
.sendBroadcast(broadcastIntent)
4042

4143
NotificationManagerCompat.from(context).cancel(callId.hashCode())
4244
}
@@ -48,6 +50,7 @@ class EventReceiver : BroadcastReceiver() {
4850
val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID)
4951
val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME)
5052
val callOpponents = extras?.getIntegerArrayList(EXTRA_CALL_OPPONENTS)
53+
val userInfo = extras?.getString(EXTRA_CALL_USER_INFO)
5154
Log.i(TAG, "NotificationReceiver onReceive Call ACCEPT, callId: $callId")
5255

5356
val broadcastIntent = Intent(ACTION_CALL_ACCEPT)
@@ -57,10 +60,11 @@ class EventReceiver : BroadcastReceiver() {
5760
bundle.putInt(EXTRA_CALL_INITIATOR_ID, callInitiatorId!!)
5861
bundle.putString(EXTRA_CALL_INITIATOR_NAME, callInitiatorName)
5962
bundle.putIntegerArrayList(EXTRA_CALL_OPPONENTS, callOpponents)
63+
bundle.putString(EXTRA_CALL_USER_INFO, userInfo)
6064
broadcastIntent.putExtras(bundle)
6165

6266
LocalBroadcastManager.getInstance(context.applicationContext)
63-
.sendBroadcast(broadcastIntent)
67+
.sendBroadcast(broadcastIntent)
6468

6569
NotificationManagerCompat.from(context).cancel(callId.hashCode())
6670
}
@@ -71,9 +75,18 @@ class EventReceiver : BroadcastReceiver() {
7175
val callType = extras?.getInt(EXTRA_CALL_TYPE)
7276
val callInitiatorId = extras?.getInt(EXTRA_CALL_INITIATOR_ID)
7377
val callInitiatorName = extras?.getString(EXTRA_CALL_INITIATOR_NAME)
74-
Log.i(TAG, "NotificationReceiver onReceive Delete Call Notification, callId: $callId")
78+
val userInfo = extras?.getString(EXTRA_CALL_USER_INFO)
79+
Log.i(
80+
TAG,
81+
"NotificationReceiver onReceive Delete Call Notification, callId: $callId"
82+
)
7583
LocalBroadcastManager.getInstance(context.applicationContext)
76-
.sendBroadcast(Intent(ACTION_CALL_NOTIFICATION_CANCELED).putExtra(EXTRA_CALL_ID, callId))
84+
.sendBroadcast(
85+
Intent(ACTION_CALL_NOTIFICATION_CANCELED).putExtra(
86+
EXTRA_CALL_ID,
87+
callId
88+
)
89+
)
7790
}
7891
}
7992
}

0 commit comments

Comments
 (0)