@blueid/access-capacitor 0.108.0 → 0.109.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.
@@ -34,6 +34,7 @@ typedef enum BlueReturnCode {
34
34
  BlueReturnCode_Disconnected = -19,
35
35
  BlueReturnCode_PointerConversionFailed = -20,
36
36
  BlueReturnCode_Unavailable = -21,
37
+ BlueReturnCode_Aborted = -22,
37
38
  BlueReturnCode_Test = -29,
38
39
  BlueReturnCode_EncodeDataWriteFailed = -30,
39
40
  BlueReturnCode_EncodeDataWriteNothingWritten = -31,
@@ -34,6 +34,7 @@ typedef enum BlueReturnCode {
34
34
  BlueReturnCode_Disconnected = -19,
35
35
  BlueReturnCode_PointerConversionFailed = -20,
36
36
  BlueReturnCode_Unavailable = -21,
37
+ BlueReturnCode_Aborted = -22,
37
38
  BlueReturnCode_Test = -29,
38
39
  BlueReturnCode_EncodeDataWriteFailed = -30,
39
40
  BlueReturnCode_EncodeDataWriteNothingWritten = -31,
@@ -34,6 +34,7 @@ typedef enum BlueReturnCode {
34
34
  BlueReturnCode_Disconnected = -19,
35
35
  BlueReturnCode_PointerConversionFailed = -20,
36
36
  BlueReturnCode_Unavailable = -21,
37
+ BlueReturnCode_Aborted = -22,
37
38
  BlueReturnCode_Test = -29,
38
39
  BlueReturnCode_EncodeDataWriteFailed = -30,
39
40
  BlueReturnCode_EncodeDataWriteNothingWritten = -31,
@@ -1,8 +1,11 @@
1
1
  import Foundation
2
2
 
3
- // TODO: implement .xconfig files
4
- // private let baseURL = "http://localhost:3000"
5
- private let baseURL = "https://api.dev.blue-id.com"
3
+ #if DEBUG
4
+ private let baseURL = BlueEnvironment.getEnvVar(key: "BLUE_API_ENDPOINT", defaultValue: "https://api.dev.blue-id.com")
5
+ #else
6
+ private let baseURL = BlueEnvironment.getEnvVar(key: "BLUE_API_ENDPOINT", defaultValue: "https://api.blue-id.com")
7
+ #endif
8
+
6
9
 
7
10
  public enum BlueAPIEndpoints: String {
8
11
  case AccessAuthenticationToken = "/access/authenticationToken"
@@ -170,15 +170,13 @@ internal func blueDisconnectBluetoothPeripheral(_ peripheral: CBPeripheral) thro
170
170
  return
171
171
  }
172
172
 
173
- if peripheral.state == .connecting {
174
- blueRemoveSignal(group: "bleCentral", name: "didConnect")
175
- return
176
- }
177
-
178
- guard peripheral.state == .connected else {
173
+ guard peripheral.state == .connected || peripheral.state == .connecting else {
179
174
  throw BlueError(.unavailable)
180
175
  }
181
176
 
177
+ // Remove all signals in case of disconnection, as some of them may not have been properly removed in the event of an abnormal disconnection, such as a timeout.
178
+ blueSignalAbort(group: "bleCentral")
179
+
182
180
  try blueAddSignal(group: "bleCentral", name: "didDisconnectPeripheral")
183
181
 
184
182
  defer { blueRemoveSignal(group: "bleCentral", name: "didDisconnectPeripheral") }
@@ -49,6 +49,7 @@ public enum BlueReturnCode: SwiftProtobuf.Enum {
49
49
  case disconnected // = -19
50
50
  case pointerConversionFailed // = -20
51
51
  case unavailable // = -21
52
+ case aborted // = -22
52
53
  case test // = -29
53
54
  case encodeDataWriteFailed // = -30
54
55
  case encodeDataWriteNothingWritten // = -31
@@ -218,6 +219,7 @@ public enum BlueReturnCode: SwiftProtobuf.Enum {
218
219
  case -31: self = .encodeDataWriteNothingWritten
219
220
  case -30: self = .encodeDataWriteFailed
220
221
  case -29: self = .test
222
+ case -22: self = .aborted
221
223
  case -21: self = .unavailable
222
224
  case -20: self = .pointerConversionFailed
223
225
  case -19: self = .disconnected
@@ -323,6 +325,7 @@ public enum BlueReturnCode: SwiftProtobuf.Enum {
323
325
  case .encodeDataWriteNothingWritten: return -31
324
326
  case .encodeDataWriteFailed: return -30
325
327
  case .test: return -29
328
+ case .aborted: return -22
326
329
  case .unavailable: return -21
327
330
  case .pointerConversionFailed: return -20
328
331
  case .disconnected: return -19
@@ -3735,6 +3738,7 @@ extension BlueReturnCode: SwiftProtobuf._ProtoNameProviding {
3735
3738
  -31: .same(proto: "EncodeDataWriteNothingWritten"),
3736
3739
  -30: .same(proto: "EncodeDataWriteFailed"),
3737
3740
  -29: .same(proto: "Test"),
3741
+ -22: .same(proto: "Aborted"),
3738
3742
  -21: .same(proto: "Unavailable"),
3739
3743
  -20: .same(proto: "PointerConversionFailed"),
3740
3744
  -19: .same(proto: "Disconnected"),
@@ -352,10 +352,7 @@ internal class BlueDeviceBluetooth: BlueDevice, CBPeripheralDelegate {
352
352
  try blueDisconnectBluetoothPeripheral(peripheral)
353
353
 
354
354
  // Remove all signals in case of disconnection, as some of them may not have been properly removed in the event of an abnormal disconnection, such as a timeout.
355
- if (peripheral.state == .disconnected) {
356
- blueRemoveSignal(group: "blePeripheral", name: "didUpdateValueFor")
357
- blueRemoveSignal(group: "blePeripheral", name: "didWriteValueFor")
358
- }
355
+ blueSignalAbort(group: "blePeripheral")
359
356
 
360
357
  blueNotifyUpdatedDevice(self)
361
358
  }
@@ -0,0 +1,21 @@
1
+ import Foundation
2
+
3
+ /**
4
+ * @class BlueEnvironment
5
+ * This class provides access to environment-specific configurations and settings related to the SDK environment.
6
+ */
7
+ internal class BlueEnvironment {
8
+ /// Gets the value of an environment variable.
9
+ ///
10
+ /// - parameters:
11
+ /// - key: The key of the environment variable.
12
+ /// - defaultValue: The default value to return if the environment variable is not found.
13
+ /// - returns: The value of the environment variable if found, otherwise the defaultValue.
14
+ static func getEnvVar(key: String, defaultValue: String) -> String {
15
+ guard let infoDictionary: [String: Any] = Bundle.main.infoDictionary else { return defaultValue }
16
+
17
+ guard let value: String = infoDictionary[key] as? String else { return defaultValue }
18
+
19
+ return value
20
+ }
21
+ }
@@ -45,6 +45,14 @@ fileprivate class BlueSignal {
45
45
  semaphore.signal()
46
46
  }
47
47
  }
48
+
49
+ internal func abort() {
50
+ if let semaphore = self.semaphore {
51
+ self.error = BlueError(.aborted)
52
+ self.result = nil
53
+ semaphore.signal()
54
+ }
55
+ }
48
56
  }
49
57
 
50
58
  private var blueSignalMap: [String: BlueSignal] = [:]
@@ -66,10 +74,12 @@ internal func blueRemoveSignal(group: String, name: String) {
66
74
 
67
75
  if blueSignalMap[key] != nil {
68
76
  blueSignalMap.removeValue(forKey: key)
77
+ blueLogDebug("BlueSignal \(name) in group \(group) has been removed")
69
78
  }
70
79
 
71
80
  if blueHistoryMap[key] != nil {
72
81
  blueHistoryMap.removeValue(forKey: key)
82
+ blueLogDebug("BlueSignal \(name) in group \(group) has been removed from history map")
73
83
  }
74
84
  }
75
85
 
@@ -120,6 +130,22 @@ internal func blueSignalFailure(group: String, name: String, error: Error) {
120
130
  signal.failure(error)
121
131
  }
122
132
 
133
+ /// Aborts the blue signal for a specified group.
134
+ ///
135
+ /// - parameters:
136
+ /// - group: A string indicating the group for which the blue signal should be aborted.
137
+ internal func blueSignalAbort(group: String) {
138
+ for (key, value) in blueSignalMap {
139
+ let keyComponents = key.components(separatedBy: ":")
140
+
141
+ if keyComponents.count >= 2 {
142
+ if (keyComponents[0] == group) {
143
+ value.abort()
144
+ }
145
+ }
146
+ }
147
+ }
148
+
123
149
  internal func blueSignalFailureGroup(group: String, error: Error) {
124
150
  for (key, value) in blueSignalMap {
125
151
  let keyComponents = key.components(separatedBy: ":")
@@ -418,7 +418,7 @@ public func blueTerminalRun<HandlerResult>(
418
418
  do {
419
419
  try device.disconnect()
420
420
  } catch {
421
- blueLogError("Unable to disconnect from peripheral after error")
421
+ blueLogError("Unable to disconnect from peripheral after error: \(error.localizedDescription)")
422
422
  }
423
423
  }
424
424
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueid/access-capacitor",
3
- "version": "0.108.0",
3
+ "version": "0.109.0",
4
4
  "description": "Capacitor JS plugin for the BlueID Access SDK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",