bridgefy-react-native 1.0.1

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 (49) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +145 -0
  3. package/android/build.gradle +105 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +10 -0
  6. package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativeModule.kt +323 -0
  7. package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativePackage.kt +17 -0
  8. package/bridgefy-react-native.podspec +42 -0
  9. package/ios/BridgefyReactNative-Bridging-Header.h +2 -0
  10. package/ios/BridgefyReactNative.m +42 -0
  11. package/ios/BridgefyReactNative.swift +327 -0
  12. package/ios/BridgefyReactNative.xcodeproj/project.pbxproj +293 -0
  13. package/ios/Frameworks/BridgefySDK.xcframework/Info.plist +44 -0
  14. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/BridgefySDK +0 -0
  15. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +296 -0
  16. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK.h +15 -0
  17. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Info.plist +0 -0
  18. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.abi.json +8744 -0
  19. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.private.swiftinterface +101 -0
  20. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  21. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftinterface +101 -0
  22. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/module.modulemap +11 -0
  23. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/_CodeSignature/CodeResources +190 -0
  24. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +20 -0
  25. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
  26. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/BridgefySDK +0 -0
  27. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +588 -0
  28. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK.h +15 -0
  29. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Info.plist +0 -0
  30. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.abi.json +8744 -0
  31. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +101 -0
  32. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  33. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +101 -0
  34. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +8744 -0
  35. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +101 -0
  36. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  37. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +101 -0
  38. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/module.modulemap +11 -0
  39. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/_CodeSignature/CodeResources +245 -0
  40. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +20 -0
  41. package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
  42. package/lib/commonjs/index.js +184 -0
  43. package/lib/commonjs/index.js.map +1 -0
  44. package/lib/module/index.js +176 -0
  45. package/lib/module/index.js.map +1 -0
  46. package/lib/typescript/index.d.ts +214 -0
  47. package/lib/typescript/index.d.ts.map +1 -0
  48. package/package.json +162 -0
  49. package/src/index.tsx +273 -0
