Skip to content

Commit 47eb931

Browse files
authored
Merge pull request #436 from PlayerData/remove-all-events
Remove all events
2 parents 3619ec5 + 760875d commit 47eb931

File tree

4 files changed

+18
-70
lines changed

4 files changed

+18
-70
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,35 @@ pnpm install @playerdata/react-native-mcu-manager
2626

2727
Run `npx pod-install` after installing the pnpm package.
2828

29-
3029
### Configure for Android
3130

3231
## Usage
32+
3333
```ts
34-
import McuManager, { ProgressEvent, UploadEvents } from '@playerdata/react-native-mcu-manager';
34+
import McuManager, {
35+
UpgradeOptions,
36+
} from '@playerdata/react-native-mcu-manager';
3537

36-
const onUploadProgress = (progress: ProgressEvent) => {
37-
console.log("Upload progress: ", progress.bleId, progress.progress);
38+
const upgradeOptions: UpgradeOptions = {
39+
estimatedSwapTime: 30,
3840
};
3941

40-
const onUploadStateChanged = (progress: ProgressEvent) => {
41-
console.log("Upload state change: ", progress.bleId, progress.state);
42+
const onUploadProgress = (progress: number) => {
43+
console.log('Upload progress: ', progress);
4244
};
4345

44-
UploadEvents.addListener('uploadProgress', onUploadProgress);
45-
UploadEvents.addListener('uploadStateChanged', onUploadStateChanged);
46+
const onUploadStateChanged = (state: string) => {
47+
console.log('Upload state change: ', state);
48+
};
4649

4750
// bluetoothId is a MAC address on Android, and a UUID on iOS
48-
McuManager.updateDevice(bluetoothId, fileUri)
51+
McuManager.updateDevice(
52+
bluetoothId,
53+
fileUri,
54+
upgradeOptions,
55+
onUploadProgress,
56+
onUploadStateChanged
57+
);
4958
```
5059

5160
# Contributing

example/src/useFirmwareUpdate.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,7 @@ const useFirmwareUpdate = (
2828

2929
upgradeRef.current = upgrade;
3030

31-
const uploadProgressListener = upgrade.addListener(
32-
'uploadProgress',
33-
({ progress: newProgress }) => {
34-
setProgress(newProgress);
35-
}
36-
);
37-
38-
const uploadStateChangedListener = upgrade.addListener(
39-
'upgradeStateChanged',
40-
({ state: newState }) => {
41-
setState(newState);
42-
}
43-
);
44-
4531
return function cleanup() {
46-
uploadProgressListener.remove();
47-
uploadStateChangedListener.remove();
48-
4932
upgrade.cancel();
5033
upgrade.destroy();
5134
};

react-native-mcu-manager/ios/ReactNativeMcuManagerModule.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ import os
55

66
private let MODULE_NAME = "ReactNativeMcuManager"
77
private let TAG = "McuManagerModule"
8-
private let UPGRADE_STATE_EVENTS = "upgradeStateChanged"
9-
private let UPLOAD_PROGRESS_EVENTS = "uploadProgress"
108

119
public class ReactNativeMcuManagerModule: Module {
1210
private var upgrades: [String: DeviceUpgrade] = [:]
1311

1412
public func definition() -> ModuleDefinition {
1513
Name(MODULE_NAME)
1614

17-
// Defines event names that the module can send to JavaScript.
18-
Events(UPGRADE_STATE_EVENTS, UPLOAD_PROGRESS_EVENTS)
19-
2015
AsyncFunction("eraseImage") { (bleId: String, promise: Promise) in
2116
guard let bleUuid = UUID(uuidString: bleId) else {
2217
promise.reject(Exception(name: "UUIDParseError", description: "Failed to parse UUID"))

react-native-mcu-manager/src/Upgrade.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { EventEmitter, EventSubscription } from 'expo-modules-core';
2-
31
import ReactNativeMcuManager from './ReactNativeMcuManagerModule';
42

53
export enum UpgradeMode {
@@ -50,33 +48,6 @@ export type FirmwareUpgradeState =
5048
declare const UpgradeIdSymbol: unique symbol;
5149
type UpgradeID = string & { [UpgradeIdSymbol]: never };
5250

53-
type UpgradeEvent = 'upgradeStateChanged' | 'uploadProgress';
54-
55-
type UpgradeStateChangedPayload = {
56-
id: UpgradeID;
57-
state: FirmwareUpgradeState;
58-
};
59-
type UploadProgressPayload = { id: UpgradeID; progress: number };
60-
type UpgradeEventPayload = UpgradeStateChangedPayload & UploadProgressPayload;
61-
62-
type AddUpgradeListener = {
63-
(
64-
eventType: 'upgradeStateChanged',
65-
listener: (event: UpgradeStateChangedPayload) => void
66-
): EventSubscription;
67-
(
68-
eventType: 'uploadProgress',
69-
listener: (event: UploadProgressPayload) => void
70-
): EventSubscription;
71-
};
72-
73-
type McuManagerEventMap = {
74-
upgradeStateChanged: (payload: UpgradeStateChangedPayload) => void;
75-
uploadProgress: (payload: UploadProgressPayload) => void;
76-
};
77-
78-
const McuManagerEvents = new EventEmitter<McuManagerEventMap>();
79-
8051
class Upgrade {
8152
private id: UpgradeID;
8253

@@ -122,16 +93,6 @@ class Upgrade {
12293
ReactNativeMcuManager.cancelUpgrade(this.id);
12394
};
12495

125-
addListener: AddUpgradeListener = (
126-
eventType: UpgradeEvent,
127-
listener: (event: UpgradeEventPayload) => void
128-
): EventSubscription => {
129-
return McuManagerEvents.addListener(eventType, (event) => {
130-
if (event.id !== this.id) return;
131-
listener(event);
132-
});
133-
};
134-
13596
/**
13697
* Call to release native Upgrade class.
13798
* Failure to do so may result in memory leaks.

0 commit comments

Comments
 (0)