react-native-sinch-calling 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.3.0
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Automatic proximity-screen-off management during established earpiece calls, same behavior as the system Phone app: on while a call is `ESTABLISHED` and the speaker is off, off otherwise (speaker toggle or call end). Handled entirely inside `SinchCallManager` on both platforms — no new public API.
|
|
10
|
+
|
|
5
11
|
## 0.2.0
|
|
6
12
|
|
|
7
13
|
### Added
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
|
6
6
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
|
7
7
|
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
|
|
8
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
8
9
|
|
|
9
10
|
<application>
|
|
10
11
|
<service
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.sinchcalling
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
+
import android.os.PowerManager
|
|
4
5
|
import com.sinch.android.rtc.AudioController
|
|
5
6
|
import com.sinch.android.rtc.ClientRegistration
|
|
6
7
|
import com.sinch.android.rtc.PushConfiguration
|
|
@@ -66,6 +67,13 @@ class SinchCallManager(private val context: Context) {
|
|
|
66
67
|
private var customPushIdField: String? = null
|
|
67
68
|
private var customPushDisplayField: String? = null
|
|
68
69
|
|
|
70
|
+
// Proximity-screen-off during an established earpiece call, same as the
|
|
71
|
+
// system Phone app: on while at least one call is established and the
|
|
72
|
+
// speaker isn't in use, off otherwise.
|
|
73
|
+
private val establishedCallIds = mutableSetOf<String>()
|
|
74
|
+
private var isSpeakerEnabled = false
|
|
75
|
+
private var proximityWakeLock: PowerManager.WakeLock? = null
|
|
76
|
+
|
|
69
77
|
private val callListener = object : CallListener {
|
|
70
78
|
override fun onCallProgressing(call: Call) {
|
|
71
79
|
listener?.onCallProgressing(call.callId)
|
|
@@ -73,11 +81,15 @@ class SinchCallManager(private val context: Context) {
|
|
|
73
81
|
|
|
74
82
|
override fun onCallEstablished(call: Call) {
|
|
75
83
|
SinchTelecomManager.reportCallActive(call.callId)
|
|
84
|
+
establishedCallIds.add(call.callId)
|
|
85
|
+
updateProximityMonitoring()
|
|
76
86
|
listener?.onCallEstablished(call.callId)
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
override fun onCallEnded(call: Call) {
|
|
80
90
|
calls.remove(call.callId)
|
|
91
|
+
establishedCallIds.remove(call.callId)
|
|
92
|
+
updateProximityMonitoring()
|
|
81
93
|
SinchTelecomManager.reportCallEnded(call.callId)
|
|
82
94
|
listener?.onCallEnded(call.callId, endCauseString(call.details.endCause))
|
|
83
95
|
}
|
|
@@ -216,6 +228,9 @@ class SinchCallManager(private val context: Context) {
|
|
|
216
228
|
client?.terminateGracefully()
|
|
217
229
|
client = null
|
|
218
230
|
calls.clear()
|
|
231
|
+
establishedCallIds.clear()
|
|
232
|
+
isSpeakerEnabled = false
|
|
233
|
+
releaseProximityWakeLock()
|
|
219
234
|
}
|
|
220
235
|
|
|
221
236
|
fun provideRegistrationCredentials(jwt: String) {
|
|
@@ -293,6 +308,36 @@ class SinchCallManager(private val context: Context) {
|
|
|
293
308
|
fun setSpeakerEnabled(enabled: Boolean) {
|
|
294
309
|
val audioController = client?.audioController ?: return
|
|
295
310
|
if (enabled) audioController.enableSpeaker() else audioController.disableSpeaker()
|
|
311
|
+
isSpeakerEnabled = enabled
|
|
312
|
+
updateProximityMonitoring()
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private fun updateProximityMonitoring() {
|
|
316
|
+
val shouldEnable = establishedCallIds.isNotEmpty() && !isSpeakerEnabled
|
|
317
|
+
if (shouldEnable) acquireProximityWakeLock() else releaseProximityWakeLock()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private fun acquireProximityWakeLock() {
|
|
321
|
+
val lock = proximityWakeLock ?: run {
|
|
322
|
+
val powerManager =
|
|
323
|
+
context.applicationContext.getSystemService(Context.POWER_SERVICE) as? PowerManager
|
|
324
|
+
?: return
|
|
325
|
+
if (!powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
|
|
326
|
+
return
|
|
327
|
+
}
|
|
328
|
+
@Suppress("DEPRECATION")
|
|
329
|
+
powerManager.newWakeLock(
|
|
330
|
+
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
|
331
|
+
"SinchCalling:ProximityWakeLock",
|
|
332
|
+
).also { proximityWakeLock = it }
|
|
333
|
+
}
|
|
334
|
+
if (!lock.isHeld) {
|
|
335
|
+
lock.acquire(10 * 60 * 1000L)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private fun releaseProximityWakeLock() {
|
|
340
|
+
proximityWakeLock?.let { if (it.isHeld) it.release() }
|
|
296
341
|
}
|
|
297
342
|
|
|
298
343
|
private fun track(call: Call) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import AVFoundation
|
|
2
2
|
import Foundation
|
|
3
3
|
import SinchRTC
|
|
4
|
+
import UIKit
|
|
4
5
|
|
|
5
6
|
@objc public protocol SinchCallManagerDelegate: AnyObject {
|
|
6
7
|
func sinchCallManagerDidStartClient()
|
|
@@ -38,6 +39,14 @@ public final class SinchCallManager: NSObject {
|
|
|
38
39
|
private var pendingRegistration: SINClientRegistration?
|
|
39
40
|
private var calls: [String: SINCall] = [:]
|
|
40
41
|
|
|
42
|
+
// Proximity-screen-off during an established earpiece call, same as the
|
|
43
|
+
// system Phone app: on while at least one call is established and the
|
|
44
|
+
// speaker isn't in use, off otherwise. Tracked here (rather than exposed
|
|
45
|
+
// as a public API) since both established-call state and speaker state
|
|
46
|
+
// already live in this class.
|
|
47
|
+
private var establishedCallIds = Set<String>()
|
|
48
|
+
private var isSpeakerEnabled = false
|
|
49
|
+
|
|
41
50
|
@objc public func configure(appKey: String, environmentHost: String, userId: String) {
|
|
42
51
|
do {
|
|
43
52
|
let sinchClient = try Sinch.client(
|
|
@@ -62,6 +71,9 @@ public final class SinchCallManager: NSObject {
|
|
|
62
71
|
client?.terminateGracefully()
|
|
63
72
|
client = nil
|
|
64
73
|
calls.removeAll()
|
|
74
|
+
establishedCallIds.removeAll()
|
|
75
|
+
isSpeakerEnabled = false
|
|
76
|
+
updateProximityMonitoring()
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
@objc public func provideRegistrationCredentials(_ jwt: String) {
|
|
@@ -129,6 +141,15 @@ public final class SinchCallManager: NSObject {
|
|
|
129
141
|
} else {
|
|
130
142
|
client?.audioController().disableSpeaker()
|
|
131
143
|
}
|
|
144
|
+
isSpeakerEnabled = enabled
|
|
145
|
+
updateProximityMonitoring()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private func updateProximityMonitoring() {
|
|
149
|
+
let shouldEnable = !establishedCallIds.isEmpty && !isSpeakerEnabled
|
|
150
|
+
DispatchQueue.main.async {
|
|
151
|
+
UIDevice.current.isProximityMonitoringEnabled = shouldEnable
|
|
152
|
+
}
|
|
132
153
|
}
|
|
133
154
|
|
|
134
155
|
@objc public func enableManagedPushNotifications() {
|
|
@@ -185,11 +206,15 @@ extension SinchCallManager: SINCallDelegate {
|
|
|
185
206
|
}
|
|
186
207
|
|
|
187
208
|
public func callDidEstablish(_ call: SINCall) {
|
|
209
|
+
establishedCallIds.insert(call.callId)
|
|
210
|
+
updateProximityMonitoring()
|
|
188
211
|
delegate?.sinchCallManagerCallDidEstablish(call.callId)
|
|
189
212
|
}
|
|
190
213
|
|
|
191
214
|
public func callDidEnd(_ call: SINCall) {
|
|
192
215
|
calls.removeValue(forKey: call.callId)
|
|
216
|
+
establishedCallIds.remove(call.callId)
|
|
217
|
+
updateProximityMonitoring()
|
|
193
218
|
delegate?.sinchCallManagerCallDidEnd(call.callId, endCause: endCauseString(call.details.endCause))
|
|
194
219
|
}
|
|
195
220
|
}
|
package/package.json
CHANGED