package/src/index.tsx ADDED
@@ -0,0 +1,273 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'bridgefy-react-native' 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
+ const BridgefyReactNative = NativeModules.BridgefyReactNative
10
+ ? NativeModules.BridgefyReactNative
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ },
17
+ }
18
+ );
19
+
20
+ /** Profile that defines a series of properties and rules for the propagation of messages. */
21
+ export enum BridgefyPropagationProfile {
22
+ standard = 'standard',
23
+ highDensityNetwork = 'highDensityNetwork',
24
+ sparseNetwork = 'sparseNetwork',
25
+ longReach = 'longReach',
26
+ shortReach = 'shortReach',
27
+ }
28
+
29
+ /** The mode used to propagate a message through nearby devices. */
30
+ export enum BridgefyTransmissionModeType {
31
+ /** Deliver a message to a specific recipient only if there's an active connection with it. */
32
+ p2p = 'p2p',
33
+ /** Deliver a message to a specific recipient using nearby devices to propagate it. */
34
+ mesh = 'mesh',
35
+ /** Propagate a message readable by every device that receives it. */
36
+ broadcast = 'broadcast',
37
+ }
38
+
39
+ export interface BridgefyTransmissionMode {
40
+ type: BridgefyTransmissionModeType;
41
+ uuid: string;
42
+ }
43
+
44
+ /** Describes errors in the Bridgefy error domain. */
45
+ export enum BridgefyErrorType {
46
+ /** The Bridgefy SDK cannot run in the simulator */
47
+ simulatorIsNotSupported = 'simulatorIsNotSupported',
48
+ /** The Bridgefy SDK is already running */
49
+ alreadyStarted = 'alreadyStarted',
50
+ /** The provided API key is not valid */
51
+ invalidAPIKey = 'invalidAPIKey',
52
+ /** The license is expired */
53
+ expiredLicense = 'expiredLicense',
54
+ /** An error occurred while creating the session */
55
+ sessionError = 'sessionError',
56
+ /** (iOS) The Bridgefy SDK hasn't been started */
57
+ notStarted = 'notStarted',
58
+ /** (iOS) A Bridgefy SDK instance already exists */
59
+ alreadyInstantiated = 'alreadyInstantiated',
60
+ /** (iOS) The Bridgefy SDK is performing the start process */
61
+ startInProgress = 'startInProgress',
62
+ /** (iOS) The Bridgefy SDK service is not started */
63
+ serviceNotStarted = 'serviceNotStarted',
64
+ /** (iOS) Cannot get app's bundle id */
65
+ missingBundleID = 'missingBundleID',
66
+ /** (iOS) An internet connection is required to validate the license */
67
+ internetConnectionRequired = 'internetConnectionRequired',
68
+ /** (iOS) The device's time has been modified */
69
+ inconsistentDeviceTime = 'inconsistentDeviceTime',
70
+ /** (iOS) The user does not allow the use of BLE */
71
+ BLEUsageNotGranted = 'BLEUsageNotGranted',
72
+ /** (iOS) The use of BLE in this device is restricted */
73
+ BLEUsageRestricted = 'BLEUsageRestricted',
74
+ /** (iOS) The BLE antenna has been turned off */
75
+ BLEPoweredOff = 'BLEPoweredOff',
76
+ /** (iOS) The usage of BLE is not supported in the device */
77
+ BLEUnsupported = 'BLEUnsupported',
78
+ /** (iOS) BLE usage failed with an unknown error */
79
+ BLEUnknownError = 'BLEUnknownError',
80
+ /** (iOS) Inconsistent connection */
81
+ inconsistentConnection = 'inconsistentConnection',
82
+ /** (iOS) Connection is already secure */
83
+ connectionIsAlreadySecure = 'connectionIsAlreadySecure',
84
+ /** (iOS) Cannot create secure connection */
85
+ cannotCreateSecureConnection = 'cannotCreateSecureConnection',
86
+ /** (iOS) The length of the data exceed the maximum limit */
87
+ dataLengthExceeded = 'dataLengthExceeded',
88
+ /** (iOS) The data to send is empty */
89
+ dataValueIsEmpty = 'dataValueIsEmpty',
90
+ /** (iOS) The requested peer is not connected */
91
+ peerIsNotConnected = 'peerIsNotConnected',
92
+ /** (iOS) An internal error occurred */
93
+ internalError = 'internalError',
94
+ /** (iOS) An error occurred while validating the license */
95
+ licenseError = 'licenseError',
96
+ /** (iOS) An error occurred while storing data */
97
+ storageError = 'storageError',
98
+ /** (iOS) An error occurred while encoding the message */
99
+ encodingError = 'encodingError',
100
+ /** (iOS) An error occurred while encrypting the message */
101
+ encryptionError = 'encryptionError',
102
+ /** (Android) Missing application ID */
103
+ missingApplicationId = 'missingApplicationId',
104
+ /** (Android) Permission exception */
105
+ permissionException = 'permissionException',
106
+ /** (Android) Registration exception */
107
+ registrationException = 'registrationException',
108
+ /** (Android) Size limit exceeded */
109
+ sizeLimitExceeded = 'sizeLimitExceeded',
110
+ /** (Android) Device capabilities error */
111
+ deviceCapabilities = 'deviceCapabilities',
112
+ /** (Android) Generic exception */
113
+ genericException = 'genericException',
114
+ /** (Android) Inconsistent device time */
115
+ inconsistentDeviceTimeException = 'inconsistentDeviceTimeException',
116
+ /** (Android) Internet connection required */
117
+ internetConnectionRequiredException = 'internetConnectionRequiredException',
118
+ /** (Android) Unknown exception */
119
+ unknownException = 'unknownException',
120
+ }
121
+
122
+ /**
123
+ * These events are available via subscriptions to the `NativeEventEmitter` using the
124
+ * `NativeModules.BridgefyReactNative` component. See README for further instructions.
125
+ */
126
+ export enum BridgefyEvents {
127
+ /**
128
+ * This function is called when the BridgefySDK has been started.
129
+ */
130
+ bridgefyDidStart = 'bridgefyDidStart',
131
+ /**
132
+ * This function is called when an error occurred while starting the BridgefySDK.
133
+ */
134
+ bridgefyDidFailToStart = 'bridgefyDidFailToStart',
135
+ /**
136
+ * This function is called when the BridgefySDK has been stopped.
137
+ */
138
+ bridgefyDidStop = 'bridgefyDidStop',
139
+ /**
140
+ * This function is called when an error occurred while stopping the BridgefySDK.
141
+ */
142
+ bridgefyDidFailToStop = 'bridgefyDidFailToStop',
143
+ /**
144
+ * The current session was destroyed
145
+ */
146
+ bridgefyDidDestroySession = 'bridgefyDidDestroySession',
147
+ /**
148
+ * An error occurred while destroying the current session
149
+ */
150
+ bridgefyDidFailToDestroySession = 'bridgefyDidFailToDestroySession',
151
+ /**
152
+ * This function is called to notify a new connection.
153
+ */
154
+ bridgefyDidConnect = 'bridgefyDidConnect',
155
+ /**
156
+ * This function is called to notify a disconnection.
157
+ */
158
+ bridgefyDidDisconnect = 'bridgefyDidDisconnect',
159
+ /**
160
+ * This function is called to notify when an on-demand secure connection was established.
161
+ */
162
+ bridgefyDidEstablishSecureConnection = 'bridgefyDidEstablishSecureConnection',
163
+ /**
164
+ * This function is called to notify when an on-demand secure connection could not be established.
165
+ */
166
+ bridgefyDidFailToEstablishSecureConnection = 'bridgefyDidFailToEstablishSecureConnection',
167
+ /**
168
+ * This function is called when you confirm the sending of the message
169
+ */
170
+ bridgefyDidSendMessage = 'bridgefyDidSendMessage',
171
+ /**
172
+ * This function is called when the message could not be sent
173
+ */
174
+ bridgefyDidFailSendingMessage = 'bridgefyDidFailSendingMessage',
175
+ /**
176
+ * This function is called when a new message is received
177
+ */
178
+ bridgefyDidReceiveData = 'bridgefyDidReceiveData',
179
+ /**
180
+ * (Android) Called when there is progress while transmitting data.
181
+ */
182
+ bridgefyDidSendDataProgress = 'bridgefyDidSendDataProgress',
183
+ }
184
+
185
+ /**
186
+ * Bridgefy
187
+ */
188
+ export class Bridgefy {
189
+ /**
190
+ * Initialize the SDK
191
+ * @param apiKey API key
192
+ * @param propagationProfile Profile that defines a series of properties and rules for the
193
+ * propagation of messages.
194
+ * @param verboseLogging The log level.
195
+ */
196
+ async initialize(
197
+ apiKey: string,
198
+ propagationProfile: BridgefyPropagationProfile
199
+ ): Promise<void> {
200
+ return BridgefyReactNative.initialize(apiKey, propagationProfile);
201
+ }
202
+
203
+ /**
204
+ * Start Bridgefy SDK operations
205
+ */
206
+ async start(): Promise<void> {
207
+ return BridgefyReactNative.start();
208
+ }
209
+
210
+ /**
211
+ * Stop Bridgefy SDK operations
212
+ */
213
+ async stop(): Promise<void> {
214
+ return BridgefyReactNative.stop();
215
+ }
216
+
217
+ /**
218
+ * Destroy current session
219
+ */
220
+ async destroySession(): Promise<void> {
221
+ return BridgefyReactNative.destroySession();
222
+ }
223
+
224
+ /**
225
+ * Function used to send data using a ``TransmissionMode``. This method returns a UUID to identify
226
+ * the message sent.
227
+ * @param data The message data
228
+ * @param transmissionMode The mode used to propagate a message through nearby devices.
229
+ * @returns The id of the message that was sent.
230
+ */
231
+ async send(
232
+ data: string,
233
+ transmissionMode: BridgefyTransmissionMode
234
+ ): Promise<string> {
235
+ const result = await BridgefyReactNative.send(data, transmissionMode);
236
+ return result.messageId;
237
+ }
238
+
239
+ /**
240
+ * Establishes a secure connection with the specified user
241
+ * @param userId The UUID of the user with whom a secure connection should be established.
242
+ */
243
+ async establishSecureConnection(userId: string): Promise<void> {
244
+ return BridgefyReactNative.establishSecureConnection(userId);
245
+ }
246
+
247
+ /**
248
+ * Get current user Id
249
+ * @returns User Id
250
+ */
251
+ async currentUserId(): Promise<string> {
252
+ const result = BridgefyReactNative.currentUserId();
253
+ return result.userId;
254
+ }
255
+
256
+ /**
257
+ * Returns connected peers
258
+ * @returns List of connected peers
259
+ */
260
+ async connectedPeers(): Promise<string[]> {
261
+ const result = BridgefyReactNative.connectedPeers();
262
+ return result.connectedPeers;
263
+ }
264
+
265
+ /**
266
+ * Returns license expiration date
267
+ * @returns Expiration date
268
+ */
269
+ async licenseExpirationDate(): Promise<Date> {
270
+ const result = BridgefyReactNative.licenseExpirationDate();
271
+ return new Date(result.licenseExpirationDate);
272
+ }
273
+ }