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.
- package/LICENSE +20 -0
- package/README.md +145 -0
- package/android/build.gradle +105 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +10 -0
- package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativeModule.kt +323 -0
- package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativePackage.kt +17 -0
- package/bridgefy-react-native.podspec +42 -0
- package/ios/BridgefyReactNative-Bridging-Header.h +2 -0
- package/ios/BridgefyReactNative.m +42 -0
- package/ios/BridgefyReactNative.swift +327 -0
- package/ios/BridgefyReactNative.xcodeproj/project.pbxproj +293 -0
- package/ios/Frameworks/BridgefySDK.xcframework/Info.plist +44 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/BridgefySDK +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +296 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK.h +15 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Info.plist +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.abi.json +8744 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.private.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/module.modulemap +11 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/_CodeSignature/CodeResources +190 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +20 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/BridgefySDK +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK-Swift.h +588 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK.h +15 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Info.plist +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.abi.json +8744 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +8744 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +101 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/module.modulemap +11 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/_CodeSignature/CodeResources +245 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +20 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
- package/lib/commonjs/index.js +184 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +176 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +214 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +162 -0
- package/src/index.tsx +273 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Bridgefy Inc
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://www.gitbook.com/cdn-cgi/image/width=256,dpr=2,height=40,fit=contain,format=auto/https%3A%2F%2F3290834949-files.gitbook.io%2F~%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F5XKIMMP6VF2l9XuPV80l%252Flogo%252Fd78nQFIysoU2bbM5fYNP%252FGroup%25203367.png%3Falt%3Dmedia%26token%3Df83a642d-8a9a-411f-9ef4-d7189a4c5f0a" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://3290834949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5XKIMMP6VF2l9XuPV80l%2Fuploads%2FD0HSf0lWC4pWB4U7inIw%2Fharegit.jpg?alt=media&token=a400cf7d-3254-4afc-bed0-48f7d98205b0"/>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
# Bridgefy React Native SDK
|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
The Bridgefy Software Development Kit (SDK) is a state-of-the-art, plug-and-play package that will let people use your mobile app when they don’t have access to the Internet, by using Bluetooth mesh networks.
|
|
16
|
+
|
|
17
|
+
Integrate the Bridgefy SDK into your Android and iOS app to reach the 3.5 billion people that don’t always have access to an Internet connection, and watch engagement and revenue grow!
|
|
18
|
+
|
|
19
|
+
**Website**. https://bridgefy.me/sdk <br>
|
|
20
|
+
**Email**. contact@bridgefy.me <br>
|
|
21
|
+
**witter**. https://twitter.com/bridgefy <br>
|
|
22
|
+
**Facebook**. https://www.facebook.com/bridgefy <br>
|
|
23
|
+
|
|
24
|
+
## Operation mode
|
|
25
|
+
|
|
26
|
+
All the connections are handled seamlessly by the SDK to create a mesh network. The size of this
|
|
27
|
+
network depends on the number of devices connected and the environment as a variable factor,
|
|
28
|
+
allowing you to join nodes in the same network or nodes in different networks.
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
## Platform permissions
|
|
33
|
+
|
|
34
|
+
To utilize this SDK in a React Native application, you'll need to configure permissions for each
|
|
35
|
+
individual platform (iOS and Android) first. You can read more about each platform's requirements
|
|
36
|
+
below:
|
|
37
|
+
|
|
38
|
+
* [iOS Permissions](https://github.com/bridgefy/sdk-ios#permissions)
|
|
39
|
+
* [Android Permissions](https://github.com/bridgefy/sdk-android#android-permissions)
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
Since this SDK is still in beta, you'll need to add a reference to this repository in your
|
|
44
|
+
`package.json` file:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
npm i git+https://github.com/bridgefy/bridgefy-react-native.git
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Initialization
|
|
53
|
+
|
|
54
|
+
The `initialize` method initializes the Bridgefy SDK with the given API key and propagation profile.
|
|
55
|
+
We will configure event listeners later.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Bridgefy, BridgefyPropagationProfile } from 'bridgefy-react-native';
|
|
59
|
+
|
|
60
|
+
const bridgefy = new Bridgefy();
|
|
61
|
+
|
|
62
|
+
export default function App() {
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
bridgefy
|
|
65
|
+
.initialize('api-key', BridgefyPropagationProfile.standard)
|
|
66
|
+
.catch((error) => {
|
|
67
|
+
console.error(error);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Once initialized, you can call `start` to begin using the SDK.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
bridgefy.start();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Sending data
|
|
79
|
+
|
|
80
|
+
The following method is used to send data using a transmission mode. This method returns a UUID to
|
|
81
|
+
identify the message that was sent. You'll need to serialize your data into a `string` before
|
|
82
|
+
transmission so React Native can communicate the information to the native platform.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
async function sendData() {
|
|
86
|
+
const userId = await bridgefy.currentUserId();
|
|
87
|
+
const lastMessageId = await bridgefy.send(
|
|
88
|
+
'data', // String encoded data to send.
|
|
89
|
+
{
|
|
90
|
+
type: BridgefyTransmissionModeType.broadcast,
|
|
91
|
+
uuid: userId,
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Responding to SDK events
|
|
98
|
+
|
|
99
|
+
The SDK can report events to your app through an instance of React's `NativeEventEmitter`.
|
|
100
|
+
|
|
101
|
+
The following is an example subscription to a couple of events. Each message will contain
|
|
102
|
+
information relevant to the event being transmitted.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
const subscriptions: EmitterSubscription[] = [];
|
|
107
|
+
const eventEmitter = new NativeEventEmitter(
|
|
108
|
+
NativeModules.BridgefyReactNative
|
|
109
|
+
);
|
|
110
|
+
// When the Bridgefy SDK started successfully.
|
|
111
|
+
subscriptions.push(
|
|
112
|
+
eventEmitter.addListener(BridgefyEvents.bridgefyDidStart, (event) => {
|
|
113
|
+
console.log(`Bridgefy started`, event);
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
// When this device received data from another Bridgefy device.
|
|
117
|
+
subscriptions.push(
|
|
118
|
+
eventEmitter.addListener(
|
|
119
|
+
BridgefyEvents.bridgefyDidReceiveData,
|
|
120
|
+
(event) => {
|
|
121
|
+
console.log(`Bridgefy received data`, event);
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
return () => {
|
|
126
|
+
for (const sub of subscriptions) {
|
|
127
|
+
sub.remove();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
To see a full list of events, see the `BridgefyEvents` enum.
|
|
134
|
+
|
|
135
|
+
## Multi-Platform Support
|
|
136
|
+
|
|
137
|
+
Bridgefy's SDKs are designed to work seamlessly across different platforms, including iOS and Android. This means that users with different devices can communicate with each other as long as they have the Bridgefy-enabled applications installed.
|
|
138
|
+
|
|
139
|
+
* [Bridgefy iOS](https://github.com/bridgefy/sdk-ios)
|
|
140
|
+
* [Bridgefy Android](https://github.com/bridgefy/sdk-android)
|
|
141
|
+
|
|
142
|
+
## Contact & Support
|
|
143
|
+
+ contact@bridgefy.me
|
|
144
|
+
|
|
145
|
+
© 2023 Bridgefy Inc. All rights reserved
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["BridgefyReactNative_kotlinVersion"]
|
|
4
|
+
|
|
5
|
+
repositories {
|
|
6
|
+
google()
|
|
7
|
+
mavenCentral()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
dependencies {
|
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
rootProject.allprojects {
|
|
18
|
+
repositories {
|
|
19
|
+
maven {
|
|
20
|
+
url "http://34.82.5.94:8081/artifactory/libs-release-local"
|
|
21
|
+
allowInsecureProtocol = true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
allprojects {
|
|
27
|
+
repositories {
|
|
28
|
+
google()
|
|
29
|
+
mavenCentral()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def isNewArchitectureEnabled() {
|
|
34
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
apply plugin: "com.android.library"
|
|
38
|
+
apply plugin: "kotlin-android"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
42
|
+
|
|
43
|
+
if (isNewArchitectureEnabled()) {
|
|
44
|
+
apply plugin: "com.facebook.react"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def getExtOrDefault(name) {
|
|
48
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["BridgefyReactNative_" + name]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
def getExtOrIntegerDefault(name) {
|
|
52
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["BridgefyReactNative_" + name]).toInteger()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
android {
|
|
56
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
57
|
+
|
|
58
|
+
defaultConfig {
|
|
59
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
60
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
61
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
62
|
+
}
|
|
63
|
+
buildTypes {
|
|
64
|
+
release {
|
|
65
|
+
minifyEnabled false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
lintOptions {
|
|
70
|
+
disable "GradleCompatible"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
compileOptions {
|
|
74
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
75
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
repositories {
|
|
81
|
+
mavenCentral()
|
|
82
|
+
google()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
86
|
+
|
|
87
|
+
dependencies {
|
|
88
|
+
implementation (group: "me.bridgefy", name: "android-sdk", version: "1.0.1", ext: "aar") {
|
|
89
|
+
transitive = true
|
|
90
|
+
}
|
|
91
|
+
// For < 0.71, this will be from the local maven repo
|
|
92
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
93
|
+
//noinspection GradleDynamicVersion
|
|
94
|
+
implementation "com.facebook.react:react-native:+"
|
|
95
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
96
|
+
implementation "androidx.preference:preference-ktx:1.2.0"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (isNewArchitectureEnabled()) {
|
|
100
|
+
react {
|
|
101
|
+
jsRootDir = file("../src/")
|
|
102
|
+
libraryName = "BridgefyReactNative"
|
|
103
|
+
codegenJavaPackageName = "me.bridgefy.plugin.react_native"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
xmlns:tools="http://schemas.android.com/tools"
|
|
3
|
+
package="me.bridgefy.plugin.react_native">
|
|
4
|
+
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" tools:node="replace" />
|
|
5
|
+
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="33" tools:node="replace" />
|
|
6
|
+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="30" />
|
|
7
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:node="replace" />
|
|
8
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
9
|
+
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
|
10
|
+
</manifest>
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
package me.bridgefy.plugin.react_native
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.Promise
|
|
8
|
+
import com.facebook.react.bridge.ReactContext
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap
|
|
10
|
+
import com.facebook.react.bridge.WritableMap
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
12
|
+
import me.bridgefy.Bridgefy
|
|
13
|
+
import me.bridgefy.commons.TransmissionMode
|
|
14
|
+
import me.bridgefy.commons.exception.BridgefyException
|
|
15
|
+
import me.bridgefy.commons.listener.BridgefyDelegate
|
|
16
|
+
import me.bridgefy.commons.propagation.PropagationProfile
|
|
17
|
+
import java.util.UUID
|
|
18
|
+
|
|
19
|
+
class BridgefyReactNativeModule(reactContext: ReactApplicationContext) :
|
|
20
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
21
|
+
|
|
22
|
+
private var bridgefy: Bridgefy
|
|
23
|
+
|
|
24
|
+
init {
|
|
25
|
+
bridgefy = Bridgefy(reactContext)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun getName(): String {
|
|
29
|
+
return NAME
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ReactMethod
|
|
33
|
+
fun initialize(apiKey: String,
|
|
34
|
+
propagationProfile: String,
|
|
35
|
+
promise: Promise) {
|
|
36
|
+
val profile = propagationProfileFromString(propagationProfile)
|
|
37
|
+
try {
|
|
38
|
+
bridgefy.init(
|
|
39
|
+
null,
|
|
40
|
+
UUID.fromString(apiKey),
|
|
41
|
+
profile!!,
|
|
42
|
+
object : BridgefyDelegate {
|
|
43
|
+
override fun onConnected(peerID: UUID) {
|
|
44
|
+
val params = Arguments.createMap().apply {
|
|
45
|
+
putString("userId", peerID.toString())
|
|
46
|
+
}
|
|
47
|
+
sendEvent(reactApplicationContext, "bridgefyDidConnect", params)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun onConnectedPeers(connectedPeers: List<UUID>) {
|
|
51
|
+
connectedPeers.forEach {
|
|
52
|
+
onConnected(it)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun onConnectedSecurely(peerID: UUID) {
|
|
57
|
+
val params = Arguments.createMap().apply {
|
|
58
|
+
putString("userId", peerID.toString())
|
|
59
|
+
}
|
|
60
|
+
sendEvent(
|
|
61
|
+
reactApplicationContext,
|
|
62
|
+
"bridgefyDidEstablishSecureConnection",
|
|
63
|
+
params
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override fun onDisconnected(peerID: UUID) {
|
|
68
|
+
val params = Arguments.createMap().apply {
|
|
69
|
+
putString("userId", peerID.toString())
|
|
70
|
+
}
|
|
71
|
+
sendEvent(reactApplicationContext, "bridgefyDidDisconnect", params)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// TODO: iOS provides BridgefyError
|
|
75
|
+
override fun onFailToSend(messageID: UUID) {
|
|
76
|
+
val params = Arguments.createMap().apply {
|
|
77
|
+
putString("messageId", messageID.toString())
|
|
78
|
+
}
|
|
79
|
+
sendEvent(reactApplicationContext, "bridgefyDidFailSendingMessage", params)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override fun onFailToStart(error: BridgefyException) {
|
|
83
|
+
val params = Arguments.createMap().apply {
|
|
84
|
+
putMap("error", mapFromBridgefyException(error))
|
|
85
|
+
}
|
|
86
|
+
sendEvent(reactApplicationContext, "bridgefyDidFailToStart", params)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
override fun onFailToStop(error: BridgefyException) {
|
|
90
|
+
val params = Arguments.createMap().apply {
|
|
91
|
+
putMap("error", mapFromBridgefyException(error))
|
|
92
|
+
}
|
|
93
|
+
sendEvent(reactApplicationContext, "bridgefyDidFailToStop", params)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override fun onProgressOfSend(messageID: UUID, position: Int, of: Int) {
|
|
97
|
+
val params = Arguments.createMap().apply {
|
|
98
|
+
putString("messageId", messageID.toString())
|
|
99
|
+
putInt("position", position)
|
|
100
|
+
putInt("of", of)
|
|
101
|
+
}
|
|
102
|
+
sendEvent(reactApplicationContext, "bridgefyDidSendDataProgress", params)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override fun onReceive(
|
|
106
|
+
data: ByteArray,
|
|
107
|
+
messageID: UUID,
|
|
108
|
+
transmissionMode: TransmissionMode
|
|
109
|
+
) {
|
|
110
|
+
val params = Arguments.createMap().apply {
|
|
111
|
+
putString("data", String(data))
|
|
112
|
+
putString("messageId", messageID.toString())
|
|
113
|
+
putMap("transmissionMode", mapFromTransmissionMode(transmissionMode))
|
|
114
|
+
}
|
|
115
|
+
sendEvent(reactApplicationContext, "bridgefyDidReceiveData", params)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override fun onSend(messageID: UUID) {
|
|
119
|
+
val params = Arguments.createMap().apply {
|
|
120
|
+
putString("messageId", messageID.toString())
|
|
121
|
+
}
|
|
122
|
+
sendEvent(reactApplicationContext, "bridgefyDidSendMessage", params)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
override fun onStarted(userID: UUID) {
|
|
126
|
+
val params = Arguments.createMap().apply {
|
|
127
|
+
putString("userId", userID.toString())
|
|
128
|
+
}
|
|
129
|
+
sendEvent(reactApplicationContext, "bridgefyDidStart", params)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// TODO: bridgefyDidFailToEstablishSecureConnection
|
|
133
|
+
// TODO: bridgefyDidDestroySession
|
|
134
|
+
// TODO: bridgefyDidFailToDestroySession
|
|
135
|
+
|
|
136
|
+
override fun onStopped() {
|
|
137
|
+
sendEvent(reactApplicationContext, "bridgefyDidStop", null)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
promise.resolve(null)
|
|
142
|
+
} catch (error: BridgefyException) {
|
|
143
|
+
val map = mapFromBridgefyException(error)
|
|
144
|
+
promise.reject(map.getString("code"), map.getString("message"), error)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
fun start(promise: Promise) {
|
|
150
|
+
bridgefy.start()
|
|
151
|
+
promise.resolve(null)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@ReactMethod
|
|
155
|
+
fun send(data: String, transmissionMode: ReadableMap, promise: Promise) {
|
|
156
|
+
val mode = transmissionModeFromMap(transmissionMode)!!
|
|
157
|
+
try {
|
|
158
|
+
val uuid = bridgefy.send(data.toByteArray(), mode)
|
|
159
|
+
promise.resolve(Arguments.createMap().apply {
|
|
160
|
+
putString("messageId", uuid.toString())
|
|
161
|
+
})
|
|
162
|
+
} catch (error: BridgefyException) {
|
|
163
|
+
val map = mapFromBridgefyException(error)
|
|
164
|
+
promise.reject(map.getString("code"), map.getString("message"), error)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@ReactMethod
|
|
169
|
+
fun stop(promise: Promise) {
|
|
170
|
+
bridgefy.stop()
|
|
171
|
+
promise.resolve(null)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@ReactMethod
|
|
175
|
+
fun connectedPeers(promise: Promise) {
|
|
176
|
+
promise.resolve(arrayOf<String>())
|
|
177
|
+
TODO("Android impl")
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@ReactMethod
|
|
181
|
+
fun currentUserID(promise: Promise) {
|
|
182
|
+
val userId = bridgefy.currentBridgefyUser()
|
|
183
|
+
promise.resolve(Arguments.createMap().apply {
|
|
184
|
+
putString("userId", userId.toString())
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@ReactMethod
|
|
189
|
+
fun establishSecureConnection(userId: String, promise: Promise) {
|
|
190
|
+
val uuid = UUID.fromString(userId)
|
|
191
|
+
bridgefy.establishSecureConnection(uuid)
|
|
192
|
+
promise.resolve(null)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@ReactMethod
|
|
196
|
+
fun licenseExpirationDate(promise: Promise) {
|
|
197
|
+
val date = bridgefy.licenseExpirationDate()
|
|
198
|
+
promise.resolve(Arguments.createMap().apply {
|
|
199
|
+
putString("licenseExpirationDate", date?.time.toString())
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
companion object {
|
|
204
|
+
const val NAME = "BridgefyReactNative"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
208
|
+
reactContext
|
|
209
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
210
|
+
.emit(eventName, params)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private fun mapFromBridgefyException(exception: BridgefyException): ReadableMap {
|
|
214
|
+
var code: String
|
|
215
|
+
var details: Int? = null
|
|
216
|
+
var message: String? = null
|
|
217
|
+
when (exception) {
|
|
218
|
+
is BridgefyException.AlreadyStartedException -> {
|
|
219
|
+
code = "alreadyStarted"
|
|
220
|
+
}
|
|
221
|
+
is BridgefyException.DeviceCapabilitiesException -> {
|
|
222
|
+
code = "deviceCapabilities"
|
|
223
|
+
message = exception.error
|
|
224
|
+
}
|
|
225
|
+
is BridgefyException.ExpiredLicenseException -> {
|
|
226
|
+
code = "expiredLicense"
|
|
227
|
+
message = exception.error
|
|
228
|
+
}
|
|
229
|
+
is BridgefyException.GenericException -> {
|
|
230
|
+
code = "genericException"
|
|
231
|
+
message = exception.message
|
|
232
|
+
details = exception.code
|
|
233
|
+
}
|
|
234
|
+
is BridgefyException.InconsistentDeviceTimeException -> {
|
|
235
|
+
code = "inconsistentDeviceTimeException"
|
|
236
|
+
message = exception.error
|
|
237
|
+
}
|
|
238
|
+
is BridgefyException.InternetConnectionRequiredException -> {
|
|
239
|
+
code = "internetConnectionRequiredException"
|
|
240
|
+
message = exception.error
|
|
241
|
+
}
|
|
242
|
+
is BridgefyException.InvalidAPIKeyFormatException -> {
|
|
243
|
+
code = "invalidAPIKey"
|
|
244
|
+
message = exception.error
|
|
245
|
+
}
|
|
246
|
+
is BridgefyException.MissingApplicationIdException -> {
|
|
247
|
+
code = "missingApplicationId"
|
|
248
|
+
message = exception.error
|
|
249
|
+
}
|
|
250
|
+
is BridgefyException.PermissionException -> {
|
|
251
|
+
code = "permissionException"
|
|
252
|
+
message = exception.error
|
|
253
|
+
}
|
|
254
|
+
is BridgefyException.RegistrationException -> {
|
|
255
|
+
code = "registrationException"
|
|
256
|
+
message = exception.error
|
|
257
|
+
}
|
|
258
|
+
is BridgefyException.SessionErrorException -> {
|
|
259
|
+
code = "sessionError"
|
|
260
|
+
message = exception.error
|
|
261
|
+
}
|
|
262
|
+
is BridgefyException.SimulatorIsNotSupportedException -> {
|
|
263
|
+
code = "simulatorIsNotSupported"
|
|
264
|
+
message = exception.error.toString()
|
|
265
|
+
}
|
|
266
|
+
is BridgefyException.SizeLimitExceededException -> {
|
|
267
|
+
code = "sizeLimitExceeded"
|
|
268
|
+
message = exception.error
|
|
269
|
+
}
|
|
270
|
+
is BridgefyException.UnknownException -> {
|
|
271
|
+
code = "unknownException"
|
|
272
|
+
message = exception.error.toString()
|
|
273
|
+
} else -> {
|
|
274
|
+
code = "unknownException"
|
|
275
|
+
message = exception.toString()
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return Arguments.createMap().apply {
|
|
279
|
+
putString("code", code)
|
|
280
|
+
putString("message", message)
|
|
281
|
+
if (details != null) putInt("details", details) else putNull("details")
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private fun propagationProfileFromString(str: String): PropagationProfile? {
|
|
286
|
+
return when (str) {
|
|
287
|
+
"highDensityNetwork" -> PropagationProfile.HighDensityEnvironment
|
|
288
|
+
"sparseNetwork" -> PropagationProfile.SparseEnvironment
|
|
289
|
+
"longReach" -> PropagationProfile.LongReach
|
|
290
|
+
"shortReach" -> PropagationProfile.ShortReach
|
|
291
|
+
"standard" -> PropagationProfile.Standard
|
|
292
|
+
else -> null
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private fun mapFromTransmissionMode(mode: TransmissionMode): ReadableMap {
|
|
297
|
+
return when (mode) {
|
|
298
|
+
is TransmissionMode.Broadcast -> Arguments.createMap().apply {
|
|
299
|
+
putString("mode", "broadcast")
|
|
300
|
+
putString("uuid", mode.sender.toString())
|
|
301
|
+
}
|
|
302
|
+
is TransmissionMode.Mesh -> Arguments.createMap().apply {
|
|
303
|
+
putString("mode", "mesh")
|
|
304
|
+
putString("uuid", mode.receiver.toString())
|
|
305
|
+
}
|
|
306
|
+
is TransmissionMode.P2P -> Arguments.createMap().apply {
|
|
307
|
+
putString("mode", "p2p")
|
|
308
|
+
putString("uuid", mode.receiver.toString())
|
|
309
|
+
}
|
|
310
|
+
else -> Arguments.createMap()
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private fun transmissionModeFromMap(map: ReadableMap): TransmissionMode? {
|
|
315
|
+
val uuid = UUID.fromString(map.getString("uuid"))
|
|
316
|
+
return when (map.getString("type")) {
|
|
317
|
+
"p2p" -> TransmissionMode.P2P(uuid)
|
|
318
|
+
"mesh" -> TransmissionMode.Mesh(uuid)
|
|
319
|
+
"broadcast" -> TransmissionMode.Broadcast(uuid)
|
|
320
|
+
else -> null
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package me.bridgefy.plugin.react_native
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BridgefyReactNativePackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(BridgefyReactNativeModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return emptyList()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 = "bridgefy-react-native"
|
|
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 => "11.0" }
|
|
15
|
+
s.source = { :git => "https://github.com/bridgefy/bridgefy-react-native.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
|
+
s.vendored_frameworks = "ios/Frameworks/BridgefySDK.xcframework"
|
|
19
|
+
|
|
20
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
21
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
22
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
23
|
+
install_modules_dependencies(s)
|
|
24
|
+
else
|
|
25
|
+
s.dependency "React-Core"
|
|
26
|
+
|
|
27
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
28
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
29
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
30
|
+
s.pod_target_xcconfig = {
|
|
31
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
32
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
33
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
34
|
+
}
|
|
35
|
+
s.dependency "React-Codegen"
|
|
36
|
+
s.dependency "RCT-Folly"
|
|
37
|
+
s.dependency "RCTRequired"
|
|
38
|
+
s.dependency "RCTTypeSafety"
|
|
39
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|