Skip to content

Commit

Permalink
feat: add missing ts interfaces for abrevva modules (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhochsto authored Jul 30, 2024
2 parents 212ebd1 + 244ee2c commit 97988b3
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 212 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ To start off first import `AbrevvaBle` from this module
import {AbrevvaBle} from 'react-natice-example-app';

async function scanForBleDevices(androidNeverForLocation: Boolean, timeout: Number){
await AbrevvaBle.initialize({
androidNeverForLocation: true,
});
const androidNeverForLocation = true;
await AbrevvaBle.initialize(androidNeverForLocation);

const timeout = 10_000
AbrevvaBle.requestLEScan(
{ timeout: 10_000 },
timeout,
(data: ScanResult) => {
console.log(`found device: ${data.name}`);
},
Expand All @@ -95,24 +95,24 @@ async function scanForBleDevices(androidNeverForLocation: Boolean, timeout: Numb
With the signalize method you can localize EVVA components. On a successful signalization the component will emit a melody indicating its location.

```typescript
AbrevvaBle.signalize(
{'deviceID': deviceID},
() => {
console.log(`Signalized /w success=${it}`)
}
);
AbrevvaBle.signalize(
deviceID,
() => {
console.log(`Signalized /w success=${it}`)
}
);
```
### Perform disengage for EVVA components

For the component disengage you have to provide access credentials to the EVVA component. Those are generally acquired in the form of access media metadata from the Xesar software.

```typescript
AbrevvaBle.disengage({
mobileId: '',
mobileDeviceKey:: '',
mobileGroupId: '',
mobileAccessData: '',
isPermanentRelease: '',
timeout: 10_000
});
AbrevvaBle.disengage(
mobileId: '',
mobileDeviceKey:: '',
mobileGroupId: '',
mobileAccessData: '',
isPermanentRelease: '',
timeout: 10_000
);
```
8 changes: 6 additions & 2 deletions android/src/main/java/com/exampleapp/AbrevvaBleModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,16 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :

// not needed for Android
@ReactMethod
fun setSupportedEvents(options: ReadableArray, promise: Promise) {
fun setSupportedEvents(options: ReadableMap, promise: Promise) {
promise.resolve(null)
}

override fun getName(): String {
return ("AbrevvaBle")
return NAME
}

companion object {
const val NAME = "AbrevvaBle"
}

@ReactMethod
Expand Down
7 changes: 6 additions & 1 deletion android/src/main/java/com/exampleapp/AbrevvaCryptoModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ class AbrevvaCryptoModule(reactContext: ReactApplicationContext) :
}

override fun getName(): String {
return ("AbrevvaCrypto")
return NAME
}

companion object {
const val NAME = "AbrevvaCrypto"
}

}
2 changes: 1 addition & 1 deletion android/src/main/java/com/exampleapp/AbrevvaNfcModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish
import java.util.Timer
import java.util.TimerTask

class ReactNativeAbrevvaModule(reactContext: ReactApplicationContext) :
class AbrevvaNfcModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {

private val host = "172.16.2.91"
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/java/com/exampleapp/ExampleAppPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager

class ExampleAppPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf(ReactNativeAbrevvaModule(reactContext)) + listOf(AbrevvaBleModule(reactContext)) + listOf(AbrevvaCryptoModule(reactContext))
return listOf(AbrevvaCryptoModule(reactContext)) + listOf(AbrevvaNfcModule(reactContext)) + listOf(AbrevvaBleModule(reactContext))
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
Expand Down
98 changes: 49 additions & 49 deletions example/ios/ExampleAppExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const CryptoScreen = () => {
<Button
text="random"
onPressFunction={() => {
AbrevvaCrypto.random({ numBytes: 4 }).then((ret: any) => {
AbrevvaCrypto.random(4).then((ret: any) => {
setResult(`random:\n${ret.value}\n\n`);
});
}}
Expand Down
59 changes: 39 additions & 20 deletions example/src/BleScreenComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,6 @@ const ScanResults = ({ setStatus }) => {
const [deviceList, setdeviceList] = useState<ScanResult[]>([]);
const [refreshing, setRefreshing] = useState(false);

const onRefresh = () => {
setStatus('none');
setRefreshing(true);
setdeviceList([]);

AbrevvaBle.stopLEScan().then(() => {
void AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
});
setTimeout(() => {
setRefreshing(false);
}, SCAN_TIMEOUT);
};

const scanRequestCallback = (data: ScanResult) => {
if (data.manufacturerData !== undefined && '2153' in data.manufacturerData) {
const md = new Uint8Array(data.manufacturerData!['2153'].buffer);
Expand All @@ -125,9 +112,43 @@ const ScanResults = ({ setStatus }) => {
}
};

const onRefresh = () => {
setStatus('none');
setRefreshing(true);
setdeviceList([]);

const timeout: NodeJS.Timeout = setTimeout(() => {
setRefreshing(false);
}, SCAN_TIMEOUT);
AbrevvaBle.stopLEScan()
.then(() => {
void AbrevvaBle.requestLEScan(
scanRequestCallback,
(address: string) => {
console.log(`connected to Device =${address}`);
},
(address: string) => {
console.log(`disconnected from Device =${address}`);
},
);
})
.catch((e) => {
console.log(e);
clearTimeout(timeout);
});
};

useEffect(() => {
AbrevvaBle.initialize({ androidNeverForLocation: true }).then(() => {
void AbrevvaBle.requestLEScan({ timeout: SCAN_TIMEOUT }, scanRequestCallback);
AbrevvaBle.initialize(true).then(() => {
void AbrevvaBle.requestLEScan(
scanRequestCallback,
(address: string) => {
console.log(`connected to Device =${address}`);
},
(address: string) => {
console.log(`disconnected from Device =${address}`);
},
);
});
}, []);

Expand Down Expand Up @@ -170,11 +191,9 @@ async function mobileIdentificationMediumService(data: ScanResult, setStatus: an
});

await AbrevvaBle.startNotifications(
{
deviceId: data.device.deviceId,
service: SERVICE,
characteristic: CHARACTERISTICS.ACCESS_STATUS,
},
data.device.deviceId,
SERVICE,
CHARACTERISTICS.ACCESS_STATUS,
(event: ReadResult) => {
newStatus = event.value!;
},
Expand Down
6 changes: 2 additions & 4 deletions ios/ble/AbrevvaBle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ public class AbrevvaBle: RCTEventEmitter {
let data = self.getScanResultDict(device, advertisementData, rssi)
self.sendEvent(withName: "onScanResult", body: data)
},{ address in
self.sendEvent(withName: "connected|\(address)", body: nil)

self.sendEvent(withName: "onConnect", body: address)
},{ address in
self.sendEvent(withName: "disconnected|\(address)", body: nil)

self.sendEvent(withName: "onDisconnect", body: address)
},
timeout
)
Expand Down
30 changes: 25 additions & 5 deletions ios/nfc/AbrevvaNfc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import CoreNFC
import AbrevvaSDK

@objc(AbrevvaNfc)
class AbrevvaNfc: NSObject {

class AbrevvaNfc: NSObject, NFCSessionDelegate {

let HOST = "172.16.2.91" //"172.16.158.30" //
let PORT: UInt16 = 1883
Expand All @@ -18,17 +17,22 @@ class AbrevvaNfc: NSObject {
private var mqtt5Client: MQTT5Client?
private var nfcSession = NFCSession()

override init() {
super.init()
nfcSession.delegate = self
}

@objc func connect() {
var clientCertArray = getClientCertFromP12File(certName: "client-ios.p12", certPassword: "123")
self.clientID = CLIENTID

mqtt5Client = MQTT5Client(clientID: clientID, host: HOST, port: PORT, clientCertArray:clientCertArray)
mqtt5Client?.setOnMessageRecieveHandler(handler: onMessageRecieveHandler)
mqtt5Client?.setDidStateChangeToHandler(handler: didStateChangeToHandler)
mqtt5Client?.connect()

// nfcSession.setPublishKyOnHandler(handler: mqtt5Client!.publishKyOn)
// nfcSession.setPublishKeyOffHander(handler: mqtt5Client!.publishKyOff)

mqtt5Client?.connect()

}

@objc func disconnect() {
Expand Down Expand Up @@ -103,4 +107,20 @@ class AbrevvaNfc: NSObject {
self.mqtt5Client?.disconnect()
self.nfcSession.invalidateSession()
}

func sessionDidStart(_ withSuccess: Bool) {

}

func sessionDidClose(_ withError: (any Error)?) {

}

func sessionDidReceiveKeyOnEvent(_ tagID: Data, _ historicalBytes: Data) {
mqtt5Client?.publishKyOn(identifier: tagID.toHexString(), historicalBytes: historicalBytes.toHexString())
}

func sessionDidReceiveKeyOffEvent(_ tagID: Data, _ historicalBytes: Data) {
mqtt5Client?.publishKyOff(identifier: tagID.toHexString(), historicalBytes: historicalBytes.toHexString())
}
}
Loading

0 comments on commit 97988b3

Please sign in to comment.