@ionic/portals-react-native 0.0.6 → 0.1.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/ReactNativePortals.podspec +1 -1
- package/android/src/main/java/io/ionic/portals/reactnative/ReactNativePortalsModule.kt +57 -37
- package/ios/Podfile +1 -1
- package/ios/Podfile.lock +12 -12
- package/ios/PortalView.m +1 -2
- package/ios/ReactNativePortals.swift +17 -19
- package/lib/commonjs/index.js +53 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +59 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +79 -1
- package/package.json +1 -1
- package/src/index.ts +80 -1
|
@@ -11,6 +11,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
|
11
11
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
12
12
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
13
13
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
14
|
+
import com.getcapacitor.CapConfig
|
|
14
15
|
import com.getcapacitor.JSObject
|
|
15
16
|
import com.getcapacitor.Plugin
|
|
16
17
|
import io.ionic.liveupdates.LiveUpdate
|
|
@@ -19,16 +20,12 @@ import org.json.JSONArray
|
|
|
19
20
|
import org.json.JSONException
|
|
20
21
|
import org.json.JSONObject
|
|
21
22
|
|
|
22
|
-
internal
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@ReactMethod
|
|
27
|
-
fun register(key: String) {
|
|
28
|
-
PortalManager.register(key)
|
|
29
|
-
}
|
|
23
|
+
internal object RNPortalManager {
|
|
24
|
+
private val manager = PortalManager
|
|
25
|
+
internal var indexMap: MutableMap<String, String> = mutableMapOf()
|
|
26
|
+
lateinit var reactApplicationContext: ReactApplicationContext
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
fun register(key: String) = manager.register(key)
|
|
32
29
|
fun addPortal(map: ReadableMap) {
|
|
33
30
|
val name = map.getString("name") ?: return
|
|
34
31
|
val portalBuilder = PortalBuilder(name)
|
|
@@ -40,6 +37,9 @@ internal class PortalManagerModule(reactContext: ReactApplicationContext) :
|
|
|
40
37
|
?.toHashMap()
|
|
41
38
|
?.let(portalBuilder::setInitialContext)
|
|
42
39
|
|
|
40
|
+
map.getString("index")
|
|
41
|
+
?.let { indexMap[name] = "/$it" }
|
|
42
|
+
|
|
43
43
|
map.getArray("androidPlugins")
|
|
44
44
|
?.toArrayList()
|
|
45
45
|
?.mapNotNull { it as? String }
|
|
@@ -72,6 +72,25 @@ internal class PortalManagerModule(reactContext: ReactApplicationContext) :
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
internal class PortalManagerModule(reactContext: ReactApplicationContext) :
|
|
76
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
77
|
+
override fun getName() = "IONPortalManager"
|
|
78
|
+
|
|
79
|
+
init {
|
|
80
|
+
RNPortalManager.reactApplicationContext = reactContext
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@ReactMethod
|
|
84
|
+
fun register(key: String) {
|
|
85
|
+
RNPortalManager.register(key)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@ReactMethod
|
|
89
|
+
fun addPortal(map: ReadableMap) {
|
|
90
|
+
RNPortalManager.addPortal(map)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
75
94
|
internal class PortalsPubSubModule(reactContext: ReactApplicationContext) :
|
|
76
95
|
ReactContextBaseJavaModule(reactContext) {
|
|
77
96
|
override fun getName() = "IONPortalPubSub"
|
|
@@ -159,27 +178,15 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
|
|
|
159
178
|
private val createId = 1
|
|
160
179
|
private val fragmentMap = mutableMapOf<Int, PortalViewState>()
|
|
161
180
|
|
|
162
|
-
@ReactProp(name = "
|
|
163
|
-
fun setPortal(viewGroup: ViewGroup,
|
|
164
|
-
|
|
165
|
-
null -> fragmentMap[viewGroup.id] = PortalViewState(
|
|
166
|
-
fragment = null,
|
|
167
|
-
portal = PortalManager.getPortal(portalName),
|
|
168
|
-
initialContext = null
|
|
169
|
-
)
|
|
170
|
-
else -> viewState.portal = PortalManager.getPortal(portalName)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
@ReactProp(name = "initialContext")
|
|
175
|
-
fun setInitialContext(viewGroup: ViewGroup, initialContext: ReadableMap) {
|
|
181
|
+
@ReactProp(name = "portal")
|
|
182
|
+
fun setPortal(viewGroup: ViewGroup, portal: ReadableMap) {
|
|
183
|
+
val name = portal.getString("name") ?: return
|
|
176
184
|
when (val viewState = fragmentMap[viewGroup.id]) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
else -> viewState.initialContext = initialContext.toHashMap()
|
|
185
|
+
null -> fragmentMap[viewGroup.id] = PortalViewState(
|
|
186
|
+
fragment = null,
|
|
187
|
+
portal = PortalManager.getPortal(name),
|
|
188
|
+
initialContext = portal.getMap("initialContext")?.toHashMap()
|
|
189
|
+
)
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
192
|
|
|
@@ -189,7 +196,7 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
|
|
|
189
196
|
return FrameLayout(reactContext)
|
|
190
197
|
}
|
|
191
198
|
|
|
192
|
-
override fun getCommandsMap(): MutableMap<String, Int
|
|
199
|
+
override fun getCommandsMap(): MutableMap<String, Int> {
|
|
193
200
|
return mutableMapOf("create" to createId)
|
|
194
201
|
}
|
|
195
202
|
|
|
@@ -213,6 +220,15 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
|
|
|
213
220
|
setupLayout(parentView)
|
|
214
221
|
|
|
215
222
|
val portalFragment = PortalFragment(portal)
|
|
223
|
+
|
|
224
|
+
val configBuilder = CapConfig.Builder(context)
|
|
225
|
+
.setInitialFocus(false)
|
|
226
|
+
|
|
227
|
+
RNPortalManager.indexMap[portal.name]
|
|
228
|
+
?.let(configBuilder::setStartPath)
|
|
229
|
+
|
|
230
|
+
portalFragment.setConfig(configBuilder.create())
|
|
231
|
+
|
|
216
232
|
viewState.initialContext?.let(portalFragment::setInitialContext)
|
|
217
233
|
|
|
218
234
|
viewState.fragment = portalFragment
|
|
@@ -241,7 +257,7 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
|
|
|
241
257
|
fragmentMap.remove(view.id)
|
|
242
258
|
}
|
|
243
259
|
|
|
244
|
-
private fun setupLayout(view:
|
|
260
|
+
private fun setupLayout(view: ViewGroup) {
|
|
245
261
|
Choreographer.getInstance().postFrameCallback(object : Choreographer.FrameCallback {
|
|
246
262
|
override fun doFrame(frameTimeNanos: Long) {
|
|
247
263
|
layoutPortal(view)
|
|
@@ -251,12 +267,16 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
|
|
|
251
267
|
})
|
|
252
268
|
}
|
|
253
269
|
|
|
254
|
-
private fun layoutPortal(view:
|
|
255
|
-
view.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
270
|
+
private fun layoutPortal(view: ViewGroup) {
|
|
271
|
+
for (i in 0 until view.childCount) {
|
|
272
|
+
val child = view.getChildAt(i)
|
|
273
|
+
|
|
274
|
+
child.measure(
|
|
275
|
+
View.MeasureSpec.makeMeasureSpec(view.measuredWidth, View.MeasureSpec.EXACTLY),
|
|
276
|
+
View.MeasureSpec.makeMeasureSpec(view.measuredHeight, View.MeasureSpec.EXACTLY)
|
|
277
|
+
)
|
|
259
278
|
|
|
260
|
-
|
|
279
|
+
child.layout(0, 0, child.measuredWidth, child.measuredHeight)
|
|
280
|
+
}
|
|
261
281
|
}
|
|
262
282
|
}
|
package/ios/Podfile
CHANGED
package/ios/Podfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PODS:
|
|
2
2
|
- boost-for-react-native (1.63.0)
|
|
3
|
-
- Capacitor (3.
|
|
3
|
+
- Capacitor (3.7.0):
|
|
4
4
|
- CapacitorCordova
|
|
5
|
-
- CapacitorCordova (3.
|
|
5
|
+
- CapacitorCordova (3.7.0)
|
|
6
6
|
- DoubleConversion (1.1.6)
|
|
7
7
|
- FBLazyVector (0.63.4)
|
|
8
8
|
- FBReactNativeSpec (0.63.4):
|
|
@@ -22,10 +22,10 @@ PODS:
|
|
|
22
22
|
- DoubleConversion
|
|
23
23
|
- glog
|
|
24
24
|
- glog (0.3.5)
|
|
25
|
-
- IonicLiveUpdates (0.1.
|
|
26
|
-
- IonicPortals (0.6.
|
|
27
|
-
- Capacitor (~> 3.
|
|
28
|
-
- IonicLiveUpdates (~> 0.1.
|
|
25
|
+
- IonicLiveUpdates (0.1.3)
|
|
26
|
+
- IonicPortals (0.6.3):
|
|
27
|
+
- Capacitor (~> 3.7)
|
|
28
|
+
- IonicLiveUpdates (~> 0.1.2)
|
|
29
29
|
- RCTRequired (0.63.4)
|
|
30
30
|
- RCTTypeSafety (0.63.4):
|
|
31
31
|
- FBLazyVector (= 0.63.4)
|
|
@@ -260,7 +260,7 @@ DEPENDENCIES:
|
|
|
260
260
|
- FBReactNativeSpec (from `../node_modules/react-native/Libraries/FBReactNativeSpec`)
|
|
261
261
|
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
|
|
262
262
|
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
|
|
263
|
-
- IonicPortals (~> 0.6.
|
|
263
|
+
- IonicPortals (~> 0.6.3)
|
|
264
264
|
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
|
|
265
265
|
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
|
|
266
266
|
- React (from `../node_modules/react-native/`)
|
|
@@ -349,15 +349,15 @@ EXTERNAL SOURCES:
|
|
|
349
349
|
|
|
350
350
|
SPEC CHECKSUMS:
|
|
351
351
|
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
|
|
352
|
-
Capacitor:
|
|
353
|
-
CapacitorCordova:
|
|
352
|
+
Capacitor: 747a1e47077e8f82abf2209867c440d7366ad68c
|
|
353
|
+
CapacitorCordova: e6b42a8e8d5986c1eb8f02ac0be205fafc32ac33
|
|
354
354
|
DoubleConversion: cde416483dac037923206447da6e1454df403714
|
|
355
355
|
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
|
|
356
356
|
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
|
|
357
357
|
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
|
|
358
358
|
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
|
|
359
|
-
IonicLiveUpdates:
|
|
360
|
-
IonicPortals:
|
|
359
|
+
IonicLiveUpdates: 91481e88b9a9a9bc02aecc589ed4bcfd658c4854
|
|
360
|
+
IonicPortals: 752f740cfaf84fafd45c0d9ab7b06c6b2a281993
|
|
361
361
|
RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
|
|
362
362
|
RCTTypeSafety: 8c9c544ecbf20337d069e4ae7fd9a377aadf504b
|
|
363
363
|
React: b0a957a2c44da4113b0c4c9853d8387f8e64e615
|
|
@@ -380,6 +380,6 @@ SPEC CHECKSUMS:
|
|
|
380
380
|
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
|
|
381
381
|
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
|
|
382
382
|
|
|
383
|
-
PODFILE CHECKSUM:
|
|
383
|
+
PODFILE CHECKSUM: d6df5af67dbc83914b551c00dd0fbfac38c74589
|
|
384
384
|
|
|
385
385
|
COCOAPODS: 1.11.2
|
package/ios/PortalView.m
CHANGED
|
@@ -9,6 +9,5 @@
|
|
|
9
9
|
#import <React/RCTViewManager.h>
|
|
10
10
|
|
|
11
11
|
@interface RCT_EXTERN_MODULE(IONPortalViewManager, RCTViewManager)
|
|
12
|
-
RCT_EXPORT_VIEW_PROPERTY(
|
|
13
|
-
RCT_EXPORT_VIEW_PROPERTY(initialContext, NSDictionary)
|
|
12
|
+
RCT_EXPORT_VIEW_PROPERTY(portal, NSDictionary)
|
|
14
13
|
@end
|
|
@@ -74,36 +74,33 @@ class PortalViewManager: RCTViewManager {
|
|
|
74
74
|
|
|
75
75
|
class PortalView: UIView {
|
|
76
76
|
private var webView: PortalUIView?
|
|
77
|
-
private var _initialContext: [String: JSValue]?
|
|
78
77
|
|
|
79
|
-
@objc var
|
|
78
|
+
@objc var portal: [String: Any]? {
|
|
80
79
|
get {
|
|
81
80
|
guard let _portal = _portal else { return nil }
|
|
82
|
-
return
|
|
81
|
+
return [
|
|
82
|
+
"name": _portal.name,
|
|
83
|
+
"initialContext": _portal.initialContext
|
|
84
|
+
]
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
set {
|
|
86
|
-
guard let
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
_portal?.initialContext = _initialContext ?? [:]
|
|
88
|
+
guard let portalDict = newValue,
|
|
89
|
+
let name = portalDict["name"] as? String
|
|
90
|
+
else { return }
|
|
91
|
+
|
|
92
|
+
var portal = PortalManager.getPortal(named: name)
|
|
93
|
+
if let initialContext = portalDict["initialContext"] as? [String: Any] {
|
|
94
|
+
portal?.initialContext = JSTypes.coerceDictionaryToJSObject(initialContext) ?? [:]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_portal = portal
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
private var _portal: Portal? {
|
|
101
102
|
didSet {
|
|
102
|
-
guard
|
|
103
|
-
|
|
104
|
-
if let initialContext = _initialContext {
|
|
105
|
-
portal.initialContext = initialContext
|
|
106
|
-
}
|
|
103
|
+
guard let portal = _portal else { return }
|
|
107
104
|
|
|
108
105
|
DispatchQueue.main.async { [weak self] in
|
|
109
106
|
guard let self = self else { return }
|
|
@@ -129,6 +126,7 @@ extension Portal {
|
|
|
129
126
|
self.init(
|
|
130
127
|
name: name,
|
|
131
128
|
startDir: dict["startDir"] as? String,
|
|
129
|
+
index: dict["index"] as? String ?? "index.html",
|
|
132
130
|
initialContext: JSTypes.coerceDictionaryToJSObject(dict["initialContext"] as? [String: Any]) ?? [:],
|
|
133
131
|
liveUpdateConfig: (dict["liveUpdate"] as? [String: Any]).flatMap(LiveUpdate.init)
|
|
134
132
|
)
|
package/lib/commonjs/index.js
CHANGED
|
@@ -24,6 +24,13 @@ const {
|
|
|
24
24
|
} = _reactNative.NativeModules;
|
|
25
25
|
const PortalsPubSub = new _reactNative.NativeEventEmitter(IONPortalPubSub);
|
|
26
26
|
const subscriptionMap = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* Subscribes to messages for a topic
|
|
29
|
+
*
|
|
30
|
+
* @param topic The topic to subscribe to
|
|
31
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
32
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
33
|
+
*/
|
|
27
34
|
|
|
28
35
|
const subscribe = async (topic, onMessageReceived) => {
|
|
29
36
|
const subscriptionRef = await IONPortalPubSub.subscribe(topic);
|
|
@@ -35,6 +42,13 @@ const subscribe = async (topic, onMessageReceived) => {
|
|
|
35
42
|
subscriptionMap.set(subscriptionRef, subscriber);
|
|
36
43
|
return subscriptionRef;
|
|
37
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
47
|
+
*
|
|
48
|
+
* @param topic The topic to unsubscribe from
|
|
49
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
50
|
+
*/
|
|
51
|
+
|
|
38
52
|
|
|
39
53
|
exports.subscribe = subscribe;
|
|
40
54
|
|
|
@@ -47,6 +61,13 @@ const unsubscribe = (topic, subRef) => {
|
|
|
47
61
|
subscriptionMap.delete(subRef);
|
|
48
62
|
}
|
|
49
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Publishes a message to the provided topic
|
|
66
|
+
*
|
|
67
|
+
* @param topic The topic to publish the message to
|
|
68
|
+
* @param data The data to publish to subscribers
|
|
69
|
+
*/
|
|
70
|
+
|
|
50
71
|
|
|
51
72
|
exports.unsubscribe = unsubscribe;
|
|
52
73
|
|
|
@@ -56,30 +77,62 @@ const publish = (topic, data) => {
|
|
|
56
77
|
};
|
|
57
78
|
IONPortalPubSub.publish(topic, msg);
|
|
58
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
82
|
+
* @param key The registration key
|
|
83
|
+
*/
|
|
84
|
+
|
|
59
85
|
|
|
60
86
|
exports.publish = publish;
|
|
61
87
|
|
|
62
88
|
const register = key => {
|
|
63
89
|
IONPortalManager.register(key);
|
|
64
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
93
|
+
*/
|
|
94
|
+
|
|
65
95
|
|
|
66
96
|
exports.register = register;
|
|
67
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
100
|
+
*
|
|
101
|
+
* @param portal The portal to add to the internal registry.
|
|
102
|
+
*/
|
|
68
103
|
const addPortal = portal => {
|
|
69
104
|
IONPortalManager.addPortal(portal);
|
|
70
105
|
};
|
|
71
106
|
|
|
72
107
|
exports.addPortal = addPortal;
|
|
73
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Syncs a single live update.
|
|
111
|
+
*
|
|
112
|
+
* @param appId The AppFlow application ID to sync.
|
|
113
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
114
|
+
*/
|
|
74
115
|
const syncOne = appId => {
|
|
75
116
|
return IONLiveUpdatesManager.syncOne(appId);
|
|
76
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* Syncs many live updates.
|
|
120
|
+
*
|
|
121
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
122
|
+
* @returns Promise<SyncResults>
|
|
123
|
+
*/
|
|
124
|
+
|
|
77
125
|
|
|
78
126
|
exports.syncOne = syncOne;
|
|
79
127
|
|
|
80
128
|
const syncSome = appIds => {
|
|
81
129
|
return IONLiveUpdatesManager.syncSome(appIds);
|
|
82
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* Syncs all registered LiveUpdates
|
|
133
|
+
* @returns Promise<SyncResults>
|
|
134
|
+
*/
|
|
135
|
+
|
|
83
136
|
|
|
84
137
|
exports.syncSome = syncSome;
|
|
85
138
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n androidPlugins?: string[];\n startDir?: string;\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport type
|
|
1
|
+
{"version":3,"names":["IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\n/**\n * The data that is received from a subscription event.\n */\nexport interface Message {\n /** The unique subscription reference received from {@link subscribe}*/\n subscriptionRef: number;\n data: any;\n /** The topic the message was sent from */\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\n/**\n * Subscribes to messages for a topic\n *\n * @param topic The topic to subscribe to\n * @param onMessageReceived The callback to invoke when a message is received\n * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.\n */\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\n/**\n * Unsubscribes from events for the provided topic and subscription reference\n *\n * @param topic The topic to unsubscribe from\n * @param subRef The unique subscription reference received when initially calling {@link subscribe}\n */\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\n/**\n * Publishes a message to the provided topic\n *\n * @param topic The topic to publish the message to\n * @param data The data to publish to subscribers\n */\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\n/**\n * Validates that a valid registration key has been procured from http://ionic.io/register-portals\n * @param key The registration key\n */\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\n/**\n * The configuration of a web application to be embedded in a React Native application.\n */\nexport interface Portal {\n /** The name of the Portal to be referenced. Must be **unique** */\n name: string;\n /** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidPlugins?: string[];\n /**\n * The root directory of the web application relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, `name` is used.\n */\n startDir?: string;\n /** The name of the initial file to load. If omitted, 'index.html' is used. */\n index?: string;\n /** Any data needed at initial render when a portal is loaded. */\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\n/**\n * A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override\n * any initialContext defined in the original {@link Portal} definition.\n */\nexport type PortalProp = {\n portal: Pick<Portal, 'name' | 'initialContext'>;\n};\n\n/**\n * Props needed for rendering a {@link Portal}\n */\nexport type PortalProps = PortalProp & ViewProps;\n\n/**\n * Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.\n *\n * @param portal The portal to add to the internal registry.\n */\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n\nexport interface LiveUpdate {\n /** The AppFlow application ID */\n appId: string;\n /** The AppFlow distribution channel */\n channel: string;\n}\n\n/** Data needed to register a live update to be managed */\nexport type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };\n\nexport interface LiveUpdateError {\n /** The AppFlow application ID relating to the failure */\n appId: string;\n /** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/\n failStep: string;\n /** A human readable error message */\n message: string;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n liveUpdates: LiveUpdate[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Syncs a single live update.\n *\n * @param appId The AppFlow application ID to sync.\n * @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.\n */\nexport const syncOne = (appId: string): Promise<LiveUpdate> => {\n return IONLiveUpdatesManager.syncOne(appId);\n};\n\n/**\n * Syncs many live updates.\n *\n * @param appIds The AppFlow application IDs to sync.\n * @returns Promise<SyncResults>\n */\nexport const syncSome = (appIds: string[]): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = (): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncAll();\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAUA;;;;AAHA,MAAM;EAAEA,eAAF;EAAmBC,gBAAnB;EAAqCC;AAArC,IACJC,0BADF;AAgBA,MAAMC,aAAa,GAAG,IAAIC,+BAAJ,CAAuBL,eAAvB,CAAtB;AAEA,MAAMM,eAAe,GAAG,IAAIC,GAAJ,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMX,eAAe,CAACQ,SAAhB,CAA0BC,KAA1B,CAA9B;EAEA,MAAMG,UAAU,GAAGR,aAAa,CAACS,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACH,eAAR,KAA4BA,eAAhC,EAAiD;MAC/CD,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DjB,eAAe,CAACgB,WAAhB,CAA4BP,KAA5B,EAAmCQ,MAAnC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;AAUP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAxB,eAAe,CAACuB,OAAhB,CAAwBd,KAAxB,EAA+BgB,GAA/B;AACD,CAHM;AAKP;AACA;AACA;AACA;;;;;AACO,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvC1B,gBAAgB,CAACyB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAIP;AACA;AACA;;;;;AAiCA;AACA;AACA;AACA;AACA;AACO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C5B,gBAAgB,CAAC2B,SAAjB,CAA2BC,MAA3B;AACD,CAFM;;;;AA6BP;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,OAAO,GAAIC,KAAD,IAAwC;EAC7D,OAAO7B,qBAAqB,CAAC4B,OAAtB,CAA8BC,KAA9B,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,QAAQ,GAAIC,MAAD,IAA4C;EAClE,OAAO/B,qBAAqB,CAAC8B,QAAtB,CAA+BC,MAA/B,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAMC,OAAO,GAAG,MAA4B;EACjD,OAAOhC,qBAAqB,CAACgC,OAAtB,EAAP;AACD,CAFM"}
|
package/lib/module/index.js
CHANGED
|
@@ -5,8 +5,20 @@ const {
|
|
|
5
5
|
IONLiveUpdatesManager
|
|
6
6
|
} = NativeModules;
|
|
7
7
|
export { default as PortalView } from './PortalView';
|
|
8
|
+
/**
|
|
9
|
+
* The data that is received from a subscription event.
|
|
10
|
+
*/
|
|
11
|
+
|
|
8
12
|
const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
|
|
9
13
|
const subscriptionMap = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Subscribes to messages for a topic
|
|
16
|
+
*
|
|
17
|
+
* @param topic The topic to subscribe to
|
|
18
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
19
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
20
|
+
*/
|
|
21
|
+
|
|
10
22
|
export const subscribe = async (topic, onMessageReceived) => {
|
|
11
23
|
const subscriptionRef = await IONPortalPubSub.subscribe(topic);
|
|
12
24
|
const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
|
|
@@ -17,6 +29,13 @@ export const subscribe = async (topic, onMessageReceived) => {
|
|
|
17
29
|
subscriptionMap.set(subscriptionRef, subscriber);
|
|
18
30
|
return subscriptionRef;
|
|
19
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
34
|
+
*
|
|
35
|
+
* @param topic The topic to unsubscribe from
|
|
36
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
37
|
+
*/
|
|
38
|
+
|
|
20
39
|
export const unsubscribe = (topic, subRef) => {
|
|
21
40
|
IONPortalPubSub.unsubscribe(topic, subRef);
|
|
22
41
|
const subscription = subscriptionMap.get(subRef);
|
|
@@ -26,24 +45,64 @@ export const unsubscribe = (topic, subRef) => {
|
|
|
26
45
|
subscriptionMap.delete(subRef);
|
|
27
46
|
}
|
|
28
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Publishes a message to the provided topic
|
|
50
|
+
*
|
|
51
|
+
* @param topic The topic to publish the message to
|
|
52
|
+
* @param data The data to publish to subscribers
|
|
53
|
+
*/
|
|
54
|
+
|
|
29
55
|
export const publish = (topic, data) => {
|
|
30
56
|
const msg = {
|
|
31
57
|
message: data
|
|
32
58
|
};
|
|
33
59
|
IONPortalPubSub.publish(topic, msg);
|
|
34
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
63
|
+
* @param key The registration key
|
|
64
|
+
*/
|
|
65
|
+
|
|
35
66
|
export const register = key => {
|
|
36
67
|
IONPortalManager.register(key);
|
|
37
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
75
|
+
*
|
|
76
|
+
* @param portal The portal to add to the internal registry.
|
|
77
|
+
*/
|
|
38
78
|
export const addPortal = portal => {
|
|
39
79
|
IONPortalManager.addPortal(portal);
|
|
40
80
|
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Syncs a single live update.
|
|
84
|
+
*
|
|
85
|
+
* @param appId The AppFlow application ID to sync.
|
|
86
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
87
|
+
*/
|
|
41
88
|
export const syncOne = appId => {
|
|
42
89
|
return IONLiveUpdatesManager.syncOne(appId);
|
|
43
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Syncs many live updates.
|
|
93
|
+
*
|
|
94
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
95
|
+
* @returns Promise<SyncResults>
|
|
96
|
+
*/
|
|
97
|
+
|
|
44
98
|
export const syncSome = appIds => {
|
|
45
99
|
return IONLiveUpdatesManager.syncSome(appIds);
|
|
46
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Syncs all registered LiveUpdates
|
|
103
|
+
* @returns Promise<SyncResults>
|
|
104
|
+
*/
|
|
105
|
+
|
|
47
106
|
export const syncAll = () => {
|
|
48
107
|
return IONLiveUpdatesManager.syncAll();
|
|
49
108
|
};
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\nexport interface Message {\n subscriptionRef: number;\n data: any;\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\nexport interface Portal {\n name: string;\n androidPlugins?: string[];\n startDir?: string;\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport type
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","NativeModules","IONPortalPubSub","IONPortalManager","IONLiveUpdatesManager","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =\n NativeModules;\n\nexport { default as PortalView } from './PortalView';\n\n/**\n * The data that is received from a subscription event.\n */\nexport interface Message {\n /** The unique subscription reference received from {@link subscribe}*/\n subscriptionRef: number;\n data: any;\n /** The topic the message was sent from */\n topic: string;\n}\n\nconst PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);\n\nconst subscriptionMap = new Map<number, EmitterSubscription>();\n\n/**\n * Subscribes to messages for a topic\n *\n * @param topic The topic to subscribe to\n * @param onMessageReceived The callback to invoke when a message is received\n * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.\n */\nexport const subscribe = async (\n topic: string,\n onMessageReceived: (message: Message) => void\n): Promise<number> => {\n const subscriptionRef = await IONPortalPubSub.subscribe(topic);\n\n const subscriber = PortalsPubSub.addListener(\n 'PortalsSubscription',\n (message: Message) => {\n if (message.subscriptionRef === subscriptionRef) {\n onMessageReceived(message);\n }\n }\n );\n\n subscriptionMap.set(subscriptionRef, subscriber);\n\n return subscriptionRef;\n};\n\n/**\n * Unsubscribes from events for the provided topic and subscription reference\n *\n * @param topic The topic to unsubscribe from\n * @param subRef The unique subscription reference received when initially calling {@link subscribe}\n */\nexport const unsubscribe = (topic: string, subRef: number) => {\n IONPortalPubSub.unsubscribe(topic, subRef);\n\n const subscription = subscriptionMap.get(subRef);\n if (subscription !== undefined) {\n subscription.remove();\n subscriptionMap.delete(subRef);\n }\n};\n\n/**\n * Publishes a message to the provided topic\n *\n * @param topic The topic to publish the message to\n * @param data The data to publish to subscribers\n */\nexport const publish = (topic: string, data: any) => {\n const msg = { message: data };\n IONPortalPubSub.publish(topic, msg);\n};\n\n/**\n * Validates that a valid registration key has been procured from http://ionic.io/register-portals\n * @param key The registration key\n */\nexport const register = (key: string) => {\n IONPortalManager.register(key);\n};\n\n/**\n * The configuration of a web application to be embedded in a React Native application.\n */\nexport interface Portal {\n /** The name of the Portal to be referenced. Must be **unique** */\n name: string;\n /** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidPlugins?: string[];\n /**\n * The root directory of the web application relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, `name` is used.\n */\n startDir?: string;\n /** The name of the initial file to load. If omitted, 'index.html' is used. */\n index?: string;\n /** Any data needed at initial render when a portal is loaded. */\n initialContext?: {\n [key: string]: any;\n };\n liveUpdate?: LiveUpdateConfig;\n}\n\n/**\n * A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override\n * any initialContext defined in the original {@link Portal} definition.\n */\nexport type PortalProp = {\n portal: Pick<Portal, 'name' | 'initialContext'>;\n};\n\n/**\n * Props needed for rendering a {@link Portal}\n */\nexport type PortalProps = PortalProp & ViewProps;\n\n/**\n * Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.\n *\n * @param portal The portal to add to the internal registry.\n */\nexport const addPortal = (portal: Portal) => {\n IONPortalManager.addPortal(portal);\n};\n\nexport interface LiveUpdate {\n /** The AppFlow application ID */\n appId: string;\n /** The AppFlow distribution channel */\n channel: string;\n}\n\n/** Data needed to register a live update to be managed */\nexport type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };\n\nexport interface LiveUpdateError {\n /** The AppFlow application ID relating to the failure */\n appId: string;\n /** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/\n failStep: string;\n /** A human readable error message */\n message: string;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n liveUpdates: LiveUpdate[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Syncs a single live update.\n *\n * @param appId The AppFlow application ID to sync.\n * @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.\n */\nexport const syncOne = (appId: string): Promise<LiveUpdate> => {\n return IONLiveUpdatesManager.syncOne(appId);\n};\n\n/**\n * Syncs many live updates.\n *\n * @param appIds The AppFlow application IDs to sync.\n * @returns Promise<SyncResults>\n */\nexport const syncSome = (appIds: string[]): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = (): Promise<SyncResults> => {\n return IONLiveUpdatesManager.syncAll();\n};\n"],"mappings":"AAAA,SAEEA,kBAFF,EAGEC,aAHF,QAKO,cALP;AAOA,MAAM;EAAEC,eAAF;EAAmBC,gBAAnB;EAAqCC;AAArC,IACJH,aADF;AAGA,SAASI,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AAEA;AACA;AACA;;AASA,MAAMC,aAAa,GAAG,IAAIP,kBAAJ,CAAuBE,eAAvB,CAAtB;AAEA,MAAMM,eAAe,GAAG,IAAIC,GAAJ,EAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,SAAS,GAAG,OACvBC,KADuB,EAEvBC,iBAFuB,KAGH;EACpB,MAAMC,eAAe,GAAG,MAAMX,eAAe,CAACQ,SAAhB,CAA0BC,KAA1B,CAA9B;EAEA,MAAMG,UAAU,GAAGP,aAAa,CAACQ,WAAd,CACjB,qBADiB,EAEhBC,OAAD,IAAsB;IACpB,IAAIA,OAAO,CAACH,eAAR,KAA4BA,eAAhC,EAAiD;MAC/CD,iBAAiB,CAACI,OAAD,CAAjB;IACD;EACF,CANgB,CAAnB;EASAR,eAAe,CAACS,GAAhB,CAAoBJ,eAApB,EAAqCC,UAArC;EAEA,OAAOD,eAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMK,WAAW,GAAG,CAACP,KAAD,EAAgBQ,MAAhB,KAAmC;EAC5DjB,eAAe,CAACgB,WAAhB,CAA4BP,KAA5B,EAAmCQ,MAAnC;EAEA,MAAMC,YAAY,GAAGZ,eAAe,CAACa,GAAhB,CAAoBF,MAApB,CAArB;;EACA,IAAIC,YAAY,KAAKE,SAArB,EAAgC;IAC9BF,YAAY,CAACG,MAAb;IACAf,eAAe,CAACgB,MAAhB,CAAuBL,MAAvB;EACD;AACF,CARM;AAUP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMM,OAAO,GAAG,CAACd,KAAD,EAAgBe,IAAhB,KAA8B;EACnD,MAAMC,GAAG,GAAG;IAAEX,OAAO,EAAEU;EAAX,CAAZ;EACAxB,eAAe,CAACuB,OAAhB,CAAwBd,KAAxB,EAA+BgB,GAA/B;AACD,CAHM;AAKP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,QAAQ,GAAIC,GAAD,IAAiB;EACvC1B,gBAAgB,CAACyB,QAAjB,CAA0BC,GAA1B;AACD,CAFM;AAIP;AACA;AACA;;AAiCA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAIC,MAAD,IAAoB;EAC3C5B,gBAAgB,CAAC2B,SAAjB,CAA2BC,MAA3B;AACD,CAFM;;AA6BP;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAIC,KAAD,IAAwC;EAC7D,OAAO7B,qBAAqB,CAAC4B,OAAtB,CAA8BC,KAA9B,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,QAAQ,GAAIC,MAAD,IAA4C;EAClE,OAAO/B,qBAAqB,CAAC8B,QAAtB,CAA+BC,MAA/B,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,OAAO,GAAG,MAA4B;EACjD,OAAOhC,qBAAqB,CAACgC,OAAtB,EAAP;AACD,CAFM"}
|
|
@@ -1,41 +1,119 @@
|
|
|
1
1
|
import { ViewProps } from 'react-native';
|
|
2
2
|
export { default as PortalView } from './PortalView';
|
|
3
|
+
/**
|
|
4
|
+
* The data that is received from a subscription event.
|
|
5
|
+
*/
|
|
3
6
|
export interface Message {
|
|
7
|
+
/** The unique subscription reference received from {@link subscribe}*/
|
|
4
8
|
subscriptionRef: number;
|
|
5
9
|
data: any;
|
|
10
|
+
/** The topic the message was sent from */
|
|
6
11
|
topic: string;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Subscribes to messages for a topic
|
|
15
|
+
*
|
|
16
|
+
* @param topic The topic to subscribe to
|
|
17
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
18
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
19
|
+
*/
|
|
8
20
|
export declare const subscribe: (topic: string, onMessageReceived: (message: Message) => void) => Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
23
|
+
*
|
|
24
|
+
* @param topic The topic to unsubscribe from
|
|
25
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
26
|
+
*/
|
|
9
27
|
export declare const unsubscribe: (topic: string, subRef: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Publishes a message to the provided topic
|
|
30
|
+
*
|
|
31
|
+
* @param topic The topic to publish the message to
|
|
32
|
+
* @param data The data to publish to subscribers
|
|
33
|
+
*/
|
|
10
34
|
export declare const publish: (topic: string, data: any) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
37
|
+
* @param key The registration key
|
|
38
|
+
*/
|
|
11
39
|
export declare const register: (key: string) => void;
|
|
40
|
+
/**
|
|
41
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
42
|
+
*/
|
|
12
43
|
export interface Portal {
|
|
44
|
+
/** The name of the Portal to be referenced. Must be **unique** */
|
|
13
45
|
name: string;
|
|
46
|
+
/** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */
|
|
14
47
|
androidPlugins?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* The root directory of the web application relative to Bundle.main on iOS
|
|
50
|
+
* and src/main/assets on Android. If omitted, `name` is used.
|
|
51
|
+
*/
|
|
15
52
|
startDir?: string;
|
|
53
|
+
/** The name of the initial file to load. If omitted, 'index.html' is used. */
|
|
54
|
+
index?: string;
|
|
55
|
+
/** Any data needed at initial render when a portal is loaded. */
|
|
16
56
|
initialContext?: {
|
|
17
57
|
[key: string]: any;
|
|
18
58
|
};
|
|
19
59
|
liveUpdate?: LiveUpdateConfig;
|
|
20
60
|
}
|
|
21
|
-
|
|
61
|
+
/**
|
|
62
|
+
* A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override
|
|
63
|
+
* any initialContext defined in the original {@link Portal} definition.
|
|
64
|
+
*/
|
|
65
|
+
export declare type PortalProp = {
|
|
66
|
+
portal: Pick<Portal, 'name' | 'initialContext'>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Props needed for rendering a {@link Portal}
|
|
70
|
+
*/
|
|
71
|
+
export declare type PortalProps = PortalProp & ViewProps;
|
|
72
|
+
/**
|
|
73
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
74
|
+
*
|
|
75
|
+
* @param portal The portal to add to the internal registry.
|
|
76
|
+
*/
|
|
22
77
|
export declare const addPortal: (portal: Portal) => void;
|
|
23
78
|
export interface LiveUpdate {
|
|
79
|
+
/** The AppFlow application ID */
|
|
24
80
|
appId: string;
|
|
81
|
+
/** The AppFlow distribution channel */
|
|
25
82
|
channel: string;
|
|
26
83
|
}
|
|
84
|
+
/** Data needed to register a live update to be managed */
|
|
27
85
|
export declare type LiveUpdateConfig = LiveUpdate & {
|
|
28
86
|
syncOnAdd: boolean;
|
|
29
87
|
};
|
|
30
88
|
export interface LiveUpdateError {
|
|
89
|
+
/** The AppFlow application ID relating to the failure */
|
|
31
90
|
appId: string;
|
|
91
|
+
/** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
|
|
32
92
|
failStep: string;
|
|
93
|
+
/** A human readable error message */
|
|
33
94
|
message: string;
|
|
34
95
|
}
|
|
96
|
+
/** Used for communicating sync results of multiple live updates */
|
|
35
97
|
export interface SyncResults {
|
|
36
98
|
liveUpdates: LiveUpdate[];
|
|
37
99
|
errors: LiveUpdateError[];
|
|
38
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Syncs a single live update.
|
|
103
|
+
*
|
|
104
|
+
* @param appId The AppFlow application ID to sync.
|
|
105
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
106
|
+
*/
|
|
39
107
|
export declare const syncOne: (appId: string) => Promise<LiveUpdate>;
|
|
108
|
+
/**
|
|
109
|
+
* Syncs many live updates.
|
|
110
|
+
*
|
|
111
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
112
|
+
* @returns Promise<SyncResults>
|
|
113
|
+
*/
|
|
40
114
|
export declare const syncSome: (appIds: string[]) => Promise<SyncResults>;
|
|
115
|
+
/**
|
|
116
|
+
* Syncs all registered LiveUpdates
|
|
117
|
+
* @returns Promise<SyncResults>
|
|
118
|
+
*/
|
|
41
119
|
export declare const syncAll: () => Promise<SyncResults>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,9 +10,14 @@ const { IONPortalPubSub, IONPortalManager, IONLiveUpdatesManager } =
|
|
|
10
10
|
|
|
11
11
|
export { default as PortalView } from './PortalView';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The data that is received from a subscription event.
|
|
15
|
+
*/
|
|
13
16
|
export interface Message {
|
|
17
|
+
/** The unique subscription reference received from {@link subscribe}*/
|
|
14
18
|
subscriptionRef: number;
|
|
15
19
|
data: any;
|
|
20
|
+
/** The topic the message was sent from */
|
|
16
21
|
topic: string;
|
|
17
22
|
}
|
|
18
23
|
|
|
@@ -20,6 +25,13 @@ const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
|
|
|
20
25
|
|
|
21
26
|
const subscriptionMap = new Map<number, EmitterSubscription>();
|
|
22
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Subscribes to messages for a topic
|
|
30
|
+
*
|
|
31
|
+
* @param topic The topic to subscribe to
|
|
32
|
+
* @param onMessageReceived The callback to invoke when a message is received
|
|
33
|
+
* @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
|
|
34
|
+
*/
|
|
23
35
|
export const subscribe = async (
|
|
24
36
|
topic: string,
|
|
25
37
|
onMessageReceived: (message: Message) => void
|
|
@@ -40,6 +52,12 @@ export const subscribe = async (
|
|
|
40
52
|
return subscriptionRef;
|
|
41
53
|
};
|
|
42
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Unsubscribes from events for the provided topic and subscription reference
|
|
57
|
+
*
|
|
58
|
+
* @param topic The topic to unsubscribe from
|
|
59
|
+
* @param subRef The unique subscription reference received when initially calling {@link subscribe}
|
|
60
|
+
*/
|
|
43
61
|
export const unsubscribe = (topic: string, subRef: number) => {
|
|
44
62
|
IONPortalPubSub.unsubscribe(topic, subRef);
|
|
45
63
|
|
|
@@ -50,57 +68,118 @@ export const unsubscribe = (topic: string, subRef: number) => {
|
|
|
50
68
|
}
|
|
51
69
|
};
|
|
52
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Publishes a message to the provided topic
|
|
73
|
+
*
|
|
74
|
+
* @param topic The topic to publish the message to
|
|
75
|
+
* @param data The data to publish to subscribers
|
|
76
|
+
*/
|
|
53
77
|
export const publish = (topic: string, data: any) => {
|
|
54
78
|
const msg = { message: data };
|
|
55
79
|
IONPortalPubSub.publish(topic, msg);
|
|
56
80
|
};
|
|
57
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Validates that a valid registration key has been procured from http://ionic.io/register-portals
|
|
84
|
+
* @param key The registration key
|
|
85
|
+
*/
|
|
58
86
|
export const register = (key: string) => {
|
|
59
87
|
IONPortalManager.register(key);
|
|
60
88
|
};
|
|
61
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The configuration of a web application to be embedded in a React Native application.
|
|
92
|
+
*/
|
|
62
93
|
export interface Portal {
|
|
94
|
+
/** The name of the Portal to be referenced. Must be **unique** */
|
|
63
95
|
name: string;
|
|
96
|
+
/** The classpath of all Capacitor plugins used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */
|
|
64
97
|
androidPlugins?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* The root directory of the web application relative to Bundle.main on iOS
|
|
100
|
+
* and src/main/assets on Android. If omitted, `name` is used.
|
|
101
|
+
*/
|
|
65
102
|
startDir?: string;
|
|
103
|
+
/** The name of the initial file to load. If omitted, 'index.html' is used. */
|
|
104
|
+
index?: string;
|
|
105
|
+
/** Any data needed at initial render when a portal is loaded. */
|
|
66
106
|
initialContext?: {
|
|
67
107
|
[key: string]: any;
|
|
68
108
|
};
|
|
69
109
|
liveUpdate?: LiveUpdateConfig;
|
|
70
110
|
}
|
|
71
111
|
|
|
72
|
-
|
|
112
|
+
/**
|
|
113
|
+
* A subset of {@link Portal} properties needed for rendering a Portal. `initialContext` can be used to override
|
|
114
|
+
* any initialContext defined in the original {@link Portal} definition.
|
|
115
|
+
*/
|
|
116
|
+
export type PortalProp = {
|
|
117
|
+
portal: Pick<Portal, 'name' | 'initialContext'>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Props needed for rendering a {@link Portal}
|
|
122
|
+
*/
|
|
123
|
+
export type PortalProps = PortalProp & ViewProps;
|
|
73
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Adds a Portal to an internal registry. Must be called before attempting to render a {@link PortalView}.
|
|
127
|
+
*
|
|
128
|
+
* @param portal The portal to add to the internal registry.
|
|
129
|
+
*/
|
|
74
130
|
export const addPortal = (portal: Portal) => {
|
|
75
131
|
IONPortalManager.addPortal(portal);
|
|
76
132
|
};
|
|
77
133
|
|
|
78
134
|
export interface LiveUpdate {
|
|
135
|
+
/** The AppFlow application ID */
|
|
79
136
|
appId: string;
|
|
137
|
+
/** The AppFlow distribution channel */
|
|
80
138
|
channel: string;
|
|
81
139
|
}
|
|
82
140
|
|
|
141
|
+
/** Data needed to register a live update to be managed */
|
|
83
142
|
export type LiveUpdateConfig = LiveUpdate & { syncOnAdd: boolean };
|
|
84
143
|
|
|
85
144
|
export interface LiveUpdateError {
|
|
145
|
+
/** The AppFlow application ID relating to the failure */
|
|
86
146
|
appId: string;
|
|
147
|
+
/** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
|
|
87
148
|
failStep: string;
|
|
149
|
+
/** A human readable error message */
|
|
88
150
|
message: string;
|
|
89
151
|
}
|
|
90
152
|
|
|
153
|
+
/** Used for communicating sync results of multiple live updates */
|
|
91
154
|
export interface SyncResults {
|
|
92
155
|
liveUpdates: LiveUpdate[];
|
|
93
156
|
errors: LiveUpdateError[];
|
|
94
157
|
}
|
|
95
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Syncs a single live update.
|
|
161
|
+
*
|
|
162
|
+
* @param appId The AppFlow application ID to sync.
|
|
163
|
+
* @returns A Promise<LiveUpdate>. A failure should result in a {@link LiveUpdateError}.
|
|
164
|
+
*/
|
|
96
165
|
export const syncOne = (appId: string): Promise<LiveUpdate> => {
|
|
97
166
|
return IONLiveUpdatesManager.syncOne(appId);
|
|
98
167
|
};
|
|
99
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Syncs many live updates.
|
|
171
|
+
*
|
|
172
|
+
* @param appIds The AppFlow application IDs to sync.
|
|
173
|
+
* @returns Promise<SyncResults>
|
|
174
|
+
*/
|
|
100
175
|
export const syncSome = (appIds: string[]): Promise<SyncResults> => {
|
|
101
176
|
return IONLiveUpdatesManager.syncSome(appIds);
|
|
102
177
|
};
|
|
103
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Syncs all registered LiveUpdates
|
|
181
|
+
* @returns Promise<SyncResults>
|
|
182
|
+
*/
|
|
104
183
|
export const syncAll = (): Promise<SyncResults> => {
|
|
105
184
|
return IONLiveUpdatesManager.syncAll();
|
|
106
185
|
};
|