@tower-supplies/react-native-broadcast-receiver 0.6.2

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.
Files changed (68) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +53 -0
  3. package/android/build.gradle +158 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +5 -0
  6. package/android/src/main/java/com/broadcastreceiver/BroadcastReceiverImpl.kt +90 -0
  7. package/android/src/main/java/com/broadcastreceiver/BroadcastReceiverPackage.kt +35 -0
  8. package/android/src/main/java/com/broadcastreceiver/BroadcastReceiverReceiver.kt +104 -0
  9. package/android/src/main/java/com/broadcastreceiver/Constants.kt +8 -0
  10. package/android/src/main/java/com/broadcastreceiver/IntentConfiguration.kt +21 -0
  11. package/android/src/newarch/java/com/BroadcastReceiverModule.kt +51 -0
  12. package/android/src/oldarch/java/com/BroadcastReceiverModule.kt +54 -0
  13. package/ios/BarcodeScanner-Bridging-Header.h +2 -0
  14. package/ios/BarcodeScanner.m +14 -0
  15. package/ios/BarcodeScanner.swift +8 -0
  16. package/ios/BarcodeScanner.xcodeproj/project.pbxproj +283 -0
  17. package/lib/commonjs/BroadcastReceiver.js +51 -0
  18. package/lib/commonjs/BroadcastReceiver.js.map +1 -0
  19. package/lib/commonjs/config.js +35 -0
  20. package/lib/commonjs/config.js.map +1 -0
  21. package/lib/commonjs/error.js +12 -0
  22. package/lib/commonjs/error.js.map +1 -0
  23. package/lib/commonjs/index.js +19 -0
  24. package/lib/commonjs/index.js.map +1 -0
  25. package/lib/commonjs/js/NativeBroadcastReceiver.js +9 -0
  26. package/lib/commonjs/js/NativeBroadcastReceiver.js.map +1 -0
  27. package/lib/commonjs/package.json +1 -0
  28. package/lib/commonjs/types.js +6 -0
  29. package/lib/commonjs/types.js.map +1 -0
  30. package/lib/commonjs/util.js +10 -0
  31. package/lib/commonjs/util.js.map +1 -0
  32. package/lib/module/BroadcastReceiver.js +49 -0
  33. package/lib/module/BroadcastReceiver.js.map +1 -0
  34. package/lib/module/config.js +32 -0
  35. package/lib/module/config.js.map +1 -0
  36. package/lib/module/error.js +9 -0
  37. package/lib/module/error.js.map +1 -0
  38. package/lib/module/index.js +9 -0
  39. package/lib/module/index.js.map +1 -0
  40. package/lib/module/js/NativeBroadcastReceiver.js +5 -0
  41. package/lib/module/js/NativeBroadcastReceiver.js.map +1 -0
  42. package/lib/module/types.js +4 -0
  43. package/lib/module/types.js.map +1 -0
  44. package/lib/module/util.js +7 -0
  45. package/lib/module/util.js.map +1 -0
  46. package/lib/typescript/BroadcastReceiver.d.ts +13 -0
  47. package/lib/typescript/BroadcastReceiver.d.ts.map +1 -0
  48. package/lib/typescript/config.d.ts +11 -0
  49. package/lib/typescript/config.d.ts.map +1 -0
  50. package/lib/typescript/error.d.ts +3 -0
  51. package/lib/typescript/error.d.ts.map +1 -0
  52. package/lib/typescript/index.d.ts +9 -0
  53. package/lib/typescript/index.d.ts.map +1 -0
  54. package/lib/typescript/js/NativeBroadcastReceiver.d.ts +8 -0
  55. package/lib/typescript/js/NativeBroadcastReceiver.d.ts.map +1 -0
  56. package/lib/typescript/types.d.ts +39 -0
  57. package/lib/typescript/types.d.ts.map +1 -0
  58. package/lib/typescript/util.d.ts +4 -0
  59. package/lib/typescript/util.d.ts.map +1 -0
  60. package/package.json +162 -0
  61. package/react-native-broadcast-receiver.podspec +35 -0
  62. package/src/BroadcastReceiver.ts +60 -0
  63. package/src/config.ts +36 -0
  64. package/src/error.ts +9 -0
  65. package/src/index.ts +10 -0
  66. package/src/js/NativeBroadcastReceiver.ts +11 -0
  67. package/src/types.ts +47 -0
  68. package/src/util.ts +7 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,QAAA,MAAM,aAAa,EAAE,kBAqBpB,CAAC;AAEF,KAAK,KAAK,GAAG,iBAAiB,CAAC;AAG/B,QAAA,MAAM,SAAS;;;;CAId,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC;AACpC,YAAY,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const LINKING_ERROR: string;
