bridgefy-react-native 1.1.7 → 1.1.9

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 (105) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +137 -76
  3. package/android/build.gradle +37 -56
  4. package/android/gradle.properties +4 -4
  5. package/android/src/main/AndroidManifest.xml +1 -11
  6. package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativeModule.kt +590 -333
  7. package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativePackage.kt +25 -8
  8. package/android/src/main/java/me/bridgefy/plugin/react_native/service/BridgefyService.kt +625 -0
  9. package/android/src/main/java/me/bridgefy/plugin/react_native/util/BridgefyOperationModeManager.kt +193 -0
  10. package/android/src/main/java/me/bridgefy/plugin/react_native/util/BridgefyServiceManager.kt +123 -0
  11. package/android/src/main/java/me/bridgefy/plugin/react_native/util/Utils.kt +172 -0
  12. package/bridgefy-react-native.podspec +5 -25
  13. package/ios/BridgefyReactNativeModule.m +88 -0
  14. package/ios/BridgefyReactNativeModule.swift +524 -0
  15. package/lib/module/NativeBridgefy.js +117 -0
  16. package/lib/module/NativeBridgefy.js.map +1 -0
  17. package/lib/module/index.js +172 -207
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/package.json +1 -0
  20. package/lib/typescript/package.json +1 -0
  21. package/lib/typescript/src/NativeBridgefy.d.ts +250 -0
  22. package/lib/typescript/src/NativeBridgefy.d.ts.map +1 -0
  23. package/lib/typescript/src/index.d.ts +146 -0
  24. package/lib/typescript/src/index.d.ts.map +1 -0
  25. package/package.json +77 -72
  26. package/src/NativeBridgefy.ts +321 -0
  27. package/src/index.tsx +283 -225
  28. package/ios/BridgefyReactNative.m +0 -56
  29. package/ios/BridgefyReactNative.swift +0 -368
  30. package/ios/BridgefyReactNative.xcodeproj/project.pbxproj +0 -293
  31. package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  32. package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  33. package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/xcuserdata/bridgefy.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  34. package/ios/BridgefyReactNative.xcodeproj/xcuserdata/bridgefy.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  35. package/ios/Frameworks/BridgefySDK.xcframework/Info.plist +0 -48
  36. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/BridgefySDK +0 -0
  37. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +0 -313
  38. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK.h +0 -15
  39. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Info.plist +0 -0
  40. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.abi.json +0 -7020
  41. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.private.swiftinterface +0 -115
  42. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  43. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftinterface +0 -115
  44. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/module.modulemap +0 -11
  45. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/_CodeSignature/CodeResources +0 -190
  46. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +0 -20
  47. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
  48. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/aarch64/BridgefySDK.yml +0 -13549
  49. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/BridgefySDK +0 -0
  50. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +0 -622
  51. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK.h +0 -15
  52. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Info.plist +0 -0
  53. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.abi.json +0 -7020
  54. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +0 -115
  55. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  56. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +0 -115
  57. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +0 -7020
  58. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +0 -115
  59. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  60. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +0 -115
  61. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/module.modulemap +0 -11
  62. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/_CodeSignature/CodeResources +0 -245
  63. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +0 -20
  64. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
  65. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/aarch64/BridgefySDK.yml +0 -13237
  66. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/x86_64/BridgefySDK.yml +0 -12858
  67. package/lib/commonjs/index.js +0 -278
  68. package/lib/commonjs/index.js.map +0 -1
  69. package/lib/commonjs/infraestructure/index.js +0 -28
  70. package/lib/commonjs/infraestructure/index.js.map +0 -1
  71. package/lib/commonjs/infraestructure/interfaces/ibridgefy.js +0 -6
  72. package/lib/commonjs/infraestructure/interfaces/ibridgefy.js.map +0 -1
  73. package/lib/commonjs/infraestructure/interfaces/index.js +0 -17
  74. package/lib/commonjs/infraestructure/interfaces/index.js.map +0 -1
  75. package/lib/commonjs/infraestructure/services/bridgefy_service.js +0 -6
  76. package/lib/commonjs/infraestructure/services/bridgefy_service.js.map +0 -1
  77. package/lib/commonjs/infraestructure/services/index.js +0 -17
  78. package/lib/commonjs/infraestructure/services/index.js.map +0 -1
  79. package/lib/module/infraestructure/index.js +0 -3
  80. package/lib/module/infraestructure/index.js.map +0 -1
  81. package/lib/module/infraestructure/interfaces/ibridgefy.js +0 -2
  82. package/lib/module/infraestructure/interfaces/ibridgefy.js.map +0 -1
  83. package/lib/module/infraestructure/interfaces/index.js +0 -2
  84. package/lib/module/infraestructure/interfaces/index.js.map +0 -1
  85. package/lib/module/infraestructure/services/bridgefy_service.js +0 -2
  86. package/lib/module/infraestructure/services/bridgefy_service.js.map +0 -1
  87. package/lib/module/infraestructure/services/index.js +0 -2
  88. package/lib/module/infraestructure/services/index.js.map +0 -1
  89. package/lib/typescript/index.d.ts +0 -219
  90. package/lib/typescript/index.d.ts.map +0 -1
  91. package/lib/typescript/infraestructure/index.d.ts +0 -3
  92. package/lib/typescript/infraestructure/index.d.ts.map +0 -1
  93. package/lib/typescript/infraestructure/interfaces/ibridgefy.d.ts +0 -10
  94. package/lib/typescript/infraestructure/interfaces/ibridgefy.d.ts.map +0 -1
  95. package/lib/typescript/infraestructure/interfaces/index.d.ts +0 -2
  96. package/lib/typescript/infraestructure/interfaces/index.d.ts.map +0 -1
  97. package/lib/typescript/infraestructure/services/bridgefy_service.d.ts +0 -17
  98. package/lib/typescript/infraestructure/services/bridgefy_service.d.ts.map +0 -1
  99. package/lib/typescript/infraestructure/services/index.d.ts +0 -2
  100. package/lib/typescript/infraestructure/services/index.d.ts.map +0 -1
  101. package/src/infraestructure/index.tsx +0 -2
  102. package/src/infraestructure/interfaces/ibridgefy.tsx +0 -10
  103. package/src/infraestructure/interfaces/index.tsx +0 -1
  104. package/src/infraestructure/services/bridgefy_service.tsx +0 -20
  105. package/src/infraestructure/services/index.tsx +0 -1
