Skip to content

Commit 1522dbd

Browse files
authored
fix: ios headset (#24)
* CU-3w8ybcw fixed bugs with iOS PPT headset * fix: CU-3w8ybcw minor android ptt changes
1 parent aa54f3c commit 1522dbd

File tree

6 files changed

+72
-28
lines changed

6 files changed

+72
-28
lines changed

android/build.gradle

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
ext {
2-
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6-
kotlinVersion = project.hasProperty('kotlinVersion') ? rootProject.ext.kotlinVersion : '1.8.20'
7-
coreKtx = project.hasProperty('coreKtx') ? rootProject.ext.coreKtx : '1.9.0'
8-
coroutinesVersion = project.hasProperty('coroutinesVersion') ? rootProject.ext.coroutinesVersion : '1.6.0'
9-
androidxLifecycleVersion = project.hasProperty('androidxLifecycleVersion') ? rootProject.ext.androidxLifecycleVersion : '2.5.1'
10-
groupieVersion = project.hasProperty('groupieVersion') ? rootProject.ext.groupieVersion : '2.9.0'
11-
}
12-
131
buildscript {
142
repositories {
153
google()

android/src/main/java/com/resgrid/plugins/resgrid/fragments/AudioCallView.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,19 @@ class AudioCallFragment: Fragment(R.layout.audio_call_activity)
184184
micButton.setOnClickListener { viewModel.setMicEnabled(!viewModel.micEnabled.value!!) }
185185
viewModel.micEnabled.observe(this) { enabled ->
186186
micButton.setImageResource(
187-
if (enabled) R.drawable.outline_mic_24
188-
else R.drawable.outline_mic_off_24
187+
if (enabled) {
188+
R.drawable.outline_mic_24
189+
}
190+
else {
191+
R.drawable.outline_mic_off_24
192+
}
189193
)
194+
195+
if (enabled) {
196+
micButton.setColorFilter(getResources().getColor(R.color.colorTransmitting));
197+
} else {
198+
micButton.setColorFilter(getResources().getColor(R.color.colorWhite));
199+
}
190200
}
191201

192202
val exitButton = view.findViewById(R.id.exit) as ImageView
@@ -196,6 +206,13 @@ class AudioCallFragment: Fragment(R.layout.audio_call_activity)
196206
bluetoothButton.setOnClickListener {
197207
showBluetoothDeviceDialogFrag(viewModel)
198208
}
209+
viewModel.headsetConnected.observe(this) { connected ->
210+
if (connected) {
211+
bluetoothButton.setColorFilter(getResources().getColor(R.color.colorPrimary));
212+
} else {
213+
bluetoothButton.setColorFilter(getResources().getColor(R.color.colorWhite));
214+
}
215+
}
199216
}
200217

201218
private fun startTransmitting(pttButton: Button) {

android/src/main/java/com/resgrid/plugins/resgrid/fragments/BottomAudioView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BottomAudioView(private val configData: ConfigData, private val audioView:
112112

113113
override fun onCancel(dialog: DialogInterface) {
114114
super.onCancel(dialog)
115-
Logger.info("Klarna KCO plugin: Cancel the bottom sheet dialog")
115+
Logger.info("Resgrid plugin: Cancel the bottom sheet dialog")
116116
//kco.notifyWeb("closed", JSObject())
117117
}
118118

android/src/main/java/com/resgrid/plugins/resgrid/vms/CallViewModel.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ class CallViewModel(
116116
private val mutablePermissionAllowed = MutableStateFlow(true)
117117
val permissionAllowed = mutablePermissionAllowed.hide()
118118

119+
private val mutableHeadsetConnected = MutableLiveData(false)
120+
val headsetConnected = mutableHeadsetConnected.hide()
121+
119122
val preferences = Preferences(application.applicationContext, PreferencesConfiguration.DEFAULTS!!);
120123

121124
init {
@@ -285,6 +288,12 @@ class CallViewModel(
285288
}
286289
}
287290

291+
fun setHeadsetConnected(connected: Boolean) {
292+
viewModelScope.launch {
293+
mutableHeadsetConnected.postValue(connected)
294+
}
295+
}
296+
288297
fun setCameraEnabled(enabled: Boolean) {
289298
viewModelScope.launch {
290299
room.localParticipant.setCameraEnabled(enabled)
@@ -392,6 +401,8 @@ class CallViewModel(
392401
newDevice!!.connect(10000) { response ->
393402
run {
394403
if (response.success) {
404+
setHeadsetConnected(true);
405+
395406
newDevice!!.setNotifications(UUID.fromString("127FACE1-CB21-11E5-93D0-0002A5D5C51B"), UUID.fromString("127FBEEF-CB21-11E5-93D0-0002A5D5C51B"), true, { response ->
396407
run {
397408
if (response != null) {
@@ -400,7 +411,7 @@ class CallViewModel(
400411
stopTransmittingSound?.seekTo(0)
401412

402413
setMicEnabled(false)
403-
} else if (response.value.trim() == "01") {
414+
} else if (response.value.trim() == "01" || response.value.trim() == "04") {
404415
startTransmittingSound?.start()
405416
startTransmittingSound?.seekTo(0)
406417

@@ -431,13 +442,14 @@ class CallViewModel(
431442
run {
432443
newDevice = null
433444
preferences.clear()
445+
setHeadsetConnected(false)
434446
}
435447
}
436448
}
437449
}
438450

439451
private fun onDisconnect(deviceId: String) {
440-
452+
setHeadsetConnected(false)
441453
}
442454

443455
// Debug functions

android/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<color name="colorPrimary">#007DFF</color>
44
<color name="colorPrimaryDark">#0058b3</color>
55
<color name="colorAccent">#66b1ff</color>
6+
<color name="colorWhite">#FFFFFF</color>
7+
<color name="colorTransmitting">#FF4081</color>
68
<color name="no_video_participant">#5A8BFF</color>
79
<color name="no_video_background">#00153C</color>
810
</resources>

ios/Plugin/Views/AudioRoomView.swift

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct AudioRoomView: View {
1515
@State private var screenPickerPresented = false
1616
@State private var showConnectionTime = true
1717
@State var isLongPressing = false
18+
@State var isDeviceConnected = false
19+
@State var deviceId = "";
1820

1921
@State private var deviceManager: DeviceManager?
2022

@@ -28,8 +30,7 @@ struct AudioRoomView: View {
2830
NavigationView {
2931
GeometryReader { geometry in
3032
content(geometry: geometry)
31-
}
32-
.toolbar {
33+
}.toolbar {
3334
ToolbarItemGroup(placement: .navigationBarLeading) {
3435
Text("(\(room.room.remoteParticipants.count)) ")
3536

@@ -38,15 +39,17 @@ struct AudioRoomView: View {
3839
// Select Headset
3940
Menu {
4041
Section {
41-
Button(action: {}) {
42+
Button(action: {
43+
disconnectHeadset()
44+
}) {
4245
Label("Disconnect", systemImage: "minus")
4346
}
4447
Button(action: {
4548
deviceManager = DeviceManager({ (success, message) -> Void in
4649
if success {
4750
connectToHeadset()
4851
} else {
49-
52+
isDeviceConnected = false
5053
}
5154
})
5255

@@ -55,7 +58,8 @@ struct AudioRoomView: View {
5558
}
5659
}
5760
} label: {
58-
Label("Headset", systemImage: "megaphone")
61+
Image(systemSymbol: .phoneFill)
62+
.renderingMode(isDeviceConnected ? .original : .template)
5963
}
6064

6165
Divider()
@@ -103,7 +107,23 @@ struct AudioRoomView: View {
103107
}
104108
}
105109
}
106-
110+
111+
func disconnectHeadset() {
112+
guard let device = deviceManager!.getDevice(deviceId) else {
113+
return
114+
}
115+
116+
deviceManager!.disconnect(device, CONNECTION_TIMEOUT, bleDisconnectComplete)
117+
118+
}
119+
120+
func bleDisconnectComplete(_ success: Bool, _ message: String) -> Void {
121+
if success {
122+
log("Disconnected from device")
123+
isDeviceConnected = false
124+
}
125+
}
126+
107127
func connectToHeadset() {
108128
deviceManager!.startScanning(
109129
[HeadsetPeripheral.AINA_HEADSET_SERVICE],
@@ -124,11 +144,13 @@ struct AudioRoomView: View {
124144
return
125145
}
126146
log("Scanning complete, attempting to connect.")
127-
147+
deviceId = message
148+
128149
device.setOnConnected(CONNECTION_TIMEOUT, { (success2, message2) -> Void in
129150
if success2 {
130151
log("Connected to device")
131-
152+
isDeviceConnected = true
153+
132154
device.setNotifications(
133155
HeadsetPeripheral.AINA_HEADSET_SERVICE,
134156
HeadsetPeripheral.AINA_HEADSET_SERVICE_PROP,
@@ -147,6 +169,7 @@ struct AudioRoomView: View {
147169
//call.resolve()
148170
} else {
149171
//call.reject(message)
172+
isDeviceConnected = false
150173
}
151174
})
152175
self.deviceManager?.setOnDisconnected(device, { (_, _) -> Void in
@@ -165,17 +188,19 @@ struct AudioRoomView: View {
165188
//let bleDevice: BleDevice = self.getBleDevice(device)
166189
//call.resolve(bleDevice)
167190
} else {
168-
191+
isDeviceConnected = false
169192
}
170193
}
171194

172195
func processBluetoothEvents(_ success: Bool, _ message: String) -> Void {
173196
if success {
174197
log("ble message: " + message)
175198

176-
if (message == "00") {
199+
let trimmedMessage = message.trimmingCharacters(in: .whitespacesAndNewlines)
200+
201+
if (trimmedMessage == "00") {
177202
stopTransmitting()
178-
} else if (message == "04") {
203+
} else if (trimmedMessage == "04" || trimmedMessage == "01") {
179204
startTransmitting()
180205
}
181206
}

0 commit comments

Comments
 (0)