2
+ export { LINKING_ERROR };
3
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,QAIc,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { receiver } from './BroadcastReceiver';
2
+ import { type Event as BroadcastEventType } from './config';
3
+ declare const BroadcastEvent: "BROADCAST_EVENT";
4
+ declare const ModuleName: "RNBroadcastReceiver";
5
+ declare const DataKey: "data";
6
+ export type { BroadcastEventCallback, BroadcastEventData } from './types';
7
+ export { receiver as BroadcastReceiver, BroadcastEvent, ModuleName, DataKey };
8
+ export type { BroadcastEventType };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,KAAK,KAAK,IAAI,kBAAkB,EAAa,MAAM,UAAU,CAAC;AAEvE,QAAA,MAAM,cAAc,mBAAiC,CAAC;AACtD,QAAA,MAAM,UAAU,uBAAwB,CAAC;AACzC,QAAA,MAAM,OAAO,QAAsB,CAAC;AAEpC,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC9E,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ getPhoneID(): Promise<Array<string>>;
4
+ setIntentConfig(args: Array<Array<string>>): Promise<boolean>;
5
+ }
6
+ declare const _default: Spec | undefined;
7
+ export default _default;
8
+ //# sourceMappingURL=NativeBroadcastReceiver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeBroadcastReceiver.d.ts","sourceRoot":"","sources":["../../../src/js/NativeBroadcastReceiver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACrC,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/D;wBAGG,IAAI,GACJ,SAAS;AAFb,wBAEc"}
@@ -0,0 +1,39 @@
1
+ import type { EmitterSubscription } from 'react-native';
2
+ import type { Constants } from './config';
3
+ type IntentActionConfigTuple = [string, string][];
4
+ type IntentActionConfig = {
5
+ action: string;
6
+ datakey: string;
7
+ }[];
8
+ interface BroadcastEventData {
9
+ /**
10
+ * intent that was triggered
11
+ */
12
+ action: string;
13
+ /**
14
+ * Scanned barcode data from harware scanners
15
+ */
16
+ [Constants.DATA_PROP]: string | Record<string, string>;
17
+ }
18
+ type BroadcastEventCallback = (d: BroadcastEventData) => void;
19
+ interface NativeModuleType {
20
+ getPhoneID(): Promise<string[]>;
21
+ setIntentConfig(args: IntentActionConfigTuple): Promise<boolean>;
22
+ }
23
+ interface BroadcastReceiverInterface {
24
+ /**
25
+ * Get device harware id
26
+ */
27
+ getPhoneID(): Promise<string[]>;
28
+ /**
29
+ *
30
+ * @param args ``` [intentAction: string, intentExtrasDataKey: string][] ```
31
+ * @description
32
+ * - `intentAction` is the actions name that'd be registered for `android.BroadcastReceiver`
33
+ * - `intentExtrasDataKey` will be used to extract data from the intent
34
+ */
35
+ setIntentActionConfig(args: IntentActionConfig): Promise<boolean>;
36
+ addEventListener(cb: BroadcastEventCallback): EmitterSubscription;
37
+ }
38
+ export type { NativeModuleType, BroadcastReceiverInterface, IntentActionConfigTuple, IntentActionConfig, BroadcastEventData, BroadcastEventCallback, };
39
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,uBAAuB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;AAClD,KAAK,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC;AAEhE,UAAU,kBAAkB;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxD;AACD,KAAK,sBAAsB,GAAG,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAE9D,UAAU,gBAAgB;IACxB,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAChC,eAAe,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAClE;AAED,UAAU,0BAA0B;IAClC;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAChC;;;;;;OAMG;IACH,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,gBAAgB,CAAC,EAAE,EAAE,sBAAsB,GAAG,mBAAmB,CAAC;CACnE;AAED,YAAY,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IntentActionConfig, IntentActionConfigTuple } from './types';
2
+ declare function transformConfig(config: IntentActionConfig): IntentActionConfigTuple;
3
+ export { transformConfig };
4
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE3E,iBAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,uBAAuB,CAE5E;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,162 @@
1
+ {
2
+ "name": "@tower-supplies/react-native-broadcast-receiver",
3
+ "version": "0.6.2",
4
+ "description": "test",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!lib/typescript/example",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "scripts": {
30
+ "test": "jest",
31
+ "typescript": "tsc --noEmit",
32
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
+ "prepare": "bob build",
34
+ "release": "dotenv release-it",
35
+ "example": "yarn --cwd example",
36
+ "bootstrap": "yarn example && yarn install && yarn example pods",
37
+ "broadcast": "adb shell am broadcast -a BROADCAST_BARCODE --es BROADCAST_BARCODE_STRING"
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "broadcast-receiver",
42
+ "broadcast",
43
+ "receiver",
44
+ "ios",
45
+ "android"
46
+ ],
47
+ "repository": "https://github.com/tower-supplies/react-native-broadcast-receiver",
48
+ "author": "Adrian Stokes <adrian.stokes@tower-supplies.com> (https://github.com/adrian-stokes)",
49
+ "license": "MIT",
50
+ "bugs": {
51
+ "url": "https://github.com/tower-supplies/react-native-broadcast-receiver/issues"
52
+ },
53
+ "homepage": "https://github.com/tower-supplies/react-native-broadcast-receiver#readme",
54
+ "publishConfig": {
55
+ "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "devDependencies": {
58
+ "@babel/core": "^7.8.0",
59
+ "@commitlint/config-conventional": "^17.0.2",
60
+ "@evilmartians/lefthook": "^2.0.15",
61
+ "@react-native-community/eslint-config": "^3.0.2",
62
+ "@react-native/babel-preset": "^0.83.1",
63
+ "@release-it/conventional-changelog": "^10.0.4",
64
+ "@types/jest": "^28.1.2",
65
+ "@types/node": "^25.0.10",
66
+ "@types/react": "^19.1.0",
67
+ "@types/react-native": "0.70.0",
68
+ "@types/react-test-renderer": "^18.3.0",
69
+ "commitlint": "^20.3.1",
70
+ "dotenv-cli": "^6.0.0",
71
+ "eslint": "^8.4.1",
72
+ "eslint-config-prettier": "^8.5.0",
73
+ "eslint-plugin-prettier": "^4.0.0",
74
+ "jest": "^28.1.1",
75
+ "pod-install": "^0.1.0",
76
+ "prettier": "^2.0.5",
77
+ "react": "19.1.0",
78
+ "react-native": "0.81.5",
79
+ "react-native-builder-bob": "^0.40.17",
80
+ "release-it": "^19.2.4",
81
+ "shell-escape": "^0.2.0",
82
+ "typescript": "^5.5.4"
83
+ },
84
+ "peerDependencies": {
85
+ "react": "*",
86
+ "react-native": "*"
87
+ },
88
+ "jest": {
89
+ "preset": "react-native",
90
+ "modulePathIgnorePatterns": [
91
+ "<rootDir>/example/node_modules",
92
+ "<rootDir>/lib/"
93
+ ]
94
+ },
95
+ "commitlint": {
96
+ "extends": [
97
+ "@commitlint/config-conventional"
98
+ ]
99
+ },
100
+ "release-it": {
101
+ "git": {
102
+ "commitMessage": "chore: release ${version}",
103
+ "tagName": "v${version}"
104
+ },
105
+ "npm": {
106
+ "publish": true
107
+ },
108
+ "github": {
109
+ "release": true
110
+ },
111
+ "plugins": {
112
+ "@release-it/conventional-changelog": {
113
+ "preset": "angular"
114
+ }
115
+ }
116
+ },
117
+ "eslintConfig": {
118
+ "root": true,
119
+ "extends": [
120
+ "@react-native-community",
121
+ "prettier"
122
+ ],
123
+ "rules": {
124
+ "prettier/prettier": [
125
+ "error",
126
+ {
127
+ "quoteProps": "consistent",
128
+ "singleQuote": true,
129
+ "tabWidth": 2,
130
+ "trailingComma": "es5",
131
+ "useTabs": false
132
+ }
133
+ ]
134
+ }
135
+ },
136
+ "eslintIgnore": [
137
+ "node_modules/",
138
+ "lib/"
139
+ ],
140
+ "prettier": {
141
+ "quoteProps": "consistent",
142
+ "singleQuote": true,
143
+ "tabWidth": 2,
144
+ "trailingComma": "es5",
145
+ "useTabs": false
146
+ },
147
+ "react-native-builder-bob": {
148
+ "source": "src",
149
+ "output": "lib",
150
+ "targets": [
151
+ "commonjs",
152
+ "module",
153
+ [
154
+ "typescript",
155
+ {
156
+ "project": "tsconfig.build.json"
157
+ }
158
+ ]
159
+ ]
160
+ },
161
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
162
+ }
@@ -0,0 +1,35 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-broadcast-receiver"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "10.0" }
15
+ s.source = { :git => "https://github.com/tower-supplies/react-native-broadcast-receiver.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+
19
+ s.dependency "React-Core"
20
+
21
+ # Don't install the dependencies when we run `pod install` in the old architecture.
22
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
23
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
24
+ s.pod_target_xcconfig = {
25
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
26
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
27
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
28
+ }
29
+ s.dependency "React-Codegen"
30
+ s.dependency "RCT-Folly"
31
+ s.dependency "RCTRequired"
32
+ s.dependency "RCTTypeSafety"
33
+ s.dependency "ReactCommon/turbomodule/core"
34
+ end
35
+ end
@@ -0,0 +1,60 @@
1
+ import { NativeEventEmitter, NativeModule, Platform } from 'react-native';
2
+ import { Constants, defaultConfig } from './config';
3
+ import type * as t from './types';
4
+ import { transformConfig } from './util';
5
+ import RNBroadcastReceiver from './js/NativeBroadcastReceiver';
6
+ import { LogBox } from 'react-native';
7
+
8
+ // Ignore log notification by message
9
+ LogBox.ignoreLogs([
10
+ '`new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.',
11
+ '`new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.',
12
+ ]);
13
+
14
+ const nativeEventEmitter = new NativeEventEmitter(
15
+ RNBroadcastReceiver as unknown as NativeModule
16
+ );
17
+ class BroadcastReceiver implements t.BroadcastReceiverInterface {
18
+ private _nativeModule: t.NativeModuleType | undefined;
19
+ constructor(args: t.IntentActionConfig = defaultConfig) {
20
+ this._nativeModule = this.getNativeModule();
21
+ this.setIntentActionConfig(args);
22
+ }
23
+
24
+ private getNativeModule = (): t.NativeModuleType | undefined => {
25
+ return RNBroadcastReceiver;
26
+ };
27
+
28
+ addEventListener(listener: t.BroadcastEventCallback) {
29
+ return nativeEventEmitter.addListener(
30
+ Constants.BROADCAST_EVENT_NAME,
31
+ listener
32
+ );
33
+ }
34
+
35
+ sendEvent(payload: unknown) {
36
+ return nativeEventEmitter.emit(Constants.BROADCAST_EVENT_NAME, {
37
+ [Constants.DATA_PROP]: payload,
38
+ });
39
+ }
40
+
41
+ // Start Region :: Native modules methods
42
+ setIntentActionConfig(args: t.IntentActionConfig) {
43
+ if (Platform.OS === 'ios') return Promise.resolve(false);
44
+ return (
45
+ this._nativeModule?.setIntentConfig(transformConfig(args)) ??
46
+ Promise.resolve(false)
47
+ );
48
+ }
49
+ getPhoneID() {
50
+ if (Platform.OS === 'ios') return Promise.resolve(['']);
51
+ return this._nativeModule?.getPhoneID() ?? Promise.resolve(['']);
52
+ }
53
+
54
+ // Start Region :: Native modules methods
55
+ }
56
+ const receiver = new BroadcastReceiver([
57
+ { action: 'com.string.intent', datakey: 'data' },
58
+ { action: 'com.record.intent', datakey: '' },
59
+ ]);
60
+ export { receiver };
package/src/config.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { IntentActionConfig } from './types';
2
+
3
+ const defaultConfig: IntentActionConfig = [
4
+ // {
5
+ // action: 'com.cipherlab.barcodebaseapi.PASS_DATA_2_APP',
6
+ // datakey: 'Decoder_Data',
7
+ // },
8
+ // {
9
+ // action: 'com.barcodeservice.broadcast.string',
10
+ // datakey: 'barcodedata',
11
+ // },
12
+ // {
13
+ // action: 'BROADCAST_BARCODE',
14
+ // datakey: 'BROADCAST_BARCODE_STRING',
15
+ // },
16
+ // {
17
+ // action: 'zebra.barcode',
18
+ // datakey: 'com.motorolasolutions.emdk.datawedge.data_string',
19
+ // },
20
+ // {
21
+ // action: 'com.honeywell.scantointent.intent.action.BARCODE',
22
+ // datakey: 'data',
23
+ // },
24
+ ];
25
+
26
+ type Event = 'BROADCAST_EVENT';
27
+ const BROADCAST_EVENT_NAME: Event = 'BROADCAST_EVENT';
28
+
29
+ const Constants = {
30
+ MODULE_NAME: 'RNBroadcastReceiver' as const,
31
+ DATA_PROP: 'data' as const,
32
+ BROADCAST_EVENT_NAME,
33
+ };
34
+
35
+ export { defaultConfig, Constants };
36
+ export type { Event };
package/src/error.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'react-native-broadcast-receiver' doesn't seem to be linked. Make sure: \n\n` +
5
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+
9
+ export { LINKING_ERROR };
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { receiver } from './BroadcastReceiver';
2
+ import { type Event as BroadcastEventType, Constants } from './config';
3
+
4
+ const BroadcastEvent = Constants.BROADCAST_EVENT_NAME;
5
+ const ModuleName = Constants.MODULE_NAME;
6
+ const DataKey = Constants.DATA_PROP;
7
+
8
+ export type { BroadcastEventCallback, BroadcastEventData } from './types';
9
+ export { receiver as BroadcastReceiver, BroadcastEvent, ModuleName, DataKey };
10
+ export type { BroadcastEventType };
@@ -0,0 +1,11 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ getPhoneID(): Promise<Array<string>>;
6
+ setIntentConfig(args: Array<Array<string>>): Promise<boolean>;
7
+ }
8
+
9
+ export default TurboModuleRegistry.get<Spec>('RNBroadcastReceiver') as
10
+ | Spec
11
+ | undefined;
package/src/types.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { EmitterSubscription } from 'react-native';
2
+ import type { Constants } from './config';
3
+
4
+ type IntentActionConfigTuple = [string, string][];
5
+ type IntentActionConfig = { action: string; datakey: string }[];
6
+
7
+ interface BroadcastEventData {
8
+ /**
9
+ * intent that was triggered
10
+ */
11
+ action: string;
12
+ /**
13
+ * Scanned barcode data from harware scanners
14
+ */
15
+ [Constants.DATA_PROP]: string | Record<string, string>;
16
+ }
17
+ type BroadcastEventCallback = (d: BroadcastEventData) => void;
18
+
19
+ interface NativeModuleType {
20
+ getPhoneID(): Promise<string[]>;
21
+ setIntentConfig(args: IntentActionConfigTuple): Promise<boolean>;
22
+ }
23
+
24
+ interface BroadcastReceiverInterface {
25
+ /**
26
+ * Get device harware id
27
+ */
28
+ getPhoneID(): Promise<string[]>;
29
+ /**
30
+ *
31
+ * @param args ``` [intentAction: string, intentExtrasDataKey: string][] ```
32
+ * @description
33
+ * - `intentAction` is the actions name that'd be registered for `android.BroadcastReceiver`
34
+ * - `intentExtrasDataKey` will be used to extract data from the intent
35
+ */
36
+ setIntentActionConfig(args: IntentActionConfig): Promise<boolean>;
37
+ addEventListener(cb: BroadcastEventCallback): EmitterSubscription;
38
+ }
39
+
40
+ export type {
41
+ NativeModuleType,
42
+ BroadcastReceiverInterface,
43
+ IntentActionConfigTuple,
44
+ IntentActionConfig,
45
+ BroadcastEventData,
46
+ BroadcastEventCallback,
47
+ };
package/src/util.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { IntentActionConfig, IntentActionConfigTuple } from './types';
2
+
3
+ function transformConfig(config: IntentActionConfig): IntentActionConfigTuple {
4
+ return config.map((x) => [x.action, x.datakey]);
5
+ }
6
+
7
+ export { transformConfig };