package/src/index.tsx CHANGED
@@ -1,230 +1,178 @@
1
- import { NativeModules, Platform } from 'react-native';
2
- import type {
3
- BridgefyService,
4
- IInitializeIn,
5
- IStartIn,
6
- } from './infraestructure';
7
-
8
- const LINKING_ERROR =
9
- "The package 'bridgefy-react-native' doesn't seem to be linked. Make sure: \n\n" +
10
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
11
- '- You rebuilt the app after installing the package\n' +
12
- '- You are not using Expo Go\n';
13
-
14
- const BridgefyReactNative = NativeModules.BridgefyReactNative
15
- ? NativeModules.BridgefyReactNative
16
- : new Proxy(
17
- {},
18
- {
19
- get() {
20
- throw new Error(LINKING_ERROR);
21
- },
22
- }
23
- );
24
-
25
- /** Profile that defines a series of properties and rules for the propagation of messages. */
26
- export enum BridgefyPropagationProfile {
27
- standard = 'standard',
28
- highDensityNetwork = 'highDensityNetwork',
29
- sparseNetwork = 'sparseNetwork',
30
- longReach = 'longReach',
31
- shortReach = 'shortReach',
32
- }
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import BridgefyReactNative, {
3
+ BridgefyPropagationProfile,
4
+ BridgefyTransmissionModeType,
5
+ BridgefyEvents,
6
+ BridgefyErrorCode,
7
+ BridgefyOperationMode,
8
+ type BridgefyInitConfig,
9
+ type BridgefyTransmissionMode,
10
+ type BridgefyError,
11
+ type BridgefyMessageData,
12
+ type BridgefyStartEvent,
13
+ type BridgefyConnectEvent,
14
+ type BridgefyDisconnectEvent,
15
+ type BridgefySendMessageEvent,
16
+ type BridgefyReceiveDataEvent,
17
+ type BridgefySecureConnectionEvent,
18
+ type BridgefyLicenseInfo,
19
+ type BridgefyUpdatedConnectedEvent,
20
+ type BridgefyDidSendDataProgress,
21
+ type BridgefyOperationModeConfig,
22
+ type BridgefyOperationModeStatus,
23
+ } from './NativeBridgefy';
33
24
 
