bridgefy-react-native 1.1.8 → 1.2.0
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 +1 -1
- package/README.md +582 -112
- package/android/build.gradle +36 -56
- package/android/gradle.properties +4 -4
- package/android/src/main/AndroidManifest.xml +1 -11
- package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativeModule.kt +609 -332
- package/android/src/main/java/me/bridgefy/plugin/react_native/BridgefyReactNativePackage.kt +25 -8
- package/android/src/main/java/me/bridgefy/plugin/react_native/service/BridgefyService.kt +625 -0
- package/android/src/main/java/me/bridgefy/plugin/react_native/util/BridgefyOperationModeManager.kt +193 -0
- package/android/src/main/java/me/bridgefy/plugin/react_native/util/BridgefyServiceManager.kt +123 -0
- package/android/src/main/java/me/bridgefy/plugin/react_native/util/Utils.kt +172 -0
- package/bridgefy-react-native.podspec +5 -25
- package/ios/BridgefyReactNativeModule.m +88 -0
- package/ios/BridgefyReactNativeModule.swift +524 -0
- package/lib/module/NativeBridgefy.js +114 -0
- package/lib/module/NativeBridgefy.js.map +1 -0
- package/lib/module/index.js +167 -208
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeBridgefy.d.ts +248 -0
- package/lib/typescript/src/NativeBridgefy.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +140 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +77 -74
- package/src/NativeBridgefy.ts +317 -0
- package/src/index.tsx +270 -226
- package/ios/BridgefyReactNative.m +0 -56
- package/ios/BridgefyReactNative.swift +0 -368
- package/ios/BridgefyReactNative.xcodeproj/project.pbxproj +0 -293
- package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/BridgefyReactNative.xcodeproj/project.xcworkspace/xcuserdata/bridgefy.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/BridgefyReactNative.xcodeproj/xcuserdata/bridgefy.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/Frameworks/BridgefySDK.xcframework/Info.plist +0 -48
- 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 +0 -317
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Headers/BridgefySDK.h +0 -15
- 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 +0 -5523
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios.private.swiftinterface +0 -116
- 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 +0 -116
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/Modules/module.modulemap +0 -11
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/BridgefySDK.framework/_CodeSignature/CodeResources +0 -190
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +0 -20
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/aarch64/BridgefySDK.yml +0 -12529
- 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 +0 -630
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Headers/BridgefySDK.h +0 -15
- 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 +0 -5523
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +0 -116
- 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 +0 -116
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +0 -5523
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/BridgefySDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +0 -116
- 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 +0 -116
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/Modules/module.modulemap +0 -11
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/BridgefySDK.framework/_CodeSignature/CodeResources +0 -245
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Info.plist +0 -20
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/DWARF/BridgefySDK +0 -0
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/aarch64/BridgefySDK.yml +0 -12276
- package/ios/Frameworks/BridgefySDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/BridgefySDK.framework.dSYM/Contents/Resources/Relocations/x86_64/BridgefySDK.yml +0 -11932
- package/lib/commonjs/index.js +0 -278
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/infraestructure/index.js +0 -28
- package/lib/commonjs/infraestructure/index.js.map +0 -1
- package/lib/commonjs/infraestructure/interfaces/ibridgefy.js +0 -6
- package/lib/commonjs/infraestructure/interfaces/ibridgefy.js.map +0 -1
- package/lib/commonjs/infraestructure/interfaces/index.js +0 -17
- package/lib/commonjs/infraestructure/interfaces/index.js.map +0 -1
- package/lib/commonjs/infraestructure/services/bridgefy_service.js +0 -6
- package/lib/commonjs/infraestructure/services/bridgefy_service.js.map +0 -1
- package/lib/commonjs/infraestructure/services/index.js +0 -17
- package/lib/commonjs/infraestructure/services/index.js.map +0 -1
- package/lib/module/infraestructure/index.js +0 -3
- package/lib/module/infraestructure/index.js.map +0 -1
- package/lib/module/infraestructure/interfaces/ibridgefy.js +0 -2
- package/lib/module/infraestructure/interfaces/ibridgefy.js.map +0 -1
- package/lib/module/infraestructure/interfaces/index.js +0 -2
- package/lib/module/infraestructure/interfaces/index.js.map +0 -1
- package/lib/module/infraestructure/services/bridgefy_service.js +0 -2
- package/lib/module/infraestructure/services/bridgefy_service.js.map +0 -1
- package/lib/module/infraestructure/services/index.js +0 -2
- package/lib/module/infraestructure/services/index.js.map +0 -1
- package/lib/typescript/index.d.ts +0 -219
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/infraestructure/index.d.ts +0 -3
- package/lib/typescript/infraestructure/index.d.ts.map +0 -1
- package/lib/typescript/infraestructure/interfaces/ibridgefy.d.ts +0 -10
- package/lib/typescript/infraestructure/interfaces/ibridgefy.d.ts.map +0 -1
- package/lib/typescript/infraestructure/interfaces/index.d.ts +0 -2
- package/lib/typescript/infraestructure/interfaces/index.d.ts.map +0 -1
- package/lib/typescript/infraestructure/services/bridgefy_service.d.ts +0 -17
- package/lib/typescript/infraestructure/services/bridgefy_service.d.ts.map +0 -1
- package/lib/typescript/infraestructure/services/index.d.ts +0 -2
- package/lib/typescript/infraestructure/services/index.d.ts.map +0 -1
- package/src/infraestructure/index.tsx +0 -2
- package/src/infraestructure/interfaces/ibridgefy.tsx +0 -10
- package/src/infraestructure/interfaces/index.tsx +0 -1
- package/src/infraestructure/services/bridgefy_service.tsx +0 -20
- package/src/infraestructure/services/index.tsx +0 -1
|
@@ -1,408 +1,685 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Kotlin implementation for Bridgefy TurboModule on Android
|
|
4
|
+
* Implements NativeBridgefy spec methods
|
|
5
|
+
*/
|
|
6
|
+
|
|
1
7
|
package me.bridgefy.plugin.react_native
|
|
2
8
|
|
|
3
|
-
import android.
|
|
9
|
+
import android.content.BroadcastReceiver
|
|
10
|
+
import android.content.Context
|
|
11
|
+
import android.content.Intent
|
|
12
|
+
import android.content.IntentFilter
|
|
13
|
+
import android.os.Build
|
|
14
|
+
import android.os.Bundle
|
|
15
|
+
import androidx.core.content.ContextCompat
|
|
4
16
|
import com.facebook.react.bridge.Arguments
|
|
17
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
5
18
|
import com.facebook.react.bridge.Promise
|
|
6
19
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
-
import com.facebook.react.bridge.ReactContext
|
|
8
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
-
import com.facebook.react.bridge.ReactMethod
|
|
10
20
|
import com.facebook.react.bridge.ReadableMap
|
|
11
21
|
import com.facebook.react.bridge.WritableMap
|
|
22
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
12
23
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
13
|
-
import java.util.UUID
|
|
14
|
-
import me.bridgefy.Bridgefy
|
|
15
|
-
import me.bridgefy.logger.enums.LogType
|
|
16
24
|
import me.bridgefy.commons.TransmissionMode
|
|
17
|
-
import me.bridgefy.
|
|
18
|
-
import me.bridgefy.
|
|
19
|
-
import me.bridgefy.
|
|
25
|
+
import me.bridgefy.plugin.react_native.service.BridgefyService
|
|
26
|
+
import me.bridgefy.plugin.react_native.util.BridgefyOperationModeManager
|
|
27
|
+
import me.bridgefy.plugin.react_native.util.BridgefyServiceManager
|
|
28
|
+
import me.bridgefy.plugin.react_native.util.OperationMode
|
|
29
|
+
import me.bridgefy.plugin.react_native.util.Utils.bundleFromTransmissionMode
|
|
30
|
+
import me.bridgefy.plugin.react_native.util.Utils.mapFromTransmissionMode
|
|
31
|
+
import me.bridgefy.plugin.react_native.util.Utils.transmissionModeFromBundle
|
|
32
|
+
import java.util.Date
|
|
33
|
+
import java.util.UUID
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
@ReactModule(name = NativeBridgefySpec.NAME)
|
|
36
|
+
class BridgefyReactNativeModule(
|
|
37
|
+
reactContext: ReactApplicationContext,
|
|
38
|
+
) : NativeBridgefySpec(reactContext),
|
|
39
|
+
LifecycleEventListener {
|
|
40
|
+
private val context: ReactApplicationContext = reactContext
|
|
41
|
+
private val eventReceiver: BridgefyEventReceiver = BridgefyEventReceiver()
|
|
42
|
+
private var isReceiverRegistered = false
|
|
23
43
|
|
|
24
|
-
private
|
|
44
|
+
private val serviceManager: BridgefyServiceManager by lazy { BridgefyServiceManager.getInstance(reactContext) }
|
|
45
|
+
private val modeManager: BridgefyOperationModeManager by lazy { BridgefyOperationModeManager.getInstance(reactContext) }
|
|
25
46
|
|
|
26
47
|
init {
|
|
27
|
-
|
|
48
|
+
reactContext.addLifecycleEventListener(this)
|
|
49
|
+
registerBroadcastReceiver()
|
|
50
|
+
|
|
51
|
+
// Set up mode change listener
|
|
52
|
+
modeManager.setModeChangeListener { mode ->
|
|
53
|
+
sendEvent(
|
|
54
|
+
"bridgefyModeChanged",
|
|
55
|
+
Arguments.createMap().apply {
|
|
56
|
+
putString("mode", mode.name.lowercase())
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
}
|
|
28
60
|
}
|
|
29
61
|
|
|
30
|
-
override fun getName(): String
|
|
31
|
-
|
|
62
|
+
override fun getName(): String = NAME
|
|
63
|
+
|
|
64
|
+
companion object {
|
|
65
|
+
const val NAME = NativeBridgefySpec.NAME
|
|
32
66
|
}
|
|
33
67
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
68
|
+
// MARK: - Lifecycle
|
|
69
|
+
|
|
70
|
+
override fun onHostResume() {
|
|
71
|
+
if (!isReceiverRegistered) {
|
|
72
|
+
registerBroadcastReceiver()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Refresh service state
|
|
76
|
+
serviceManager.refreshFromService()
|
|
77
|
+
|
|
78
|
+
// If HYBRID mode, switch to foreground
|
|
79
|
+
if (modeManager.getOperationMode() == OperationMode.HYBRID) {
|
|
80
|
+
modeManager.switchToForegroundMode()
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override fun onHostPause() {
|
|
85
|
+
// If HYBRID mode, switch to background
|
|
86
|
+
if (modeManager.getOperationMode() == OperationMode.HYBRID) {
|
|
87
|
+
modeManager.switchToBackgroundMode()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
override fun onHostDestroy() {
|
|
92
|
+
unregisterBroadcastReceiver()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// MARK: - BroadcastReceiver Setup
|
|
96
|
+
|
|
97
|
+
private inner class BridgefyEventReceiver : BroadcastReceiver() {
|
|
98
|
+
override fun onReceive(
|
|
99
|
+
context: Context?,
|
|
100
|
+
intent: Intent?,
|
|
101
|
+
) {
|
|
102
|
+
intent ?: return
|
|
103
|
+
when (intent.action) {
|
|
104
|
+
BridgefyService.EVENT_BRIDGEFY_DID_START -> {
|
|
105
|
+
val userId = intent.getStringExtra(BridgefyService.EXTRA_USER_ID) ?: return
|
|
106
|
+
|
|
107
|
+
serviceManager.setCurrentUserId(userId)
|
|
108
|
+
|
|
109
|
+
sendEvent(
|
|
110
|
+
"bridgefyDidStart",
|
|
111
|
+
Arguments.createMap().apply {
|
|
112
|
+
putString("userId", userId)
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
BridgefyService.EVENT_BRIDGEFY_DID_STOP -> {
|
|
118
|
+
sendEvent("bridgefyDidStop", null)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
BridgefyService.EVENT_BRIDGEFY_DID_CONNECT -> {
|
|
122
|
+
val userId = intent.getStringExtra(BridgefyService.EXTRA_USER_ID) ?: return
|
|
123
|
+
sendEvent(
|
|
124
|
+
"bridgefyDidConnect",
|
|
125
|
+
Arguments.createMap().apply {
|
|
126
|
+
putString("userId", userId)
|
|
127
|
+
},
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
BridgefyService.EVENT_BRIDGEFY_DID_DISCONNECT -> {
|
|
132
|
+
val userId = intent.getStringExtra(BridgefyService.EXTRA_USER_ID) ?: return
|
|
133
|
+
sendEvent(
|
|
134
|
+
"bridgefyDidDisconnect",
|
|
135
|
+
Arguments.createMap().apply {
|
|
136
|
+
putString("userId", userId)
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
BridgefyService.EVENT_BRIDGEFY_RECEIVE_DATA -> {
|
|
142
|
+
val data = intent.getByteArrayExtra(BridgefyService.EXTRA_MESSAGE_DATA) ?: return
|
|
143
|
+
val messageId = intent.getStringExtra(BridgefyService.EXTRA_MESSAGE_ID) ?: return
|
|
144
|
+
val transmissionMode =
|
|
145
|
+
intent.getBundleExtra(BridgefyService.EXTRA_TRANSMISSION_MODE) ?: Bundle()
|
|
146
|
+
|
|
147
|
+
sendEvent(
|
|
148
|
+
"bridgefyDidReceiveData",
|
|
149
|
+
Arguments.createMap().apply {
|
|
150
|
+
putString("data", String(data))
|
|
151
|
+
putString("messageId", messageId)
|
|
152
|
+
putMap(
|
|
153
|
+
"transmissionMode",
|
|
154
|
+
mapFromTransmissionMode(transmissionModeFromBundle(transmissionMode)),
|
|
155
|
+
)
|
|
156
|
+
},
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
BridgefyService.EVENT_BRIDGEFY_SEND_MESSAGE -> {
|
|
161
|
+
val messageId = intent.getStringExtra(BridgefyService.EXTRA_MESSAGE_ID) ?: return
|
|
162
|
+
sendEvent(
|
|
163
|
+
"bridgefyDidSendMessage",
|
|
164
|
+
Arguments.createMap().apply {
|
|
165
|
+
putString("messageId", messageId)
|
|
166
|
+
},
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
BridgefyService.EVENT_BRIDGEFY_FAIL_SENDING -> {
|
|
171
|
+
val messageId = intent.getStringExtra(BridgefyService.EXTRA_MESSAGE_ID) ?: return
|
|
172
|
+
val errorCode = intent.getStringExtra(BridgefyService.EXTRA_ERROR_CODE) ?: "UNKNOWN_ERROR"
|
|
173
|
+
val errorMessage =
|
|
174
|
+
intent.getStringExtra(BridgefyService.EXTRA_ERROR_MESSAGE) ?: "Unknown error"
|
|
175
|
+
|
|
176
|
+
sendEvent(
|
|
177
|
+
"bridgefyDidFailSendingMessage",
|
|
178
|
+
Arguments.createMap().apply {
|
|
179
|
+
putString("messageId", messageId)
|
|
180
|
+
putString("code", errorCode)
|
|
181
|
+
putString("message", errorMessage)
|
|
182
|
+
},
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
BridgefyService.EVENT_BRIDGEFY_FAIL_TO_START -> {
|
|
187
|
+
val errorCode = intent.getStringExtra(BridgefyService.EXTRA_ERROR_CODE) ?: "UNKNOWN_ERROR"
|
|
188
|
+
val errorMessage =
|
|
189
|
+
intent.getStringExtra(BridgefyService.EXTRA_ERROR_MESSAGE) ?: "Unknown error"
|
|
190
|
+
|
|
191
|
+
sendEvent(
|
|
192
|
+
"bridgefyDidFailToStart",
|
|
193
|
+
Arguments.createMap().apply {
|
|
194
|
+
putString("code", errorCode)
|
|
195
|
+
putString("message", errorMessage)
|
|
196
|
+
},
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
BridgefyService.EVENT_BRIDGEFY_ESTABLISH_SECURE -> {
|
|
201
|
+
val userId = intent.getStringExtra(BridgefyService.EXTRA_USER_ID) ?: return
|
|
202
|
+
sendEvent(
|
|
203
|
+
"bridgefyDidEstablishSecureConnection",
|
|
204
|
+
Arguments.createMap().apply {
|
|
205
|
+
putString("userId", userId)
|
|
206
|
+
},
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
BridgefyService.EVENT_BRIDGEFY_FAIL_SECURE -> {
|
|
211
|
+
val userId = intent.getStringExtra(BridgefyService.EXTRA_USER_ID) ?: return
|
|
212
|
+
val errorCode = intent.getStringExtra(BridgefyService.EXTRA_ERROR_CODE) ?: "UNKNOWN_ERROR"
|
|
213
|
+
val errorMessage =
|
|
214
|
+
intent.getStringExtra(BridgefyService.EXTRA_ERROR_MESSAGE) ?: "Unknown error"
|
|
215
|
+
|
|
216
|
+
sendEvent(
|
|
217
|
+
"bridgefyDidFailToEstablishSecureConnection",
|
|
218
|
+
Arguments.createMap().apply {
|
|
219
|
+
putString("userId", userId)
|
|
220
|
+
putString("code", errorCode)
|
|
221
|
+
putString("message", errorMessage)
|
|
222
|
+
},
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
BridgefyService.EVENT_BRIDGEFY_DID_DESTROY_SESSION -> {
|
|
227
|
+
sendEvent("bridgefyDidDestroySession", null)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
BridgefyService.EVENT_BRIDGEFY_FAIL_TO_DESTROY_SESSION -> {
|
|
231
|
+
val errorCode = intent.getStringExtra(BridgefyService.EXTRA_ERROR_CODE) ?: "UNKNOWN_ERROR"
|
|
232
|
+
val errorMessage =
|
|
233
|
+
intent.getStringExtra(BridgefyService.EXTRA_ERROR_MESSAGE) ?: "Unknown error"
|
|
234
|
+
|
|
235
|
+
sendEvent(
|
|
236
|
+
"bridgefyDidFailToDestroySession",
|
|
237
|
+
Arguments.createMap().apply {
|
|
238
|
+
putString("code", errorCode)
|
|
239
|
+
putString("message", errorMessage)
|
|
240
|
+
},
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
BridgefyService.EVENT_BRIDGEFY_PROGRESS_OF_SEND -> {
|
|
245
|
+
val messageId = intent.getStringExtra(BridgefyService.EXTRA_MESSAGE_ID) ?: return
|
|
246
|
+
val position = intent.getIntExtra(BridgefyService.EXTRA_POSITION, 0)
|
|
247
|
+
val of = intent.getIntExtra(BridgefyService.EXTRA_OF, 0)
|
|
248
|
+
sendEvent(
|
|
249
|
+
"bridgefyDidProgressOfSend",
|
|
250
|
+
Arguments.createMap().apply {
|
|
251
|
+
putString("messageId", messageId)
|
|
100
252
|
putInt("position", position)
|
|
101
253
|
putInt("of", of)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
putString("
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
254
|
+
},
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
BridgefyService.EVENT_BRIDGEFY_FAIL_TO_STOP -> {
|
|
259
|
+
val errorCode = intent.getStringExtra(BridgefyService.EXTRA_ERROR_CODE) ?: "UNKNOWN_ERROR"
|
|
260
|
+
val errorMessage =
|
|
261
|
+
intent.getStringExtra(BridgefyService.EXTRA_ERROR_MESSAGE) ?: "Unknown error"
|
|
262
|
+
sendEvent(
|
|
263
|
+
"bridgefyDidFailToStop",
|
|
264
|
+
Arguments.createMap().apply {
|
|
265
|
+
putString("code", errorCode)
|
|
266
|
+
putString("message", errorMessage)
|
|
267
|
+
},
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
BridgefyService.EVENT_BRIDGEFY_DID_UPDATE_CONNECTED_PEERS -> {
|
|
272
|
+
val peers: List<String> =
|
|
273
|
+
intent.getStringArrayExtra(BridgefyService.EXTRA_CONNECTED_PEERS)?.toList() ?: return
|
|
274
|
+
sendEvent(
|
|
275
|
+
"bridgefyDidUpdateConnectedPeers",
|
|
276
|
+
Arguments.createMap().apply {
|
|
277
|
+
putArray("peers", Arguments.createArray().apply { peers })
|
|
278
|
+
},
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private fun registerBroadcastReceiver() {
|
|
286
|
+
if (isReceiverRegistered) return
|
|
287
|
+
|
|
288
|
+
val filter =
|
|
289
|
+
IntentFilter().apply {
|
|
290
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_START)
|
|
291
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_STOP)
|
|
292
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_CONNECT)
|
|
293
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_DISCONNECT)
|
|
294
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_UPDATE_CONNECTED_PEERS)
|
|
295
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_RECEIVE_DATA)
|
|
296
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_SEND_MESSAGE)
|
|
297
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_FAIL_SENDING)
|
|
298
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_FAIL_TO_START)
|
|
299
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_ESTABLISH_SECURE)
|
|
300
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_FAIL_SECURE)
|
|
301
|
+
|
|
302
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_DID_DESTROY_SESSION)
|
|
303
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_FAIL_TO_DESTROY_SESSION)
|
|
304
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_PROGRESS_OF_SEND)
|
|
305
|
+
addAction(BridgefyService.EVENT_BRIDGEFY_FAIL_TO_STOP)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ContextCompat.registerReceiver(
|
|
309
|
+
context,
|
|
310
|
+
eventReceiver,
|
|
311
|
+
filter,
|
|
312
|
+
ContextCompat.RECEIVER_EXPORTED,
|
|
313
|
+
)
|
|
314
|
+
isReceiverRegistered = true
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private fun unregisterBroadcastReceiver() {
|
|
318
|
+
if (isReceiverRegistered) {
|
|
319
|
+
try {
|
|
320
|
+
context.unregisterReceiver(eventReceiver)
|
|
321
|
+
isReceiverRegistered = false
|
|
322
|
+
} catch (e: Exception) {
|
|
323
|
+
println("Error unregistering receiver ${e.localizedMessage}")
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private fun sendEvent(
|
|
329
|
+
eventName: String,
|
|
330
|
+
params: WritableMap?,
|
|
331
|
+
) {
|
|
332
|
+
context
|
|
333
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
334
|
+
.emit(eventName, params)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// MARK: - Service Control Methods
|
|
338
|
+
|
|
339
|
+
// FIX 2: Use startForegroundService() on Android 8+
|
|
340
|
+
private fun startService() {
|
|
341
|
+
val serviceIntent =
|
|
342
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
343
|
+
action = BridgefyService.ACTION_START_SERVICE
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
347
|
+
context.startForegroundService(serviceIntent)
|
|
348
|
+
} else {
|
|
349
|
+
context.startService(serviceIntent)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private fun stopService() {
|
|
354
|
+
val serviceIntent =
|
|
355
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
356
|
+
action = BridgefyService.ACTION_STOP_SERVICE
|
|
357
|
+
}
|
|
358
|
+
context.startService(serviceIntent)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// MARK: - NativeBridgefySpec Implementation
|
|
362
|
+
override fun initialize(
|
|
363
|
+
config: ReadableMap,
|
|
364
|
+
promise: Promise,
|
|
365
|
+
) {
|
|
366
|
+
try {
|
|
367
|
+
val apiKey =
|
|
368
|
+
config.getString("apiKey")
|
|
369
|
+
?: throw Exception("API key is required")
|
|
370
|
+
|
|
371
|
+
val verboseLogging = config.getBoolean("verboseLogging")
|
|
372
|
+
val operationModeStr = config.getString("operationMode") ?: "hybrid"
|
|
373
|
+
|
|
374
|
+
// Set operation mode
|
|
375
|
+
val mode =
|
|
376
|
+
when (operationModeStr.lowercase()) {
|
|
377
|
+
"foreground" -> OperationMode.FOREGROUND
|
|
378
|
+
"background" -> OperationMode.BACKGROUND
|
|
379
|
+
else -> OperationMode.HYBRID
|
|
380
|
+
}
|
|
381
|
+
modeManager.setOperationMode(mode)
|
|
382
|
+
|
|
383
|
+
// Start service if needed
|
|
384
|
+
if (modeManager.shouldRunInService()) {
|
|
385
|
+
startService()
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
val initIntent =
|
|
389
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
390
|
+
action = BridgefyService.ACTION_INITIALIZE
|
|
391
|
+
putExtra(BridgefyService.EXTRA_API_KEY, apiKey)
|
|
392
|
+
putExtra(BridgefyService.EXTRA_VERBOSE_LOGGING, verboseLogging)
|
|
393
|
+
}
|
|
394
|
+
context.startService(initIntent)
|
|
395
|
+
|
|
158
396
|
promise.resolve(null)
|
|
159
|
-
} catch (error: BridgefyException) {
|
|
160
|
-
val map = mapFromBridgefyException(error)
|
|
161
|
-
promise.reject(map.getString("code"), map.getString("message"), error)
|
|
162
397
|
} catch (e: Exception) {
|
|
163
|
-
|
|
398
|
+
println("initialize() failed: ${e.localizedMessage}")
|
|
399
|
+
promise.reject("INITIALIZATION_FAILED", e.message, e)
|
|
164
400
|
}
|
|
165
401
|
}
|
|
166
402
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
promise: Promise
|
|
403
|
+
override fun start(
|
|
404
|
+
userId: String?,
|
|
405
|
+
propagationProfile: String?,
|
|
406
|
+
promise: Promise,
|
|
172
407
|
) {
|
|
173
408
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
409
|
+
val startIntent =
|
|
410
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
411
|
+
action = BridgefyService.ACTION_START_SDK
|
|
412
|
+
putExtra(BridgefyService.EXTRA_USER_ID, userId)
|
|
413
|
+
putExtra(BridgefyService.EXTRA_PROPAGATION_PROFILE, propagationProfile ?: "realTime")
|
|
414
|
+
}
|
|
415
|
+
context.startService(startIntent)
|
|
416
|
+
|
|
180
417
|
promise.resolve(null)
|
|
181
418
|
} catch (e: Exception) {
|
|
182
|
-
|
|
419
|
+
println("start() failed: ${e.localizedMessage}")
|
|
420
|
+
promise.reject("START_FAILED", e.message, e)
|
|
183
421
|
}
|
|
184
422
|
}
|
|
185
423
|
|
|
186
|
-
|
|
187
|
-
fun send(data: String, transmissionMode: ReadableMap, promise: Promise) {
|
|
424
|
+
override fun stop(promise: Promise) {
|
|
188
425
|
try {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
val uuid = bridgefy.send(data.toByteArray(), mode)
|
|
193
|
-
promise.resolve(
|
|
194
|
-
Arguments.createMap().apply {
|
|
195
|
-
putString("messageId", uuid.toString())
|
|
426
|
+
val stopIntent =
|
|
427
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
428
|
+
action = BridgefyService.ACTION_STOP_SDK
|
|
196
429
|
}
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
promise.reject(map.getString("code"), map.getString("message"), error)
|
|
430
|
+
context.startService(stopIntent)
|
|
431
|
+
|
|
432
|
+
promise.resolve(null)
|
|
201
433
|
} catch (e: Exception) {
|
|
202
|
-
|
|
434
|
+
println("stop() failed: ${e.localizedMessage}")
|
|
435
|
+
promise.reject("STOP_FAILED", e.message, e)
|
|
203
436
|
}
|
|
204
437
|
}
|
|
205
438
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
439
|
+
override fun destroySession(promise: Promise) {
|
|
440
|
+
try {
|
|
441
|
+
stopService()
|
|
442
|
+
serviceManager.getBridgefy()?.destroySession()
|
|
443
|
+
serviceManager.refreshBridgefy()
|
|
444
|
+
serviceManager.clearState()
|
|
445
|
+
promise.resolve(null)
|
|
446
|
+
} catch (e: Exception) {
|
|
447
|
+
println("destroySession() failed: ${e.localizedMessage}")
|
|
448
|
+
promise.reject("DESTROY_FAILED", e.message, e)
|
|
449
|
+
}
|
|
212
450
|
}
|
|
213
451
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
452
|
+
// MARK: - Operation Mode Methods
|
|
453
|
+
|
|
454
|
+
override fun setOperationMode(
|
|
455
|
+
config: ReadableMap?,
|
|
456
|
+
promise: Promise,
|
|
457
|
+
) {
|
|
458
|
+
try {
|
|
459
|
+
val mode = config?.getString("mode") ?: ""
|
|
460
|
+
|
|
461
|
+
val opMode =
|
|
462
|
+
when (mode.lowercase()) {
|
|
463
|
+
"foreground" -> OperationMode.FOREGROUND
|
|
464
|
+
"background" -> OperationMode.BACKGROUND
|
|
465
|
+
else -> OperationMode.HYBRID
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
val success = modeManager.setOperationMode(opMode)
|
|
469
|
+
|
|
470
|
+
if (success) {
|
|
471
|
+
promise.resolve(Arguments.createMap().apply { putString("mode", mode.lowercase()) })
|
|
472
|
+
} else {
|
|
473
|
+
promise.reject("MODE_CHANGE_FAILED", "Could not change operation mode")
|
|
474
|
+
}
|
|
475
|
+
} catch (e: Exception) {
|
|
476
|
+
println("setOperationMode() failed: ${e.localizedMessage}")
|
|
477
|
+
promise.reject("ERROR", e.message, e)
|
|
221
478
|
}
|
|
222
|
-
promise.resolve(Arguments.createMap().apply { putArray("connectedPeers", nodes) })
|
|
223
479
|
}
|
|
224
480
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
481
|
+
override fun getOperationMode(promise: Promise) {
|
|
482
|
+
try {
|
|
483
|
+
val mode = modeManager.getOperationMode().name.lowercase()
|
|
484
|
+
promise.resolve(Arguments.createMap().apply { putString("mode", mode) })
|
|
485
|
+
} catch (e: Exception) {
|
|
486
|
+
println("getOperationMode() failed: ${e.localizedMessage}")
|
|
487
|
+
promise.reject("ERROR", e.message, e)
|
|
488
|
+
}
|
|
229
489
|
}
|
|
230
490
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
491
|
+
override fun switchToBackground(promise: Promise) {
|
|
492
|
+
try {
|
|
493
|
+
if (modeManager.getOperationMode() != OperationMode.HYBRID) {
|
|
494
|
+
promise.reject("NOT_HYBRID_MODE", "Only available in HYBRID mode")
|
|
495
|
+
return
|
|
496
|
+
}
|
|
237
497
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
promise.resolve(
|
|
244
|
-
Arguments.createMap().apply {
|
|
245
|
-
putString("userId", userId.toString())
|
|
498
|
+
val success = modeManager.switchToBackgroundMode()
|
|
499
|
+
if (success) {
|
|
500
|
+
promise.resolve(null)
|
|
501
|
+
} else {
|
|
502
|
+
promise.reject("SWITCH_FAILED", "Could not switch to background")
|
|
246
503
|
}
|
|
247
|
-
)
|
|
504
|
+
} catch (e: Exception) {
|
|
505
|
+
println("switchToBackground() failed: ${e.localizedMessage}")
|
|
506
|
+
promise.reject("ERROR", e.message, e)
|
|
507
|
+
}
|
|
248
508
|
}
|
|
249
509
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
promise.resolve(null)
|
|
257
|
-
}
|
|
510
|
+
override fun switchToForeground(promise: Promise) {
|
|
511
|
+
try {
|
|
512
|
+
if (modeManager.getOperationMode() != OperationMode.HYBRID) {
|
|
513
|
+
promise.reject("NOT_HYBRID_MODE", "Only available in HYBRID mode")
|
|
514
|
+
return
|
|
515
|
+
}
|
|
258
516
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
Arguments.createMap().apply {
|
|
265
|
-
putString("licenseExpirationDate", date?.time.toString())
|
|
517
|
+
val success = modeManager.switchToForegroundMode()
|
|
518
|
+
if (success) {
|
|
519
|
+
promise.resolve(null)
|
|
520
|
+
} else {
|
|
521
|
+
promise.reject("SWITCH_FAILED", "Could not switch to foreground")
|
|
266
522
|
}
|
|
267
|
-
)
|
|
523
|
+
} catch (e: Exception) {
|
|
524
|
+
println("switchToForeground() failed: ${e.localizedMessage}")
|
|
525
|
+
promise.reject("ERROR", e.message, e)
|
|
526
|
+
}
|
|
268
527
|
}
|
|
269
528
|
|
|
270
|
-
|
|
271
|
-
fun isInitialized(promise: Promise) {
|
|
529
|
+
override fun getOperationStatus(promise: Promise) {
|
|
272
530
|
try {
|
|
273
|
-
val
|
|
274
|
-
|
|
531
|
+
val mode = modeManager.getOperationMode().name.lowercase()
|
|
532
|
+
val isInit = serviceManager.getBridgefy()?.isInitialized ?: false
|
|
533
|
+
val isStart = serviceManager.getBridgefy()?.isStarted ?: false
|
|
534
|
+
|
|
535
|
+
promise.resolve(
|
|
536
|
+
Arguments.createMap().apply {
|
|
537
|
+
putString("operationMode", mode)
|
|
538
|
+
putBoolean("isInitialized", isInit)
|
|
539
|
+
putBoolean("isStarted", isStart)
|
|
540
|
+
putBoolean("shouldRunInService", (modeManager.shouldRunInService()))
|
|
541
|
+
putString("debugInfo", modeManager.getDebugInfo())
|
|
542
|
+
},
|
|
543
|
+
)
|
|
275
544
|
} catch (e: Exception) {
|
|
276
|
-
e.
|
|
277
|
-
promise.
|
|
545
|
+
println("getOperationStatus() failed: ${e.localizedMessage}")
|
|
546
|
+
promise.reject("ERROR", e.message, e)
|
|
278
547
|
}
|
|
279
548
|
}
|
|
280
549
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
550
|
+
override fun send(
|
|
551
|
+
data: String,
|
|
552
|
+
transmissionMode: ReadableMap,
|
|
553
|
+
promise: Promise,
|
|
554
|
+
) {
|
|
555
|
+
try {
|
|
556
|
+
val type =
|
|
557
|
+
transmissionMode.getString("type")
|
|
558
|
+
?: throw Exception("Transmission mode type is required")
|
|
559
|
+
|
|
560
|
+
val recipientId = transmissionMode.getString("uuid")
|
|
561
|
+
|
|
562
|
+
val mode =
|
|
563
|
+
when (type) {
|
|
564
|
+
"broadcast" -> TransmissionMode.Broadcast(UUID.randomUUID())
|
|
565
|
+
"p2p" -> TransmissionMode.P2P(UUID.fromString(recipientId))
|
|
566
|
+
"mesh" -> TransmissionMode.Mesh(UUID.fromString(recipientId))
|
|
567
|
+
else -> error("INVALID_MESSAGE" to "Invalid mode")
|
|
568
|
+
}
|
|
287
569
|
|
|
288
|
-
|
|
289
|
-
|
|
570
|
+
val sendIntent =
|
|
571
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
572
|
+
action = BridgefyService.ACTION_SEND_MESSAGE
|
|
573
|
+
putExtra(BridgefyService.EXTRA_MESSAGE_DATA, data.toByteArray())
|
|
574
|
+
putExtra(BridgefyService.EXTRA_TRANSMISSION_MODE, bundleFromTransmissionMode(mode))
|
|
575
|
+
putExtra(BridgefyService.EXTRA_RECIPIENT_ID, recipientId)
|
|
576
|
+
}
|
|
577
|
+
context.startService(sendIntent)
|
|
578
|
+
|
|
579
|
+
// Message ID will be returned via broadcast event
|
|
580
|
+
promise.resolve("pending")
|
|
581
|
+
} catch (e: Exception) {
|
|
582
|
+
promise.reject("SEND_FAILED", e.message, e)
|
|
583
|
+
}
|
|
290
584
|
}
|
|
291
585
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
586
|
+
override fun establishSecureConnection(
|
|
587
|
+
userId: String,
|
|
588
|
+
promise: Promise,
|
|
589
|
+
) {
|
|
590
|
+
try {
|
|
591
|
+
val secureIntent =
|
|
592
|
+
Intent(context, BridgefyService::class.java).apply {
|
|
593
|
+
action = BridgefyService.ACTION_ESTABLISH_SECURE
|
|
594
|
+
putExtra(BridgefyService.EXTRA_USER_ID, userId)
|
|
595
|
+
}
|
|
596
|
+
context.startService(secureIntent)
|
|
597
|
+
promise.resolve(null)
|
|
598
|
+
} catch (e: Exception) {
|
|
599
|
+
promise.reject("CONNECTION_FAILED", e.message, e)
|
|
600
|
+
}
|
|
296
601
|
}
|
|
297
602
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
is BridgefyException.DeviceCapabilitiesException -> {
|
|
307
|
-
code = "deviceCapabilities"
|
|
308
|
-
message = exception.error
|
|
309
|
-
}
|
|
310
|
-
is BridgefyException.ExpiredLicenseException -> {
|
|
311
|
-
code = "expiredLicense"
|
|
312
|
-
message = exception.error
|
|
313
|
-
}
|
|
314
|
-
is BridgefyException.GenericException -> {
|
|
315
|
-
code = "genericException"
|
|
316
|
-
message = exception.message
|
|
317
|
-
details = exception.code
|
|
318
|
-
}
|
|
319
|
-
is BridgefyException.InconsistentDeviceTimeException -> {
|
|
320
|
-
code = "inconsistentDeviceTimeException"
|
|
321
|
-
message = exception.error
|
|
322
|
-
}
|
|
323
|
-
is BridgefyException.InternetConnectionRequiredException -> {
|
|
324
|
-
code = "internetConnectionRequiredException"
|
|
325
|
-
message = exception.error
|
|
326
|
-
}
|
|
327
|
-
is BridgefyException.InvalidAPIKeyFormatException -> {
|
|
328
|
-
code = "invalidAPIKey"
|
|
329
|
-
message = exception.error
|
|
330
|
-
}
|
|
331
|
-
is BridgefyException.MissingApplicationIdException -> {
|
|
332
|
-
code = "missingApplicationId"
|
|
333
|
-
message = exception.error
|
|
334
|
-
}
|
|
335
|
-
is BridgefyException.PermissionException -> {
|
|
336
|
-
code = "permissionException"
|
|
337
|
-
message = exception.error
|
|
338
|
-
}
|
|
339
|
-
is BridgefyException.RegistrationException -> {
|
|
340
|
-
code = "registrationException"
|
|
341
|
-
message = exception.error
|
|
342
|
-
}
|
|
343
|
-
is BridgefyException.SessionErrorException -> {
|
|
344
|
-
code = "sessionError"
|
|
345
|
-
message = exception.error
|
|
346
|
-
}
|
|
347
|
-
is BridgefyException.SimulatorIsNotSupportedException -> {
|
|
348
|
-
code = "simulatorIsNotSupported"
|
|
349
|
-
message = exception.error.toString()
|
|
350
|
-
}
|
|
351
|
-
is BridgefyException.SizeLimitExceededException -> {
|
|
352
|
-
code = "sizeLimitExceeded"
|
|
353
|
-
message = exception.error
|
|
354
|
-
}
|
|
355
|
-
is BridgefyException.UnknownException -> {
|
|
356
|
-
code = "unknownException"
|
|
357
|
-
message = exception.error.toString()
|
|
358
|
-
} else -> {
|
|
359
|
-
code = "unknownException"
|
|
360
|
-
message = exception.toString()
|
|
603
|
+
override fun currentUserId(promise: Promise) {
|
|
604
|
+
try {
|
|
605
|
+
val userId = serviceManager.getCurrentUserId()
|
|
606
|
+
if (userId != null) {
|
|
607
|
+
promise.resolve(userId)
|
|
608
|
+
} else {
|
|
609
|
+
promise.reject("NOT_AVAILABLE", "User ID not initialized")
|
|
361
610
|
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
putString("code", code)
|
|
365
|
-
putString("message", message)
|
|
366
|
-
if (details != null) putInt("details", details) else putNull("details")
|
|
611
|
+
} catch (e: Exception) {
|
|
612
|
+
promise.reject("ERROR", e.message, e)
|
|
367
613
|
}
|
|
368
614
|
}
|
|
369
615
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
616
|
+
override fun connectedPeers(promise: Promise) {
|
|
617
|
+
try {
|
|
618
|
+
val peers =
|
|
619
|
+
serviceManager
|
|
620
|
+
.getBridgefy()
|
|
621
|
+
?.connectedPeers()
|
|
622
|
+
?.getOrNull()
|
|
623
|
+
?.map { it.toString() }
|
|
624
|
+
?.distinct()
|
|
625
|
+
val array = Arguments.createArray()
|
|
626
|
+
peers?.forEach { array.pushString(it) }
|
|
627
|
+
promise.resolve(array)
|
|
628
|
+
} catch (e: Exception) {
|
|
629
|
+
promise.reject("ERROR", e.message, e)
|
|
378
630
|
}
|
|
379
631
|
}
|
|
380
632
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
putString("mode", "p2p")
|
|
393
|
-
putString("uuid", mode.receiver.toString())
|
|
633
|
+
override fun licenseExpirationDate(promise: Promise) {
|
|
634
|
+
runCatching {
|
|
635
|
+
val exp =
|
|
636
|
+
serviceManager
|
|
637
|
+
.getBridgefy()
|
|
638
|
+
?.licenseExpirationDate()
|
|
639
|
+
?.getOrThrow()
|
|
640
|
+
?.time ?: 0L
|
|
641
|
+
Arguments.createMap().apply {
|
|
642
|
+
putDouble("expirationDate", exp.toDouble())
|
|
643
|
+
putBoolean("isValid", exp > System.currentTimeMillis())
|
|
394
644
|
}
|
|
395
|
-
|
|
645
|
+
}.fold(
|
|
646
|
+
onSuccess = { promise.resolve(it) },
|
|
647
|
+
onFailure = {
|
|
648
|
+
promise.reject("LICENSE_ERROR", it.message)
|
|
649
|
+
},
|
|
650
|
+
)
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
override fun updateLicense(promise: Promise) {
|
|
654
|
+
promise.reject(
|
|
655
|
+
"LICENSE_UPDATE_FAILED",
|
|
656
|
+
"The updateLicense method has been deprecated and will be removed in a future release."
|
|
657
|
+
)
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
override fun isInitialized(promise: Promise) {
|
|
661
|
+
try {
|
|
662
|
+
val initialized = serviceManager.getBridgefy()?.isInitialized ?: false
|
|
663
|
+
promise.resolve(initialized)
|
|
664
|
+
} catch (e: Exception) {
|
|
665
|
+
promise.resolve(false)
|
|
396
666
|
}
|
|
397
667
|
}
|
|
398
668
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
else -> null
|
|
669
|
+
override fun isStarted(promise: Promise) {
|
|
670
|
+
try {
|
|
671
|
+
val started = serviceManager.getBridgefy()?.isStarted ?: false
|
|
672
|
+
promise.resolve(started)
|
|
673
|
+
} catch (e: Exception) {
|
|
674
|
+
promise.resolve(false)
|
|
406
675
|
}
|
|
407
676
|
}
|
|
677
|
+
|
|
678
|
+
override fun addListener(eventName: String?) {
|
|
679
|
+
// Required for event emitter
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
override fun removeListeners(count: Double) {
|
|
683
|
+
// Required for event emitter
|
|
684
|
+
}
|
|
408
685
|
}
|