34
- /** The mode used to propagate a message through nearby devices. */
35
- export enum BridgefyTransmissionModeType {
36
- /** Deliver a message to a specific recipient only if there's an active connection with it. */
37
- p2p = 'p2p',
38
- /** Deliver a message to a specific recipient using nearby devices to propagate it. */
39
- mesh = 'mesh',
40
- /** Propagate a message readable by every device that receives it. */
41
- broadcast = 'broadcast',
42
- }
25
+ /**
26
+ * index.ts
27
+ *
28
+ * Main export file for Bridgefy React Native TurboModule
29
+ * Provides a clean JavaScript/TypeScript wrapper around the native TurboModule
30
+ */
43
31
 
44
- export interface BridgefyTransmissionMode {
45
- type: BridgefyTransmissionModeType;
46
- uuid: string;
47
- }
48
-
49
- /** Describes errors in the Bridgefy error domain. */
50
- export enum BridgefyErrorType {
51
- /** The Bridgefy SDK cannot run in the simulator */
52
- simulatorIsNotSupported = 'simulatorIsNotSupported',
53
- /** The Bridgefy SDK is already running */
54
- alreadyStarted = 'alreadyStarted',
55
- /** The provided API key is not valid */
56
- invalidAPIKey = 'invalidAPIKey',
57
- /** The license is expired */
58
- expiredLicense = 'expiredLicense',
59
- /** An error occurred while creating the session */
60
- sessionError = 'sessionError',
61
- /** (iOS) The Bridgefy SDK hasn't been started */
62
- notStarted = 'notStarted',
63
- /** (iOS) A Bridgefy SDK instance already exists */
64
- alreadyInstantiated = 'alreadyInstantiated',
65
- /** (iOS) The Bridgefy SDK is performing the start process */
66
- startInProgress = 'startInProgress',
67
- /** (iOS) The Bridgefy SDK service is not started */
68
- serviceNotStarted = 'serviceNotStarted',
69
- /** (iOS) Cannot get app's bundle id */
70
- missingBundleID = 'missingBundleID',
71
- /** (iOS) An internet connection is required to validate the license */
72
- internetConnectionRequired = 'internetConnectionRequired',
73
- /** (iOS) The device's time has been modified */
74
- inconsistentDeviceTime = 'inconsistentDeviceTime',
75
- /** (iOS) The user does not allow the use of BLE */
76
- BLEUsageNotGranted = 'BLEUsageNotGranted',
77
- /** (iOS) The use of BLE in this device is restricted */
78
- BLEUsageRestricted = 'BLEUsageRestricted',
79
- /** (iOS) The BLE antenna has been turned off */
80
- BLEPoweredOff = 'BLEPoweredOff',
81
- /** (iOS) The usage of BLE is not supported in the device */
82
- BLEUnsupported = 'BLEUnsupported',
83
- /** (iOS) BLE usage failed with an unknown error */
84
- BLEUnknownError = 'BLEUnknownError',
85
- /** (iOS) Inconsistent connection */
86
- inconsistentConnection = 'inconsistentConnection',
87
- /** (iOS) Connection is already secure */
88
- connectionIsAlreadySecure = 'connectionIsAlreadySecure',
89
- /** (iOS) Cannot create secure connection */
90
- cannotCreateSecureConnection = 'cannotCreateSecureConnection',
91
- /** (iOS) The length of the data exceed the maximum limit */
92
- dataLengthExceeded = 'dataLengthExceeded',
93
- /** (iOS) The data to send is empty */
94
- dataValueIsEmpty = 'dataValueIsEmpty',
95
- /** (iOS) The requested peer is not connected */
96
- peerIsNotConnected = 'peerIsNotConnected',
97
- /** (iOS) An internal error occurred */
98
- internalError = 'internalError',
99
- /** (iOS) An error occurred while validating the license */
100
- licenseError = 'licenseError',
101
- /** (iOS) An error occurred while storing data */
102
- storageError = 'storageError',
103
- /** (iOS) An error occurred while encoding the message */
104
- encodingError = 'encodingError',
105
- /** (iOS) An error occurred while encrypting the message */
106
- encryptionError = 'encryptionError',
107
- /** (Android) Missing application ID */
108
- missingApplicationId = 'missingApplicationId',
109
- /** (Android) Permission exception */
110
- permissionException = 'permissionException',
111
- /** (Android) Registration exception */
112
- registrationException = 'registrationException',
113
- /** (Android) Size limit exceeded */
114
- sizeLimitExceeded = 'sizeLimitExceeded',
115
- /** (Android) Device capabilities error */
116
- deviceCapabilities = 'deviceCapabilities',
117
- /** (Android) Generic exception */
118
- genericException = 'genericException',
119
- /** (Android) Inconsistent device time */
120
- inconsistentDeviceTimeException = 'inconsistentDeviceTimeException',
121
- /** (Android) Internet connection required */
122
- internetConnectionRequiredException = 'internetConnectionRequiredException',
123
- /** (Android) Unknown exception */
124
- unknownException = 'unknownException',
125
- }
32
+ // Export types and enums
33
+ export {
34
+ BridgefyPropagationProfile,
35
+ BridgefyTransmissionModeType,
36
+ BridgefyEvents,
37
+ BridgefyErrorCode,
38
+ BridgefyOperationMode,
39
+ type BridgefyInitConfig,
40
+ type BridgefyTransmissionMode,
41
+ type BridgefyError,
42
+ type BridgefyMessageData,
43
+ type BridgefyStartEvent,
44
+ type BridgefyConnectEvent,
45
+ type BridgefyDisconnectEvent,
46
+ type BridgefySendMessageEvent,
47
+ type BridgefyReceiveDataEvent,
48
+ type BridgefySecureConnectionEvent,
49
+ type BridgefyLicenseInfo,
50
+ type BridgefyUpdatedConnectedEvent,
51
+ type BridgefyDidSendDataProgress,
52
+ type BridgefyOperationModeConfig,
53
+ type BridgefyOperationModeStatus,
54
+ };
126
55
 
127
56
  /**
128
- * These events are available via subscriptions to the `NativeEventEmitter` using the
129
- * `NativeModules.BridgefyReactNative` component. See README for further instructions.
57
+ * Bridgefy class - JavaScript wrapper for the native TurboModule
58
+ * Provides event emitter capabilities and clean API
130
59
  */
131
- export enum BridgefyEvents {
132
- /**
133
- * This function is called when the BridgefySDK has been started.
134
- */
135
- bridgefyDidStart = 'bridgefyDidStart',
136
- /**
137
- * This function is called when an error occurred while starting the BridgefySDK.
138
- */
139
- bridgefyDidFailToStart = 'bridgefyDidFailToStart',
140
- /**
141
- * This function is called when the BridgefySDK has been stopped.
142
- */
143
- bridgefyDidStop = 'bridgefyDidStop',
144
- /**
145
- * This function is called when an error occurred while stopping the BridgefySDK.
146
- */
147
- bridgefyDidFailToStop = 'bridgefyDidFailToStop',
148
- /**
149
- * The current session was destroyed
150
- */
151
- bridgefyDidDestroySession = 'bridgefyDidDestroySession',
152
- /**
153
- * An error occurred while destroying the current session
154
- */
155
- bridgefyDidFailToDestroySession = 'bridgefyDidFailToDestroySession',
60
+ export class Bridgefy {
61
+ private eventEmitter: NativeEventEmitter;
62
+
63
+ constructor() {
64
+ // Create event emitter for native events
65
+ const module = BridgefyReactNative || NativeModules.BridgefyReactNative;
66
+ this.eventEmitter = new NativeEventEmitter(module);
67
+ }
68
+
156
69
  /**
157
- * This function is called to notify a new connection.
70
+ * Initialize the Bridgefy SDK
158
71
  */
159
- bridgefyDidConnect = 'bridgefyDidConnect',
72
+ async initialize(
73
+ apiKey: string,
74
+ verboseLogging: boolean = false,
75
+ operationMode?: BridgefyOperationMode
76
+ ): Promise<void> {
77
+ const config: BridgefyInitConfig = {
78
+ apiKey,
79
+ verboseLogging,
80
+ operationMode,
81
+ };
82
+ return BridgefyReactNative.initialize(config);
83
+ }
84
+
160
85
  /**
161
- * This function is called to notify a disconnection.
86
+ * Start the Bridgefy SDK
162
87
  */
163
- bridgefyDidDisconnect = 'bridgefyDidDisconnect',
88
+ async start(
89
+ userId?: string,
90
+ propagationProfile: BridgefyPropagationProfile = BridgefyPropagationProfile.REALTIME
91
+ ): Promise<void> {
92
+ return BridgefyReactNative.start(userId, propagationProfile);
93
+ }
94
+
164
95
  /**
165
- * This function is called to notify when an on-demand secure connection was established.
96
+ * Stop the Bridgefy SDK
166
97
  */
167
- bridgefyDidEstablishSecureConnection = 'bridgefyDidEstablishSecureConnection',
98
+ async stop(): Promise<void> {
99
+ return BridgefyReactNative.stop();
100
+ }
101
+
168
102
  /**
169
- * This function is called to notify when an on-demand secure connection could not be established.
103
+ * Destroy the current session
170
104
  */
171
- bridgefyDidFailToEstablishSecureConnection = 'bridgefyDidFailToEstablishSecureConnection',
105
+ async destroySession(): Promise<void> {
106
+ return BridgefyReactNative.destroySession();
107
+ }
108
+
172
109
  /**
173
- * This function is called when you confirm the sending of the message
110
+ * Send data through the mesh network
174
111
  */
175
- bridgefyDidSendMessage = 'bridgefyDidSendMessage',
112
+ async send(
113
+ data: string,
114
+ transmissionMode: BridgefyTransmissionMode
115
+ ): Promise<string> {
116
+ return BridgefyReactNative.send(data, transmissionMode);
117
+ }
118
+
176
119
  /**
177
- * This function is called when the message could not be sent
120
+ * Send broadcast message (convenience method)
178
121
  */
179
- bridgefyDidFailSendingMessage = 'bridgefyDidFailSendingMessage',
122
+ async sendBroadcast(data: string): Promise<string> {
123
+ const userId = await this.currentUserId();
124
+ return this.send(data, {
125
+ type: BridgefyTransmissionModeType.BROADCAST,
126
+ uuid: userId,
127
+ });
128
+ }
129
+
180
130
  /**
181
- * This function is called when a new message is received
131
+ * Send P2P message (convenience method)
182
132
  */
183
- bridgefyDidReceiveData = 'bridgefyDidReceiveData',
133
+ async sendP2P(data: string, recipientId: string): Promise<string> {
134
+ return this.send(data, {
135
+ type: BridgefyTransmissionModeType.P2P,
136
+ uuid: recipientId,
137
+ });
138
+ }
139
+
184
140
  /**
185
- * (Android) Called when there is progress while transmitting data.
141
+ * Send mesh message (convenience method)
186
142
  */
187
- bridgefyDidSendDataProgress = 'bridgefyDidSendDataProgress',
188
- }
143
+ async sendMesh(data: string, recipientId: string): Promise<string> {
144
+ return this.send(data, {
145
+ type: BridgefyTransmissionModeType.MESH,
146
+ uuid: recipientId,
147
+ });
148
+ }
189
149
 
190
- /**
191
- * Bridgefy
192
- */
193
- export class Bridgefy implements BridgefyService {
194
150
  /**
195
- * Initialize the SDK
196
- * @param apiKey API key
197
- * @param verboseLogging The log level.
151
+ * Establish secure connection with a peer
198
152
  */
199
- async initialize({
200
- apiKey,
201
- verboseLogging = false,
202
- }: IInitializeIn): Promise<void> {
203
- await BridgefyReactNative.initialize(apiKey, verboseLogging);
153
+ async establishSecureConnection(userId: string): Promise<void> {
154
+ return BridgefyReactNative.establishSecureConnection(userId);
204
155
  }
205
156
 
206
157
  /**
207
- * Start Bridgefy SDK operations
158
+ * Get current user ID
208
159
  */
209
- async start(params?: IStartIn): Promise<void> {
210
- const userId = params?.userId ?? null;
211
- const propagationProfile =
212
- params?.propagationProfile ?? BridgefyPropagationProfile.standard;
213
- return await BridgefyReactNative.start(userId, propagationProfile);
160
+ async currentUserId(): Promise<string> {
161
+ return BridgefyReactNative.currentUserId();
214
162
  }
215
163
 
216
164
  /**
217
- * Stop Bridgefy SDK operations
165
+ * Get list of connected peers
218
166
  */
219
- async stop(): Promise<void> {
220
- return await BridgefyReactNative.stop();
167
+ async connectedPeers(): Promise<string[]> {
168
+ return BridgefyReactNative.connectedPeers();
221
169
  }
222
170
 
223
171
  /**
224
- * Destroy current session
172
+ * Get license expiration info
225
173
  */
226
- async destroySession(): Promise<void> {
227
- return BridgefyReactNative.destroySession();
174
+ async licenseExpirationDate(): Promise<BridgefyLicenseInfo> {
175
+ return BridgefyReactNative.licenseExpirationDate();
228
176
  }
229
177
 
230
178
  /**
@@ -235,60 +183,170 @@ export class Bridgefy implements BridgefyService {
235
183
  }
236
184
 
237
185
  /**
238
- * Function used to send data using a ``TransmissionMode``. This method returns a UUID to identify
239
- * the message sent.
240
- * @param data The message data
241
- * @param transmissionMode The mode used to propagate a message through nearby devices.
242
- * @returns The id of the message that was sent.
186
+ * Check if SDK is initialized
243
187
  */
244
- async send(
245
- data: string,
246
- transmissionMode: BridgefyTransmissionMode
247
- ): Promise<string> {
248
- const result = await BridgefyReactNative.send(data, transmissionMode);
249
- return result.messageId;
188
+ async isInitialized(): Promise<boolean> {
189
+ return BridgefyReactNative.isInitialized();
250
190
  }
251
191
 
252
192
  /**
253
- * Establishes a secure connection with the specified user
254
- * @param userId The UUID of the user with whom a secure connection should be established.
193
+ * Check if SDK is started
255
194
  */
256
- async establishSecureConnection(userId: string): Promise<void> {
257
- return BridgefyReactNative.establishSecureConnection(userId);
195
+ async isStarted(): Promise<boolean> {
196
+ return BridgefyReactNative.isStarted();
197
+ }
198
+
199
+ async setOperationMode(
200
+ config: BridgefyOperationModeConfig
201
+ ): Promise<BridgefyOperationModeConfig> {
202
+ return BridgefyReactNative.setOperationMode(config);
203
+ }
204
+ async getOperationMode(): Promise<BridgefyOperationModeConfig> {
205
+ return BridgefyReactNative.getOperationMode();
206
+ }
207
+ async switchToBackground(): Promise<void> {
208
+ return BridgefyReactNative.switchToBackground();
209
+ }
210
+ async switchToForeground(): Promise<void> {
211
+ return BridgefyReactNative.switchToForeground();
212
+ }
213
+ async getOperationStatus(): Promise<BridgefyOperationModeStatus> {
214
+ return BridgefyReactNative.getOperationStatus();
258
215
  }
259
216
 
260
217
  /**
261
- * Get current user Id
262
- * @returns User Id
218
+ * Add event listener
263
219
  */
264
- async currentUserId(): Promise<string> {
265
- const result = await BridgefyReactNative.currentUserId();
266
- return result.userId;
220
+ addEventListener(
221
+ eventName: BridgefyEvents,
222
+ listener: (event: any) => void
223
+ ): { remove: () => void } {
224
+ const subscription = this.eventEmitter.addListener(eventName, listener);
225
+ return {
226
+ remove: () => subscription.remove(),
227
+ };
267
228
  }
268
229
 
269
230
  /**
270
- * Returns connected peers
271
- * @returns List of connected peers
231
+ * Remove all listeners for an event
272
232
  */
273
- async connectedPeers(): Promise<string[]> {
274
- const result = await BridgefyReactNative.connectedPeers();
275
- return result.connectedPeers;
233
+ removeAllListeners(eventName?: BridgefyEvents): void {
234
+ if (eventName) {
235
+ this.eventEmitter.removeAllListeners(eventName);
236
+ } else {
237
+ // Remove all listeners for all events
238
+ Object.values(BridgefyEvents).forEach((event) => {
239
+ this.eventEmitter.removeAllListeners(event);
240
+ });
241
+ }
276
242
  }
277
243
 
278
244
  /**
279
- * Returns license expiration date
280
- * @returns Expiration date
245
+ * Event listener helpers for common events
281
246
  */
282
- async licenseExpirationDate(): Promise<Date> {
283
- const result = await BridgefyReactNative.licenseExpirationDate();
284
- return new Date(result.licenseExpirationDate as number);
247
+
248
+ onStart(listener: (event: BridgefyStartEvent) => void) {
249
+ return this.addEventListener(BridgefyEvents.BRIDGEFY_DID_START, listener);
285
250
  }
286
251
 
287
- async isInitialized(): Promise<boolean> {
288
- return await BridgefyReactNative.isInitialized();
252
+ onStop(listener: () => void) {
253
+ return this.addEventListener(BridgefyEvents.BRIDGEFY_DID_STOP, listener);
289
254
  }
290
255
 
291
- async isStarted(): Promise<boolean> {
292
- return BridgefyReactNative.isStarted();
256
+ onFailToStart(listener: (error: BridgefyError) => void) {
257
+ return this.addEventListener(
258
+ BridgefyEvents.BRIDGEFY_DID_FAIL_TO_START,
259
+ listener
260
+ );
261
+ }
262
+
263
+ onFailToStop(listener: (error: BridgefyError) => void) {
264
+ return this.addEventListener(
265
+ BridgefyEvents.BRIDGEFY_DID_FAIL_TO_STOP,
266
+ listener
267
+ );
268
+ }
269
+
270
+ onConnect(listener: (event: BridgefyConnectEvent) => void) {
271
+ return this.addEventListener(BridgefyEvents.BRIDGEFY_DID_CONNECT, listener);
272
+ }
273
+
274
+ onConnectedPeers(listener: (event: BridgefyUpdatedConnectedEvent) => void) {
275
+ return this.addEventListener(
276
+ BridgefyEvents.BRIDGEFY_DID_UPDATE_CONNECTED_PEERS,
277
+ listener
278
+ );
279
+ }
280
+
281
+ onDisconnect(listener: (event: BridgefyDisconnectEvent) => void) {
282
+ return this.addEventListener(
283
+ BridgefyEvents.BRIDGEFY_DID_DISCONNECT,
284
+ listener
285
+ );
286
+ }
287
+
288
+ onSendMessage(listener: (event: BridgefySendMessageEvent) => void) {
289
+ return this.addEventListener(
290
+ BridgefyEvents.BRIDGEFY_DID_SEND_MESSAGE,
291
+ listener
292
+ );
293
+ }
294
+
295
+ onSendDataProgress(listener: (event: BridgefyDidSendDataProgress) => void) {
296
+ return this.addEventListener(
297
+ BridgefyEvents.BRIDGEFY_DID_SEND_DATA_PROGRESS,
298
+ listener
299
+ );
300
+ }
301
+
302
+ onFailSendingMessage(
303
+ listener: (error: BridgefyError & { messageId: string }) => void
304
+ ) {
305
+ return this.addEventListener(
306
+ BridgefyEvents.BRIDGEFY_DID_FAIL_SENDING_MESSAGE,
307
+ listener
308
+ );
309
+ }
310
+
311
+ onReceiveData(listener: (event: BridgefyReceiveDataEvent) => void) {
312
+ return this.addEventListener(
313
+ BridgefyEvents.BRIDGEFY_DID_RECEIVE_DATA,
314
+ listener
315
+ );
316
+ }
317
+
318
+ onEstablishSecureConnection(
319
+ listener: (event: BridgefySecureConnectionEvent) => void
320
+ ) {
321
+ return this.addEventListener(
322
+ BridgefyEvents.BRIDGEFY_DID_ESTABLISH_SECURE_CONNECTION,
323
+ listener
324
+ );
325
+ }
326
+
327
+ onFailToEstablishSecureConnection(
328
+ listener: (error: BridgefyError & { userId: string }) => void
329
+ ) {
330
+ return this.addEventListener(
331
+ BridgefyEvents.BRIDGEFY_DID_FAIL_TO_ESTABLISH_SECURE_CONNECTION,
332
+ listener
333
+ );
334
+ }
335
+
336
+ onUpdateLicense(listener: () => void) {
337
+ return this.addEventListener(
338
+ BridgefyEvents.BRIDGEFY_DID_UPDATE_LICENSE,
339
+ listener
340
+ );
341
+ }
342
+
343
+ onFailToUpdateLicense(listener: (error: BridgefyError) => void) {
344
+ return this.addEventListener(
345
+ BridgefyEvents.BRIDGEFY_DID_FAIL_TO_UPDATE_LICENSE,
346
+ listener
347
+ );
293
348
  }
294
349
  }
350
+
351
+ // Export default instance for convenience
352
+ export default new Bridgefy();
@@ -1,56 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTEventEmitter.h>
3
-
4
- @interface RCT_EXTERN_MODULE(BridgefyReactNative, RCTEventEmitter)
5
-
6
- RCT_EXTERN_METHOD(initialize:(NSString *)apiKey
7
- verboseLogging:(BOOL)verboseLogging
8
- resolve:(RCTPromiseResolveBlock)resolve
9
- reject:(RCTPromiseRejectBlock)reject)
10
-
11
- RCT_EXTERN_METHOD(start:(NSString *)userId
12
- propagationProfile:(NSString *)propagationProfile
13
- resolve:(RCTPromiseResolveBlock)resolve
14
- reject:(RCTPromiseRejectBlock)reject)
15
-
16
- RCT_EXTERN_METHOD(send:(NSString *)data
17
- transmissionMode:(NSDictionary *)transmissionMode
18
- resolve:(RCTPromiseResolveBlock)resolve
19
- reject:(RCTPromiseRejectBlock)reject)
20
-
21
- RCT_EXTERN_METHOD(stop:(RCTPromiseResolveBlock)resolve
22
- reject:(RCTPromiseRejectBlock)reject)
23
-
24
- RCT_EXTERN_METHOD(connectedPeers:(RCTPromiseResolveBlock)resolve
25
- reject:(RCTPromiseRejectBlock)reject)
26
-
27
- RCT_EXTERN_METHOD(currentUserId:(RCTPromiseResolveBlock)resolve
28
- reject:(RCTPromiseRejectBlock)reject)
29
-
30
- RCT_EXTERN_METHOD(establishSecureConnection:(NSString *)userId
31
- resolve:(RCTPromiseResolveBlock)resolve
32
- reject:(RCTPromiseRejectBlock)reject)
33
-
34
- RCT_EXTERN_METHOD(licenseExpirationDate:(RCTPromiseResolveBlock)resolve
35
- reject:(RCTPromiseRejectBlock)reject)
36
-
37
- RCT_EXTERN_METHOD(destroySession:(RCTPromiseResolveBlock)resolve
38
- reject:(RCTPromiseRejectBlock)reject)
39
-
40
- RCT_EXTERN_METHOD(updateLicense:(RCTPromiseResolveBlock)resolve
41
- reject:(RCTPromiseRejectBlock)reject)
42
-
43
- RCT_EXTERN_METHOD(isInitialized:(RCTPromiseResolveBlock)resolve
44
- reject:(RCTPromiseRejectBlock)reject)
45
-
46
- RCT_EXTERN_METHOD(isStarted:(RCTPromiseResolveBlock)resolve
47
- reject:(RCTPromiseRejectBlock)reject)
48
-
49
- RCT_EXTERN_METHOD(supportedEvents)
50
-
51
- + (BOOL)requiresMainQueueSetup
52
- {
53
- return NO;
54
- }
55
-
56
- @end