@ionic/portals-react-native 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,6 @@ Pod::Spec.new do |s|
16
16
  s.source_files = 'ios/**/*.{h,m,mm,swift}'
17
17
 
18
18
  s.dependency 'React-Core'
19
- s.dependency 'IonicPortals', '~> 0.7.3'
19
+ s.dependency 'IonicPortals', '~> 0.8.0'
20
20
  s.dependency 'IonicLiveUpdates', '~> 0.4.0'
21
21
  end
@@ -41,8 +41,8 @@ android {
41
41
  }
42
42
 
43
43
  tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
44
- sourceCompatibility = JavaVersion.VERSION_1_8
45
- targetCompatibility = JavaVersion.VERSION_1_8
44
+ sourceCompatibility = JavaVersion.VERSION_17
45
+ targetCompatibility = JavaVersion.VERSION_17
46
46
 
47
47
  kotlinOptions {
48
48
  freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
@@ -123,7 +123,7 @@ dependencies {
123
123
  //noinspection GradleDynamicVersion
124
124
  api 'com.facebook.react:react-native:+'
125
125
  //noinspection GradleDynamicVersion
126
- api "io.ionic:portals:0.7.+"
126
+ api "io.ionic:portals:0.8.+"
127
127
  //noinspection GradleDynamicVersion
128
128
  api "io.ionic:liveupdates:0.4.+"
129
129
 
@@ -1,4 +1,4 @@
1
- ReactNativePortals_kotlinVersion=1.6.21
2
- ReactNativePortals_compileSdkVersion=29
3
- ReactNativePortals_targetSdkVersion=29
1
+ ReactNativePortals_kotlinVersion=1.8.0
2
+ ReactNativePortals_compileSdkVersion=33
3
+ ReactNativePortals_targetSdkVersion=33
4
4
  android.useAndroidX=true
@@ -62,22 +62,26 @@ internal class PortalViewManager(private val context: ReactApplicationContext) :
62
62
 
63
63
  private fun createFragment(root: FrameLayout, viewId: Int) {
64
64
  val viewState = fragmentMap[viewId] ?: return
65
- val portal = viewState.portal ?: return
65
+ val rnPortal = viewState.portal ?: return
66
66
 
67
67
  val parentView = root.findViewById<ViewGroup>(viewId)
68
68
  setupLayout(parentView)
69
69
 
70
- val portalFragment = PortalFragment(portal.portal)
71
- if (portal.onFCP != null || portal.onFID != null || portal.onTTFB != null) {
72
- portalFragment.webVitalsCallback = { metric, duration ->
70
+ val portal = rnPortal.builder.create()
71
+
72
+ if (rnPortal.onFCP != null || rnPortal.onFID != null || rnPortal.onTTFB != null) {
73
+ val vitalsPlugin = WebVitals { _, metric, duration ->
73
74
  when (metric) {
74
- WebVitals.Metric.FCP -> portal.onFCP?.let { it(duration) }
75
- WebVitals.Metric.FID -> portal.onFID?.let { it(duration) }
76
- WebVitals.Metric.TTFB -> portal.onTTFB?.let { it(duration) }
75
+ WebVitals.Metric.FCP -> rnPortal.onFCP?.let { it(duration) }
76
+ WebVitals.Metric.FID -> rnPortal.onFID?.let { it(duration) }
77
+ WebVitals.Metric.TTFB -> rnPortal.onTTFB?.let { it(duration) }
77
78
  }
78
79
  }
80
+ portal.addPluginInstance(vitalsPlugin)
79
81
  }
80
82
 
83
+ val portalFragment = PortalFragment(portal)
84
+
81
85
  viewState.initialContext?.let(portalFragment::setInitialContext)
82
86
  viewState.fragment = portalFragment
83
87
 
@@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap
14
14
 
15
15
 
16
16
  internal data class RNPortal(
17
- val portal: Portal,
17
+ val builder: PortalBuilder,
18
18
  val index: String?,
19
19
  val plugins: List<PortalPlugin>,
20
20
  var onFCP: ((Long) -> Unit)? = null,
@@ -115,17 +115,16 @@ internal object RNPortalManager {
115
115
  )
116
116
  }
117
117
 
118
- val portal = portalBuilder
118
+ portalBuilder
119
119
  .addPlugin(PortalsPlugin::class.java)
120
- .create()
121
120
 
122
121
  val rnPortal = RNPortal(
123
- portal = portal,
122
+ builder = portalBuilder,
124
123
  index = map.getString("index"),
125
124
  plugins = plugins
126
125
  )
127
126
 
128
- portals[rnPortal.portal.name] = rnPortal
127
+ portals[name] = rnPortal
129
128
  return rnPortal
130
129
  }
131
130
 
@@ -106,6 +106,7 @@ fun List<*>.toReadableArray(): ReadableArray = fold(WritableNativeArray()) { arr
106
106
 
107
107
  internal fun RNPortal.toReadableMap(): ReadableMap {
108
108
  val map = WritableNativeMap()
109
+ val portal = builder.create()
109
110
  map.putString("name", portal.name)
110
111
  map.putString("startDir", portal.startDir)
111
112
  map.putArray("plugins", plugins.toReadableArray())
@@ -3,38 +3,31 @@ package io.ionic.portals.reactnative
3
3
  import com.facebook.react.bridge.*
4
4
  import com.facebook.react.modules.core.DeviceEventManagerModule
5
5
  import com.getcapacitor.JSObject
6
- import io.ionic.portals.PortalsPlugin
6
+ import io.ionic.portals.PortalsPubSub
7
7
  import org.json.JSONObject
8
+ import java.util.concurrent.ConcurrentHashMap
8
9
 
9
10
  internal class PortalsPubSubModule(reactContext: ReactApplicationContext) :
10
11
  ReactContextBaseJavaModule(reactContext) {
11
12
  override fun getName() = "IONPortalPubSub"
12
-
13
- @ReactMethod
14
- fun subscribe(topic: String, promise: Promise) {
15
- val reference = PortalsPlugin.subscribe(topic) { result ->
16
- reactApplicationContext
17
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
18
- .emit("PortalsSubscription", result.toJSObject().toReactMap())
19
- }
20
-
21
- promise.resolve(reference)
22
- }
13
+ private val subscriptionRefs = ConcurrentHashMap<String, Int>()
23
14
 
24
15
  @ReactMethod
25
16
  fun publish(topic: String, data: ReadableMap) {
26
- PortalsPlugin.publish(topic, data.toJSObject())
17
+ PortalsPubSub.shared.publish(topic, data.toJSObject())
27
18
  }
28
19
 
29
- @ReactMethod
30
- fun unsubscribe(topic: String, reference: Int) {
31
- PortalsPlugin.unsubscribe(topic, reference)
32
- }
33
-
34
- // These are required to be an EventEmitter in javascript
35
-
36
20
  @ReactMethod
37
21
  fun addListener(eventName: String) {
22
+ val topic = eventName.removePrefix("PortalsSubscription:")
23
+ if (subscriptionRefs[topic] != null) { return }
24
+ val ref = PortalsPubSub.shared.subscribe(topic) { result ->
25
+ reactApplicationContext
26
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
27
+ .emit(eventName, result.toJSObject().toReactMap())
28
+ }
29
+
30
+ subscriptionRefs[eventName] = ref
38
31
  }
39
32
 
40
33
  @ReactMethod
package/ios/Podfile CHANGED
@@ -9,6 +9,6 @@ target 'ReactNativePortals' do
9
9
  use_frameworks!
10
10
  use_react_native!(path: config['reactNativePath'])
11
11
  # Pods for ReactNativePortals
12
- pod 'IonicPortals', '~> 0.7.3'
12
+ pod 'IonicPortals', '~> 0.8.0'
13
13
  pod 'IonicLiveUpdates', '~> 0.4.0'
14
14
  end
package/ios/Podfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PODS:
2
2
  - boost-for-react-native (1.63.0)
3
- - Capacitor (4.7.0):
3
+ - Capacitor (5.3.0):
4
4
  - CapacitorCordova
5
- - CapacitorCordova (4.7.0)
5
+ - CapacitorCordova (5.3.0)
6
6
  - DoubleConversion (1.1.6)
7
7
  - FBLazyVector (0.63.4)
8
8
  - FBReactNativeSpec (0.63.4):
@@ -23,8 +23,8 @@ PODS:
23
23
  - glog
24
24
  - glog (0.3.5)
25
25
  - IonicLiveUpdates (0.4.0)
26
- - IonicPortals (0.7.3):
27
- - Capacitor (~> 4.6)
26
+ - IonicPortals (0.8.0):
27
+ - Capacitor (~> 5.0)
28
28
  - IonicLiveUpdates (< 0.5.0, >= 0.1.2)
29
29
  - RCTRequired (0.63.4)
30
30
  - RCTTypeSafety (0.63.4):
@@ -261,7 +261,7 @@ DEPENDENCIES:
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
263
  - IonicLiveUpdates (~> 0.4.0)
264
- - IonicPortals (~> 0.7.3)
264
+ - IonicPortals (~> 0.8.0)
265
265
  - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
266
266
  - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
267
267
  - React (from `../node_modules/react-native/`)
@@ -350,15 +350,15 @@ EXTERNAL SOURCES:
350
350
 
351
351
  SPEC CHECKSUMS:
352
352
  boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
353
- Capacitor: 86c48d748b59228e0fce85b1909c18c449b35f56
354
- CapacitorCordova: 49b11f2ce72487cd751aad7181606d2a710b1549
353
+ Capacitor: b722db61461f4712a326cc675285a3597edfe86c
354
+ CapacitorCordova: 7c4b8842c39206c29009ed0887788190cb2c8ff7
355
355
  DoubleConversion: cde416483dac037923206447da6e1454df403714
356
356
  FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
357
357
  FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
358
358
  Folly: b73c3869541e86821df3c387eb0af5f65addfab4
359
359
  glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
360
360
  IonicLiveUpdates: 77d9840ec1b2b9d1d56d4595640b5813be503fe9
361
- IonicPortals: e44a6f9a47e7c09a879f1e2c5d901e6629ac2024
361
+ IonicPortals: 03ff0375e2631857221de7696e89f90f55d36949
362
362
  RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
363
363
  RCTTypeSafety: 8c9c544ecbf20337d069e4ae7fd9a377aadf504b
364
364
  React: b0a957a2c44da4113b0c4c9853d8387f8e64e615
@@ -381,6 +381,6 @@ SPEC CHECKSUMS:
381
381
  ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
382
382
  Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
383
383
 
384
- PODFILE CHECKSUM: 685fb93c81db77a563a8c1ba6999dc27b98a8d33
384
+ PODFILE CHECKSUM: 3b18df74405fe59433a82e44b887ad0280a9b07f
385
385
 
386
- COCOAPODS: 1.11.2
386
+ COCOAPODS: 1.12.1
package/ios/Portal.swift CHANGED
@@ -51,7 +51,7 @@ extension Portal {
51
51
  index: dict["index"] as? String ?? "index.html",
52
52
  initialContext: JSTypes.coerceDictionaryToJSObject(dict["initialContext"] as? [String: Any]) ?? [:],
53
53
  assetMaps: assetMaps,
54
- pluginRegistrationMode: .manual(plugins.toCapPlugin),
54
+ plugins: plugins.toCapPlugin,
55
55
  liveUpdateManager: liveUpdateManager,
56
56
  liveUpdateConfig: (dict["liveUpdate"] as? [String: Any]).flatMap(LiveUpdate.init)
57
57
  )
@@ -32,7 +32,7 @@ struct PortalsConfig {
32
32
  index: index ?? "index.html",
33
33
  initialContext: initialContext ?? [:],
34
34
  assetMaps: assetMaps ?? [],
35
- pluginRegistrationMode: .manual(plugins?.toCapPlugin ?? []),
35
+ plugins: plugins?.toCapPlugin ?? [],
36
36
  liveUpdateManager: liveUpdateManager,
37
37
  liveUpdateConfig: liveUpdate.map { .init(appId: $0.appId, channel: $0.channel, syncOnAdd: $0.syncOnAdd) }
38
38
  ),
@@ -10,7 +10,5 @@
10
10
  #import <React/RCTEventEmitter.h>
11
11
 
12
12
  @interface RCT_EXTERN_MODULE(IONPortalPubSub, RCTEventEmitter)
13
- RCT_EXTERN_METHOD(subscribe: (NSString *) topic resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
14
- RCT_EXTERN_METHOD(unsubscribe: (NSString *) topic subscriptionRef: (NSNumber _Nonnull) subscriptionRef resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
15
13
  RCT_EXTERN_METHOD(publish: (NSString *) topic data: (id) data resolver: (RCTPromiseResolveBlock) resolver rejector: (RCTPromiseRejectBlock) rejector)
16
14
  @end
@@ -8,36 +8,39 @@
8
8
 
9
9
  import IonicPortals
10
10
  import React
11
+ import Combine
11
12
 
12
13
  @objc(IONPortalPubSub)
13
14
  class PortalsPubSub: RCTEventEmitter {
14
- private let eventName = "PortalsSubscription"
15
+ private let eventPrefix = "PortalsSubscription:"
16
+ private var events: Set<String> = []
15
17
 
16
- override func supportedEvents() -> [String]! {
17
- [eventName]
18
+ override func supportedEvents() -> [String] {
19
+ Array(events)
18
20
  }
19
-
20
- @objc func subscribe(_ topic: String, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
21
- let subRef = IonicPortals.PortalsPubSub.subscribe(topic) { [weak self] result in
22
- guard let self = self else { return }
23
- self.sendEvent(
24
- withName: self.eventName,
21
+
22
+ private let publishers = ConcurrentDictionary<String, AnyCancellable>(label: "io.ionic.rn.portalspubsub")
23
+
24
+ override func addListener(_ eventName: String) {
25
+ var topic = eventName
26
+ if topic.hasPrefix(eventPrefix) {
27
+ topic = String(eventName.suffix(from: eventPrefix.endIndex))
28
+ }
29
+ events.insert(eventName)
30
+ super.addListener(eventName)
31
+
32
+ if let _ = publishers[topic] { return }
33
+ publishers[topic] = IonicPortals.PortalsPubSub.subscribe(to: topic) { [weak self] result in
34
+ self?.sendEvent(
35
+ withName: eventName,
25
36
  body: [
26
- "subscriptionRef": result.subscriptionRef,
27
37
  "topic": result.topic,
28
38
  "data": result.data
29
39
  ]
30
40
  )
31
41
  }
32
-
33
- resolver(subRef)
34
42
  }
35
-
36
- @objc func unsubscribe(_ topic: String, subscriptionRef: NSNumber, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
37
- IonicPortals.PortalsPubSub.unsubscribe(from: topic, subscriptionRef: subscriptionRef.intValue)
38
- resolver(())
39
- }
40
-
43
+
41
44
  @objc func publish(_ topic: String, data: Any, resolver: RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
42
45
  IONPortalsPubSub.publish(message: data, topic: topic)
43
46
  resolver(())
@@ -12,13 +12,27 @@ import React
12
12
  @objc(IONPortalsWebVitals)
13
13
  class WebVitals: RCTEventEmitter {
14
14
  private let fcp = "vitals:fcp"
15
-
15
+
16
16
  override func supportedEvents() -> [String] {
17
17
  [fcp]
18
18
  }
19
19
 
20
20
  @objc func registerOnFirstContentfulPaint(_ portalName: String, resolver: @escaping RCTPromiseResolveBlock, rejector: RCTPromiseRejectBlock) {
21
- PortalsReactNative.portals[portalName]?.performanceReporter = WebPerformanceReporter { [weak self] _, duration in
21
+ guard var portal = PortalsReactNative.portals[portalName] else {
22
+ return resolver(())
23
+ }
24
+
25
+ var portalPlugins = portal._portal.plugins.filter { plugin in
26
+ switch plugin {
27
+ case .instance(let plugin):
28
+ return type(of: plugin) != WebVitalsPlugin.self
29
+ case .type:
30
+ return true
31
+ }
32
+ }
33
+
34
+
35
+ var vitalsPlugin = WebVitalsPlugin { [weak self] _, duration in
22
36
  guard let self = self else { return }
23
37
  self.sendEvent(
24
38
  withName: self.fcp,
@@ -28,6 +42,12 @@ class WebVitals: RCTEventEmitter {
28
42
  ]
29
43
  )
30
44
  }
45
+
46
+ portalPlugins.append(.instance(vitalsPlugin))
47
+ portal._portal.plugins = portalPlugins
48
+
49
+ PortalsReactNative.portals[portalName] = portal
50
+
31
51
  resolver(())
32
52
  }
33
53
 
@@ -24,6 +24,5 @@ const PortalView = props => {
24
24
  ref: ref
25
25
  }));
26
26
  };
27
- var _default = PortalView;
28
- exports.default = _default;
27
+ var _default = exports.default = PortalView;
29
28
  //# sourceMappingURL=PortalView.android.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","PortalViewManager","requireNativeComponent","createFragment","viewId","UIManager","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","useRef","useEffect","findNodeHandle","current","createElement","_default","exports"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIsB,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KA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C,aAAA,CAACjB,iBAAiB,EAAAT,QAAA,KAAKoB,KAAK;IAAEC,GAAG,EAAEA;EAAI,EAAE,CAAC;AACnD,CAAC;AAAC,IAAAM,QAAA,GAEaR,UAAU;AAAAS,OAAA,CAAA3C,OAAA,GAAA0C,QAAA"}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","PortalViewManager","requireNativeComponent","createFragment","viewId","UIManager","dispatchViewManagerCommand","AndroidPortalView","Commands","create","toString","PortalView","props","ref","useRef","useEffect","findNodeHandle","current","createElement","_default","exports"],"sources":["PortalView.android.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport {\n findNodeHandle,\n requireNativeComponent,\n UIManager,\n} from 'react-native';\nimport type { PortalProps } from '.';\n\nconst PortalViewManager = requireNativeComponent('AndroidPortalView');\n\nconst createFragment = (viewId: number | null) =>\n UIManager.dispatchViewManagerCommand(\n viewId,\n // we are calling the 'create' command\n // @ts-expect-error\n UIManager.AndroidPortalView.Commands.create.toString(),\n [viewId]\n );\n\nconst PortalView = (props: PortalProps) => {\n const ref = useRef(null);\n\n useEffect(() => {\n const viewId = findNodeHandle(ref.current);\n createFragment(viewId);\n }, []);\n\n return <PortalViewManager {...props} ref={ref} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIsB,SAAAE,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBA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A,EAAAb,GAAA,KAAAS,MAAA,CAAAT,GAAA,IAAAa,MAAA,CAAAb,GAAA,gBAAAS,MAAA,YAAAH,QAAA,CAAAQ,KAAA,OAAAH,SAAA;AAGtB,MAAMI,iBAAiB,GAAG,IAAAC,mCAAsB,EAAC,mBAAmB,CAAC;AAErE,MAAMC,cAAc,GAAIC,MAAqB,IAC3CC,sBAAS,CAACC,0BAA0B,CAClCF,MAAM;AACN;AACA;AACAC,sBAAS,CAACE,iBAAiB,CAACC,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAAC,CAAC,EACtD,CAACN,MAAM,CACT,CAAC;AAEH,MAAMO,UAAU,GAAIC,KAAkB,IAAK;EACzC,MAAMC,GAAG,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAExB,IAAAC,gBAAS,EAAC,MAAM;IACd,MAAMX,MAAM,GAAG,IAAAY,2BAAc,EAACH,GAAG,CAACI,OAAO,CAAC;IAC1Cd,cAAc,CAACC,MAAM,CAAC;EACxB,CAAC,EAAE,EAAE,CAAC;EAEN,oBAAOtC,MAAA,CAAAW,OAAA,CAAAyC,aAAA,CAACjB,iBAAiB,EAAAT,QAAA,KAAKoB,KAAK;IAAEC,GAAG,EAAEA;EAAI,EAAE,CAAC;AACnD,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAA3C,OAAA,GAEakC,UAAU"}
@@ -11,6 +11,5 @@ const HostComponentPortal = (0, _reactNative.requireNativeComponent)('IONPortalV
11
11
  const PortalView = props => {
12
12
  return /*#__PURE__*/_react.default.createElement(HostComponentPortal, props);
13
13
  };
14
- var _default = PortalView;
15
- exports.default = _default;
14
+ var _default = exports.default = PortalView;
16
15
  //# sourceMappingURL=PortalView.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","obj","__esModule","default","HostComponentPortal","requireNativeComponent","PortalView","props","createElement","_default","exports"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAsD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGtD,MAAMG,mBAAmB,GAAG,IAAAC,mCAAsB,EAAC,eAAe,CAAC;AAEnE,MAAMC,UAAU,GAAIC,KAAkB,IAAK;EACzC,oBAAOV,MAAA,CAAAM,OAAA,CAAAK,aAAA,CAACJ,mBAAmB,EAAKG,KAAQ,CAAC;AAC3C,CAAC;AAAC,IAAAE,QAAA,GAEaH,UAAU;AAAAI,OAAA,CAAAP,OAAA,GAAAM,QAAA"}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","obj","__esModule","default","HostComponentPortal","requireNativeComponent","PortalView","props","createElement","_default","exports"],"sources":["PortalView.tsx"],"sourcesContent":["import React from 'react';\nimport { requireNativeComponent } from 'react-native';\nimport type { PortalProps } from '.';\n\nconst HostComponentPortal = requireNativeComponent('IONPortalView');\n\nconst PortalView = (props: PortalProps) => {\n return <HostComponentPortal {...props} />;\n};\n\nexport default PortalView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAsD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGtD,MAAMG,mBAAmB,GAAG,IAAAC,mCAAsB,EAAC,eAAe,CAAC;AAEnE,MAAMC,UAAU,GAAIC,KAAkB,IAAK;EACzC,oBAAOV,MAAA,CAAAM,OAAA,CAAAK,aAAA,CAACJ,mBAAmB,EAAKG,KAAQ,CAAC;AAC3C,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAP,OAAA,GAEaG,UAAU"}
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "PortalView", {
9
9
  return _PortalView.default;
10
10
  }
11
11
  });
12
- exports.unsubscribe = exports.syncSome = exports.syncOne = exports.syncAll = exports.subscribe = exports.registerWebVitals = exports.register = exports.publish = exports.onTimeToFirstByte = exports.onFirstInputDelay = exports.onFirstContentfulPaint = exports.getPortal = exports.enableSecureLiveUpdates = exports.addPortals = exports.addPortal = void 0;
12
+ exports.syncSome = exports.syncOne = exports.syncAll = exports.subscribe = exports.registerWebVitals = exports.register = exports.publish = exports.onTimeToFirstByte = exports.onFirstInputDelay = exports.onFirstContentfulPaint = exports.getPortal = exports.enableSecureLiveUpdates = exports.addPortals = exports.addPortal = void 0;
13
13
  var _reactNative = require("react-native");
14
14
  var _PortalView = _interopRequireDefault(require("./PortalView"));
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -23,7 +23,8 @@ const {
23
23
  */
24
24
 
25
25
  const PortalsPubSub = new _reactNative.NativeEventEmitter(IONPortalPubSub);
26
- const subscriptionMap = new Map();
26
+
27
+ // const subscriptionMap = new Map<number, EmitterSubscription>();
27
28
 
28
29
  /**
29
30
  * Subscribes to messages for a topic
@@ -32,17 +33,26 @@ const subscriptionMap = new Map();
32
33
  * @param onMessageReceived The callback to invoke when a message is received
33
34
  * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
34
35
  */
35
- const subscribe = async (topic, onMessageReceived) => {
36
- const subscriptionRef = await IONPortalPubSub.subscribe(topic);
37
- const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
38
- if (message.subscriptionRef === subscriptionRef) {
39
- onMessageReceived(message);
40
- }
36
+ const subscribe = (topic, onMessageReceived) => {
37
+ return PortalsPubSub.addListener(`PortalsSubscription:${topic}`, message => {
38
+ onMessageReceived(message);
41
39
  });
42
- subscriptionMap.set(subscriptionRef, subscriber);
43
- return subscriptionRef;
44
40
  };
41
+
42
+ /**
43
+ * Publishes a message to the provided topic
44
+ *
45
+ * @param topic The topic to publish the message to
46
+ * @param data The data to publish to subscribers
47
+ */
45
48
  exports.subscribe = subscribe;
49
+ const publish = (topic, data) => {
50
+ const msg = {
51
+ message: data
52
+ };
53
+ IONPortalPubSub.publish(topic, msg);
54
+ };
55
+ exports.publish = publish;
46
56
  const webVitalsMap = new Map();
47
57
  const WebVitals = new _reactNative.NativeEventEmitter(IONPortalsWebVitals);
48
58
  const onFirstContentfulPaint = async (portalName, callback) => {
@@ -63,7 +73,7 @@ const onFirstInputDelay = async (portalName, callback) => {
63
73
  }
64
74
  });
65
75
  await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);
66
- webVitalsMap.set(`${portalName}-vitals:fcp`, listener);
76
+ webVitalsMap.set(`${portalName}-vitals:fid`, listener);
67
77
  }
68
78
  };
69
79
  exports.onFirstInputDelay = onFirstInputDelay;
@@ -85,42 +95,12 @@ const registerWebVitals = async (portalName, firstContentfulPaint, firstInputDel
85
95
  onTimeToFirstByte(portalName, timeToFirstByte);
86
96
  };
87
97
 
88
- /**
89
- * Unsubscribes from events for the provided topic and subscription reference
90
- *
91
- * @param topic The topic to unsubscribe from
92
- * @param subRef The unique subscription reference received when initially calling {@link subscribe}
93
- */
94
- exports.registerWebVitals = registerWebVitals;
95
- const unsubscribe = (topic, subRef) => {
96
- IONPortalPubSub.unsubscribe(topic, subRef);
97
- const subscription = subscriptionMap.get(subRef);
98
- if (subscription !== undefined) {
99
- subscription.remove();
100
- subscriptionMap.delete(subRef);
101
- }
102
- };
103
-
104
- /**
105
- * Publishes a message to the provided topic
106
- *
107
- * @param topic The topic to publish the message to
108
- * @param data The data to publish to subscribers
109
- */
110
- exports.unsubscribe = unsubscribe;
111
- const publish = (topic, data) => {
112
- const msg = {
113
- message: data
114
- };
115
- IONPortalPubSub.publish(topic, msg);
116
- };
117
-
118
98
  /**
119
99
  * Validates that a valid registration key has been procured from http://ionic.io/register-portals
120
100
  * @param key The registration key
121
101
  * @returns Promise<void>
122
102
  */
123
- exports.publish = publish;
103
+ exports.registerWebVitals = registerWebVitals;
124
104
  const register = async key => {
125
105
  return IONPortalsReactNative.register(key);
126
106
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_PortalView","_interopRequireDefault","obj","__esModule","default","IONPortalPubSub","IONPortalsReactNative","IONPortalsWebVitals","NativeModules","PortalsPubSub","NativeEventEmitter","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","exports","webVitalsMap","WebVitals","onFirstContentfulPaint","portalName","callback","listener","event","duration","registerOnFirstContentfulPaint","onFirstInputDelay","Platform","OS","registerOnFirstInputDelay","onTimeToFirstByte","registerOnTimeToFirstByte","registerWebVitals","firstContentfulPaint","firstInputDelay","timeToFirstByte","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","addPortals","portals","getPortal","name","enableSecureLiveUpdates","pathToKey","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n Platform,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalsReactNative, IONPortalsWebVitals } =\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\nconst webVitalsMap = new Map<string, EmitterSubscription>();\nconst WebVitals = new NativeEventEmitter(IONPortalsWebVitals);\n\ninterface WebVitalsEvent {\n portalName: string;\n duration: number;\n}\n\nexport const onFirstContentfulPaint = async (\n portalName: string,\n callback: (duration: number) => void\n): Promise<void> => {\n const listener = WebVitals.addListener(\n 'vitals:fcp',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstContentfulPaint(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n};\n\nexport const onFirstInputDelay = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:fid',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n }\n};\n\nexport const onTimeToFirstByte = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:ttfb',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnTimeToFirstByte(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:ttfb`, listener);\n }\n};\n\nexport const registerWebVitals = async (\n portalName: string,\n firstContentfulPaint: (duration: number) => void,\n firstInputDelay: (duration: number) => void,\n timeToFirstByte: (duration: number) => void\n) => {\n onFirstContentfulPaint(portalName, firstContentfulPaint);\n onFirstInputDelay(portalName, firstInputDelay);\n onTimeToFirstByte(portalName, timeToFirstByte);\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 * @returns Promise<void>\n */\nexport const register = async (key: string): Promise<void> => {\n return IONPortalsReactNative.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 /** Any Capacitor plugins to be made available to the Portal */\n plugins?: CapacitorPlugin[];\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 assetMaps?: AssetMap[];\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport interface CapacitorPlugin {\n /** The classpath of the plugin to be used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidClassPath: string;\n /** The class name of the plugin to be used in iOS.\n * This must be the name as it is exposed to the Objective-C runtime.\n * For example, The CameraPlugin swift class is exposed to Objective-C as CAPCameraPlugin.\n */\n iosClassName: string;\n}\n\nexport interface AssetMap {\n /** The name to index the asset map by */\n name: string;\n /** Any path to match via the web. If omitted, {@link AssetMap#name} will be used. */\n virtualPath?: string;\n /** The root directory of the assets relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, the root of Bundle.main\n * and src/main/assets will be used.\n */\n startDir?: string;\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 * @returns Promise containing the Portal that was added to the registry.\n */\nexport const addPortal = async (portal: Portal): Promise<Portal> => {\n return IONPortalsReactNative.addPortal(portal);\n};\n\n/**\n * Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}\n *\n * @param portals The portals to add to the internal registry.\n * @returns Promise containing the Portals that were added to the registry.\n */\nexport const addPortals = async (portals: Portal[]): Promise<Portal[]> => {\n return IONPortalsReactNative.addPortals(portals);\n};\n\n/**\n * Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.\n *\n * @param name The portal name to retrieve from the internal registry.\n * @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.\n */\nexport const getPortal = async (name: string): Promise<Portal> => {\n return IONPortalsReactNative.getPortal(name);\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\nexport interface Snapshot {\n /** The snapshot id as found in AppFlow */\n id: string;\n /** The AppFlow build id that produced the snapshot */\n buildId: string;\n}\n\nexport interface SyncResult {\n /** The {@link LiveUpdate} associated with the result */\n liveUpdate: LiveUpdate;\n /** The {@link Snapshot} that was sync'd */\n snapshot: Snapshot | null;\n /** Whether the snapshot was downloaded or already on disk */\n source: 'download' | 'cache';\n /** If the active application path was changed. A `false` value would indicate\n * the application already has the latest code for the associated {@link LiveUpdate}\n * configuration.\n */\n activeApplicationPathChanged: boolean;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n results: SyncResult[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.\n * This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.\n *\n * @param pathToKey The *relative* path to the public key for verification.\n * This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.\n * @returns Promise<void>\n */\nexport const enableSecureLiveUpdates = async (\n pathToKey: string\n): Promise<void> => {\n return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);\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 = async (appId: string): Promise<SyncResult> => {\n return IONPortalsReactNative.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 = async (appIds: string[]): Promise<SyncResults> => {\n return IONPortalsReactNative.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = async (): Promise<SyncResults> => {\n return IONPortalsReactNative.syncAll();\n};\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAWA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAqD,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,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;AACA;AALAjC,OAAA,CAAAgC,SAAA,GAAAA,SAAA;AAMO,MAAME,UAAU,GAAG,MAAOC,OAAiB,IAAwB;EACxE,OAAOlD,qBAAqB,CAACiD,UAAU,CAACC,OAAO,CAAC;AAClD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAnC,OAAA,CAAAkC,UAAA,GAAAA,UAAA;AAMO,MAAME,SAAS,GAAG,MAAOC,IAAY,IAAsB;EAChE,OAAOpD,qBAAqB,CAACmD,SAAS,CAACC,IAAI,CAAC;AAC9C,CAAC;;AASD;;AAiCA;AAAArC,OAAA,CAAAoC,SAAA,GAAAA,SAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,uBAAuB,GAAG,MACrCC,SAAiB,IACC;EAClB,OAAOtD,qBAAqB,CAACqD,uBAAuB,CAACC,SAAS,CAAC;AACjE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAvC,OAAA,CAAAsC,uBAAA,GAAAA,uBAAA;AAMO,MAAME,OAAO,GAAG,MAAOC,KAAa,IAA0B;EACnE,OAAOxD,qBAAqB,CAACuD,OAAO,CAACC,KAAK,CAAC;AAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAzC,OAAA,CAAAwC,OAAA,GAAAA,OAAA;AAMO,MAAME,QAAQ,GAAG,MAAOC,MAAgB,IAA2B;EACxE,OAAO1D,qBAAqB,CAACyD,QAAQ,CAACC,MAAM,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AAHA3C,OAAA,CAAA0C,QAAA,GAAAA,QAAA;AAIO,MAAME,OAAO,GAAG,MAAAA,CAAA,KAAkC;EACvD,OAAO3D,qBAAqB,CAAC2D,OAAO,CAAC,CAAC;AACxC,CAAC;AAAC5C,OAAA,CAAA4C,OAAA,GAAAA,OAAA"}
1
+ {"version":3,"names":["_reactNative","require","_PortalView","_interopRequireDefault","obj","__esModule","default","IONPortalPubSub","IONPortalsReactNative","IONPortalsWebVitals","NativeModules","PortalsPubSub","NativeEventEmitter","subscribe","topic","onMessageReceived","addListener","message","exports","publish","data","msg","webVitalsMap","Map","WebVitals","onFirstContentfulPaint","portalName","callback","listener","event","duration","registerOnFirstContentfulPaint","set","onFirstInputDelay","Platform","OS","registerOnFirstInputDelay","onTimeToFirstByte","registerOnTimeToFirstByte","registerWebVitals","firstContentfulPaint","firstInputDelay","timeToFirstByte","register","key","addPortal","portal","addPortals","portals","getPortal","name","enableSecureLiveUpdates","pathToKey","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n Platform,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalsReactNative, IONPortalsWebVitals } =\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\n// const 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 = (\n topic: string,\n onMessageReceived: (message: Message) => void\n): EmitterSubscription => {\n return PortalsPubSub.addListener(\n `PortalsSubscription:${topic}`,\n (message: Message) => {\n onMessageReceived(message);\n }\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\nconst webVitalsMap = new Map<string, EmitterSubscription>();\nconst WebVitals = new NativeEventEmitter(IONPortalsWebVitals);\n\ninterface WebVitalsEvent {\n portalName: string;\n duration: number;\n}\n\nexport const onFirstContentfulPaint = async (\n portalName: string,\n callback: (duration: number) => void\n): Promise<void> => {\n const listener = WebVitals.addListener(\n 'vitals:fcp',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstContentfulPaint(portalName);\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n};\n\nexport const onFirstInputDelay = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:fid',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);\n webVitalsMap.set(`${portalName}-vitals:fid`, listener);\n }\n};\n\nexport const onTimeToFirstByte = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:ttfb',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnTimeToFirstByte(portalName);\n webVitalsMap.set(`${portalName}-vitals:ttfb`, listener);\n }\n};\n\nexport const registerWebVitals = async (\n portalName: string,\n firstContentfulPaint: (duration: number) => void,\n firstInputDelay: (duration: number) => void,\n timeToFirstByte: (duration: number) => void\n) => {\n onFirstContentfulPaint(portalName, firstContentfulPaint);\n onFirstInputDelay(portalName, firstInputDelay);\n onTimeToFirstByte(portalName, timeToFirstByte);\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 * @returns Promise<void>\n */\nexport const register = async (key: string): Promise<void> => {\n return IONPortalsReactNative.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 /** Any Capacitor plugins to be made available to the Portal */\n plugins?: CapacitorPlugin[];\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 assetMaps?: AssetMap[];\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport interface CapacitorPlugin {\n /** The classpath of the plugin to be used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidClassPath: string;\n /** The class name of the plugin to be used in iOS.\n * This must be the name as it is exposed to the Objective-C runtime.\n * For example, The CameraPlugin swift class is exposed to Objective-C as CAPCameraPlugin.\n */\n iosClassName: string;\n}\n\nexport interface AssetMap {\n /** The name to index the asset map by */\n name: string;\n /** Any path to match via the web. If omitted, {@link AssetMap#name} will be used. */\n virtualPath?: string;\n /** The root directory of the assets relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, the root of Bundle.main\n * and src/main/assets will be used.\n */\n startDir?: string;\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 * @returns Promise containing the Portal that was added to the registry.\n */\nexport const addPortal = async (portal: Portal): Promise<Portal> => {\n return IONPortalsReactNative.addPortal(portal);\n};\n\n/**\n * Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}\n *\n * @param portals The portals to add to the internal registry.\n * @returns Promise containing the Portals that were added to the registry.\n */\nexport const addPortals = async (portals: Portal[]): Promise<Portal[]> => {\n return IONPortalsReactNative.addPortals(portals);\n};\n\n/**\n * Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.\n *\n * @param name The portal name to retrieve from the internal registry.\n * @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.\n */\nexport const getPortal = async (name: string): Promise<Portal> => {\n return IONPortalsReactNative.getPortal(name);\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\nexport interface Snapshot {\n /** The snapshot id as found in AppFlow */\n id: string;\n /** The AppFlow build id that produced the snapshot */\n buildId: string;\n}\n\nexport interface SyncResult {\n /** The {@link LiveUpdate} associated with the result */\n liveUpdate: LiveUpdate;\n /** The {@link Snapshot} that was sync'd */\n snapshot: Snapshot | null;\n /** Whether the snapshot was downloaded or already on disk */\n source: 'download' | 'cache';\n /** If the active application path was changed. A `false` value would indicate\n * the application already has the latest code for the associated {@link LiveUpdate}\n * configuration.\n */\n activeApplicationPathChanged: boolean;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n results: SyncResult[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.\n * This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.\n *\n * @param pathToKey The *relative* path to the public key for verification.\n * This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.\n * @returns Promise<void>\n */\nexport const enableSecureLiveUpdates = async (\n pathToKey: string\n): Promise<void> => {\n return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);\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 = async (appId: string): Promise<SyncResult> => {\n return IONPortalsReactNative.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 = async (appIds: string[]): Promise<SyncResults> => {\n return IONPortalsReactNative.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = async (): Promise<SyncResults> => {\n return IONPortalsReactNative.syncAll();\n};\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAWA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAqD,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAHrD,MAAM;EAAEG,eAAe;EAAEC,qBAAqB;EAAEC;AAAoB,CAAC,GACnEC,0BAAa;AAIf;AACA;AACA;;AASA,MAAMC,aAAa,GAAG,IAAIC,+BAAkB,CAACL,eAAe,CAAC;;AAE7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMM,SAAS,GAAGA,CACvBC,KAAa,EACbC,iBAA6C,KACrB;EACxB,OAAOJ,aAAa,CAACK,WAAW,CAC7B,uBAAsBF,KAAM,EAAC,EAC7BG,OAAgB,IAAK;IACpBF,iBAAiB,CAACE,OAAO,CAAC;EAC5B,CACF,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAC,OAAA,CAAAL,SAAA,GAAAA,SAAA;AAMO,MAAMM,OAAO,GAAGA,CAACL,KAAa,EAAEM,IAAS,KAAK;EACnD,MAAMC,GAAG,GAAG;IAAEJ,OAAO,EAAEG;EAAK,CAAC;EAC7Bb,eAAe,CAACY,OAAO,CAACL,KAAK,EAAEO,GAAG,CAAC;AACrC,CAAC;AAACH,OAAA,CAAAC,OAAA,GAAAA,OAAA;AAEF,MAAMG,YAAY,GAAG,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OAAA,CAAA6B,UAAA,GAAAA,UAAA;AAMO,MAAME,SAAS,GAAG,MAAOC,IAAY,IAAsB;EAChE,OAAO1C,qBAAqB,CAACyC,SAAS,CAACC,IAAI,CAAC;AAC9C,CAAC;;AASD;;AAiCA;AAAAhC,OAAA,CAAA+B,SAAA,GAAAA,SAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,uBAAuB,GAAG,MACrCC,SAAiB,IACC;EAClB,OAAO5C,qBAAqB,CAAC2C,uBAAuB,CAACC,SAAS,CAAC;AACjE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAlC,OAAA,CAAAiC,uBAAA,GAAAA,uBAAA;AAMO,MAAME,OAAO,GAAG,MAAOC,KAAa,IAA0B;EACnE,OAAO9C,qBAAqB,CAAC6C,OAAO,CAACC,KAAK,CAAC;AAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALApC,OAAA,CAAAmC,OAAA,GAAAA,OAAA;AAMO,MAAME,QAAQ,GAAG,MAAOC,MAAgB,IAA2B;EACxE,OAAOhD,qBAAqB,CAAC+C,QAAQ,CAACC,MAAM,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AAHAtC,OAAA,CAAAqC,QAAA,GAAAA,QAAA;AAIO,MAAME,OAAO,GAAG,MAAAA,CAAA,KAAkC;EACvD,OAAOjD,qBAAqB,CAACiD,OAAO,CAAC,CAAC;AACxC,CAAC;AAACvC,OAAA,CAAAuC,OAAA,GAAAA,OAAA"}
@@ -11,7 +11,8 @@ export { default as PortalView } from './PortalView';
11
11
  */
12
12
 
13
13
  const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
14
- const subscriptionMap = new Map();
14
+
15
+ // const subscriptionMap = new Map<number, EmitterSubscription>();
15
16
 
16
17
  /**
17
18
  * Subscribes to messages for a topic
@@ -20,15 +21,23 @@ const subscriptionMap = new Map();
20
21
  * @param onMessageReceived The callback to invoke when a message is received
21
22
  * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
22
23
  */
23
- export const subscribe = async (topic, onMessageReceived) => {
24
- const subscriptionRef = await IONPortalPubSub.subscribe(topic);
25
- const subscriber = PortalsPubSub.addListener('PortalsSubscription', message => {
26
- if (message.subscriptionRef === subscriptionRef) {
27
- onMessageReceived(message);
28
- }
24
+ export const subscribe = (topic, onMessageReceived) => {
25
+ return PortalsPubSub.addListener(`PortalsSubscription:${topic}`, message => {
26
+ onMessageReceived(message);
29
27
  });
30
- subscriptionMap.set(subscriptionRef, subscriber);
31
- return subscriptionRef;
28
+ };
29
+
30
+ /**
31
+ * Publishes a message to the provided topic
32
+ *
33
+ * @param topic The topic to publish the message to
34
+ * @param data The data to publish to subscribers
35
+ */
36
+ export const publish = (topic, data) => {
37
+ const msg = {
38
+ message: data
39
+ };
40
+ IONPortalPubSub.publish(topic, msg);
32
41
  };
33
42
  const webVitalsMap = new Map();
34
43
  const WebVitals = new NativeEventEmitter(IONPortalsWebVitals);
@@ -49,7 +58,7 @@ export const onFirstInputDelay = async (portalName, callback) => {
49
58
  }
50
59
  });
51
60
  await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);
52
- webVitalsMap.set(`${portalName}-vitals:fcp`, listener);
61
+ webVitalsMap.set(`${portalName}-vitals:fid`, listener);
53
62
  }
54
63
  };
55
64
  export const onTimeToFirstByte = async (portalName, callback) => {
@@ -69,34 +78,6 @@ export const registerWebVitals = async (portalName, firstContentfulPaint, firstI
69
78
  onTimeToFirstByte(portalName, timeToFirstByte);
70
79
  };
71
80
 
72
- /**
73
- * Unsubscribes from events for the provided topic and subscription reference
74
- *
75
- * @param topic The topic to unsubscribe from
76
- * @param subRef The unique subscription reference received when initially calling {@link subscribe}
77
- */
78
- export const unsubscribe = (topic, subRef) => {
79
- IONPortalPubSub.unsubscribe(topic, subRef);
80
- const subscription = subscriptionMap.get(subRef);
81
- if (subscription !== undefined) {
82
- subscription.remove();
83
- subscriptionMap.delete(subRef);
84
- }
85
- };
86
-
87
- /**
88
- * Publishes a message to the provided topic
89
- *
90
- * @param topic The topic to publish the message to
91
- * @param data The data to publish to subscribers
92
- */
93
- export const publish = (topic, data) => {
94
- const msg = {
95
- message: data
96
- };
97
- IONPortalPubSub.publish(topic, msg);
98
- };
99
-
100
81
  /**
101
82
  * Validates that a valid registration key has been procured from http://ionic.io/register-portals
102
83
  * @param key The registration key
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","IONPortalPubSub","IONPortalsReactNative","IONPortalsWebVitals","default","PortalView","PortalsPubSub","subscriptionMap","Map","subscribe","topic","onMessageReceived","subscriptionRef","subscriber","addListener","message","set","webVitalsMap","WebVitals","onFirstContentfulPaint","portalName","callback","listener","event","duration","registerOnFirstContentfulPaint","onFirstInputDelay","OS","registerOnFirstInputDelay","onTimeToFirstByte","registerOnTimeToFirstByte","registerWebVitals","firstContentfulPaint","firstInputDelay","timeToFirstByte","unsubscribe","subRef","subscription","get","undefined","remove","delete","publish","data","msg","register","key","addPortal","portal","addPortals","portals","getPortal","name","enableSecureLiveUpdates","pathToKey","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n Platform,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalsReactNative, IONPortalsWebVitals } =\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\nconst webVitalsMap = new Map<string, EmitterSubscription>();\nconst WebVitals = new NativeEventEmitter(IONPortalsWebVitals);\n\ninterface WebVitalsEvent {\n portalName: string;\n duration: number;\n}\n\nexport const onFirstContentfulPaint = async (\n portalName: string,\n callback: (duration: number) => void\n): Promise<void> => {\n const listener = WebVitals.addListener(\n 'vitals:fcp',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstContentfulPaint(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n};\n\nexport const onFirstInputDelay = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:fid',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n }\n};\n\nexport const onTimeToFirstByte = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:ttfb',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnTimeToFirstByte(portalName);\n\n webVitalsMap.set(`${portalName}-vitals:ttfb`, listener);\n }\n};\n\nexport const registerWebVitals = async (\n portalName: string,\n firstContentfulPaint: (duration: number) => void,\n firstInputDelay: (duration: number) => void,\n timeToFirstByte: (duration: number) => void\n) => {\n onFirstContentfulPaint(portalName, firstContentfulPaint);\n onFirstInputDelay(portalName, firstInputDelay);\n onTimeToFirstByte(portalName, timeToFirstByte);\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 * @returns Promise<void>\n */\nexport const register = async (key: string): Promise<void> => {\n return IONPortalsReactNative.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 /** Any Capacitor plugins to be made available to the Portal */\n plugins?: CapacitorPlugin[];\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 assetMaps?: AssetMap[];\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport interface CapacitorPlugin {\n /** The classpath of the plugin to be used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidClassPath: string;\n /** The class name of the plugin to be used in iOS.\n * This must be the name as it is exposed to the Objective-C runtime.\n * For example, The CameraPlugin swift class is exposed to Objective-C as CAPCameraPlugin.\n */\n iosClassName: string;\n}\n\nexport interface AssetMap {\n /** The name to index the asset map by */\n name: string;\n /** Any path to match via the web. If omitted, {@link AssetMap#name} will be used. */\n virtualPath?: string;\n /** The root directory of the assets relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, the root of Bundle.main\n * and src/main/assets will be used.\n */\n startDir?: string;\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 * @returns Promise containing the Portal that was added to the registry.\n */\nexport const addPortal = async (portal: Portal): Promise<Portal> => {\n return IONPortalsReactNative.addPortal(portal);\n};\n\n/**\n * Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}\n *\n * @param portals The portals to add to the internal registry.\n * @returns Promise containing the Portals that were added to the registry.\n */\nexport const addPortals = async (portals: Portal[]): Promise<Portal[]> => {\n return IONPortalsReactNative.addPortals(portals);\n};\n\n/**\n * Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.\n *\n * @param name The portal name to retrieve from the internal registry.\n * @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.\n */\nexport const getPortal = async (name: string): Promise<Portal> => {\n return IONPortalsReactNative.getPortal(name);\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\nexport interface Snapshot {\n /** The snapshot id as found in AppFlow */\n id: string;\n /** The AppFlow build id that produced the snapshot */\n buildId: string;\n}\n\nexport interface SyncResult {\n /** The {@link LiveUpdate} associated with the result */\n liveUpdate: LiveUpdate;\n /** The {@link Snapshot} that was sync'd */\n snapshot: Snapshot | null;\n /** Whether the snapshot was downloaded or already on disk */\n source: 'download' | 'cache';\n /** If the active application path was changed. A `false` value would indicate\n * the application already has the latest code for the associated {@link LiveUpdate}\n * configuration.\n */\n activeApplicationPathChanged: boolean;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n results: SyncResult[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.\n * This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.\n *\n * @param pathToKey The *relative* path to the public key for verification.\n * This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.\n * @returns Promise<void>\n */\nexport const enableSecureLiveUpdates = async (\n pathToKey: string\n): Promise<void> => {\n return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);\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 = async (appId: string): Promise<SyncResult> => {\n return IONPortalsReactNative.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 = async (appIds: string[]): Promise<SyncResults> => {\n return IONPortalsReactNative.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = async (): Promise<SyncResults> => {\n return IONPortalsReactNative.syncAll();\n};\n"],"mappings":"AAAA,SAEEA,kBAAkB,EAClBC,aAAa,EACbC,QAAQ,QAEH,cAAc;AAErB,MAAM;EAAEC,eAAe;EAAEC,qBAAqB;EAAEC;AAAoB,CAAC,GACnEJ,aAAa;AAEf,SAASK,OAAO,IAAIC,UAAU,QAAQ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OpD,qBAAqB,CAACmD,uBAAuB,CAACC,SAAS,CAAC;AACjE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAG,MAAOC,KAAa,IAA0B;EACnE,OAAOtD,qBAAqB,CAACqD,OAAO,CAACC,KAAK,CAAC;AAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,MAAOC,MAAgB,IAA2B;EACxE,OAAOxD,qBAAqB,CAACuD,QAAQ,CAACC,MAAM,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAG,MAAAA,CAAA,KAAkC;EACvD,OAAOzD,qBAAqB,CAACyD,OAAO,CAAC,CAAC;AACxC,CAAC"}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","IONPortalPubSub","IONPortalsReactNative","IONPortalsWebVitals","default","PortalView","PortalsPubSub","subscribe","topic","onMessageReceived","addListener","message","publish","data","msg","webVitalsMap","Map","WebVitals","onFirstContentfulPaint","portalName","callback","listener","event","duration","registerOnFirstContentfulPaint","set","onFirstInputDelay","OS","registerOnFirstInputDelay","onTimeToFirstByte","registerOnTimeToFirstByte","registerWebVitals","firstContentfulPaint","firstInputDelay","timeToFirstByte","register","key","addPortal","portal","addPortals","portals","getPortal","name","enableSecureLiveUpdates","pathToKey","syncOne","appId","syncSome","appIds","syncAll"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n Platform,\n ViewProps,\n} from 'react-native';\n\nconst { IONPortalPubSub, IONPortalsReactNative, IONPortalsWebVitals } =\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\n// const 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 = (\n topic: string,\n onMessageReceived: (message: Message) => void\n): EmitterSubscription => {\n return PortalsPubSub.addListener(\n `PortalsSubscription:${topic}`,\n (message: Message) => {\n onMessageReceived(message);\n }\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\nconst webVitalsMap = new Map<string, EmitterSubscription>();\nconst WebVitals = new NativeEventEmitter(IONPortalsWebVitals);\n\ninterface WebVitalsEvent {\n portalName: string;\n duration: number;\n}\n\nexport const onFirstContentfulPaint = async (\n portalName: string,\n callback: (duration: number) => void\n): Promise<void> => {\n const listener = WebVitals.addListener(\n 'vitals:fcp',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstContentfulPaint(portalName);\n webVitalsMap.set(`${portalName}-vitals:fcp`, listener);\n};\n\nexport const onFirstInputDelay = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:fid',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);\n webVitalsMap.set(`${portalName}-vitals:fid`, listener);\n }\n};\n\nexport const onTimeToFirstByte = async (\n portalName: string,\n callback: (duration: number) => void\n) => {\n if (Platform.OS === 'android') {\n const listener = WebVitals.addListener(\n 'vitals:ttfb',\n (event: WebVitalsEvent) => {\n if (event.portalName === portalName) {\n callback(event.duration);\n }\n }\n );\n\n await IONPortalsWebVitals.registerOnTimeToFirstByte(portalName);\n webVitalsMap.set(`${portalName}-vitals:ttfb`, listener);\n }\n};\n\nexport const registerWebVitals = async (\n portalName: string,\n firstContentfulPaint: (duration: number) => void,\n firstInputDelay: (duration: number) => void,\n timeToFirstByte: (duration: number) => void\n) => {\n onFirstContentfulPaint(portalName, firstContentfulPaint);\n onFirstInputDelay(portalName, firstInputDelay);\n onTimeToFirstByte(portalName, timeToFirstByte);\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 * @returns Promise<void>\n */\nexport const register = async (key: string): Promise<void> => {\n return IONPortalsReactNative.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 /** Any Capacitor plugins to be made available to the Portal */\n plugins?: CapacitorPlugin[];\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 assetMaps?: AssetMap[];\n liveUpdate?: LiveUpdateConfig;\n}\n\nexport interface CapacitorPlugin {\n /** The classpath of the plugin to be used in Android. (e.g. com.capacitorjs.plugins.camera.CameraPlugin) */\n androidClassPath: string;\n /** The class name of the plugin to be used in iOS.\n * This must be the name as it is exposed to the Objective-C runtime.\n * For example, The CameraPlugin swift class is exposed to Objective-C as CAPCameraPlugin.\n */\n iosClassName: string;\n}\n\nexport interface AssetMap {\n /** The name to index the asset map by */\n name: string;\n /** Any path to match via the web. If omitted, {@link AssetMap#name} will be used. */\n virtualPath?: string;\n /** The root directory of the assets relative to Bundle.main on iOS\n * and src/main/assets on Android. If omitted, the root of Bundle.main\n * and src/main/assets will be used.\n */\n startDir?: string;\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 * @returns Promise containing the Portal that was added to the registry.\n */\nexport const addPortal = async (portal: Portal): Promise<Portal> => {\n return IONPortalsReactNative.addPortal(portal);\n};\n\n/**\n * Adds all portals to an internal registry. This or {@link addPortal} must be called before attempting to render a {@link PortalView}\n *\n * @param portals The portals to add to the internal registry.\n * @returns Promise containing the Portals that were added to the registry.\n */\nexport const addPortals = async (portals: Portal[]): Promise<Portal[]> => {\n return IONPortalsReactNative.addPortals(portals);\n};\n\n/**\n * Gets a {@link Portal} previously registered via {@link addPortal} or {@link addPortals}.\n *\n * @param name The portal name to retrieve from the internal registry.\n * @returns Promise containing the registered {@link Portal}. If the {@link Portal} was not registered, the Promise will fail.\n */\nexport const getPortal = async (name: string): Promise<Portal> => {\n return IONPortalsReactNative.getPortal(name);\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\nexport interface Snapshot {\n /** The snapshot id as found in AppFlow */\n id: string;\n /** The AppFlow build id that produced the snapshot */\n buildId: string;\n}\n\nexport interface SyncResult {\n /** The {@link LiveUpdate} associated with the result */\n liveUpdate: LiveUpdate;\n /** The {@link Snapshot} that was sync'd */\n snapshot: Snapshot | null;\n /** Whether the snapshot was downloaded or already on disk */\n source: 'download' | 'cache';\n /** If the active application path was changed. A `false` value would indicate\n * the application already has the latest code for the associated {@link LiveUpdate}\n * configuration.\n */\n activeApplicationPathChanged: boolean;\n}\n\n/** Used for communicating sync results of multiple live updates */\nexport interface SyncResults {\n results: SyncResult[];\n errors: LiveUpdateError[];\n}\n\n/**\n * Configures LiveUpdates to cyrptographically verify the contents of the downloaded bundles.\n * This method must be called before any LiveUpdates are registered otherwise they will no longer be tracked.\n *\n * @param pathToKey The *relative* path to the public key for verification.\n * This path should be the same relatibe to the main application bundle on iOS and the assets directory on Android.\n * @returns Promise<void>\n */\nexport const enableSecureLiveUpdates = async (\n pathToKey: string\n): Promise<void> => {\n return IONPortalsReactNative.enableSecureLiveUpdates(pathToKey);\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 = async (appId: string): Promise<SyncResult> => {\n return IONPortalsReactNative.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 = async (appIds: string[]): Promise<SyncResults> => {\n return IONPortalsReactNative.syncSome(appIds);\n};\n\n/**\n * Syncs all registered LiveUpdates\n * @returns Promise<SyncResults>\n */\nexport const syncAll = async (): Promise<SyncResults> => {\n return IONPortalsReactNative.syncAll();\n};\n"],"mappings":"AAAA,SAEEA,kBAAkB,EAClBC,aAAa,EACbC,QAAQ,QAEH,cAAc;AAErB,MAAM;EAAEC,eAAe;EAAEC,qBAAqB;EAAEC;AAAoB,CAAC,GACnEJ,aAAa;AAEf,SAASK,OAAO,IAAIC,UAAU,QAAQ,cAAc;;AAEpD;AACA;AACA;;AASA,MAAMC,aAAa,GAAG,IAAIR,kBAAkB,CAACG,eAAe,CAAC;;AAE7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,SAAS,GAAGA,CACvBC,KAAa,EACbC,iBAA6C,KACrB;E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AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,MAAOC,OAAiB,IAAwB;EACxE,OAAOtC,qBAAqB,CAACqC,UAAU,CAACC,OAAO,CAAC;AAClD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAG,MAAOC,IAAY,IAAsB;EAChE,OAAOxC,qBAAqB,CAACuC,SAAS,CAACC,IAAI,CAAC;AAC9C,CAAC;;AASD;;AAiCA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,GAAG,MACrCC,SAAiB,IACC;EAClB,OAAO1C,qBAAqB,CAACyC,uBAAuB,CAACC,SAAS,CAAC;AACjE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAG,MAAOC,KAAa,IAA0B;EACnE,OAAO5C,qBAAqB,CAAC2C,OAAO,CAACC,KAAK,CAAC;AAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,MAAOC,MAAgB,IAA2B;EACxE,OAAO9C,qBAAqB,CAAC6C,QAAQ,CAACC,MAAM,CAAC;AAC/C,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,OAAO,GAAG,MAAAA,CAAA,KAAkC;EACvD,OAAO/C,qBAAqB,CAAC+C,OAAO,CAAC,CAAC;AACxC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { ViewProps } from 'react-native';
1
+ import { EmitterSubscription, ViewProps } from 'react-native';
2
2
  export { default as PortalView } from './PortalView';
3
3
  /**
4
4
  * The data that is received from a subscription event.
@@ -17,18 +17,7 @@ export interface Message {
17
17
  * @param onMessageReceived The callback to invoke when a message is received
18
18
  * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
19
19
  */
20
- export declare const subscribe: (topic: string, onMessageReceived: (message: Message) => void) => Promise<number>;
21
- export declare const onFirstContentfulPaint: (portalName: string, callback: (duration: number) => void) => Promise<void>;
22
- export declare const onFirstInputDelay: (portalName: string, callback: (duration: number) => void) => Promise<void>;
23
- export declare const onTimeToFirstByte: (portalName: string, callback: (duration: number) => void) => Promise<void>;
24
- export declare const registerWebVitals: (portalName: string, firstContentfulPaint: (duration: number) => void, firstInputDelay: (duration: number) => void, timeToFirstByte: (duration: number) => void) => Promise<void>;
25
- /**
26
- * Unsubscribes from events for the provided topic and subscription reference
27
- *
28
- * @param topic The topic to unsubscribe from
29
- * @param subRef The unique subscription reference received when initially calling {@link subscribe}
30
- */
31
- export declare const unsubscribe: (topic: string, subRef: number) => void;
20
+ export declare const subscribe: (topic: string, onMessageReceived: (message: Message) => void) => EmitterSubscription;
32
21
  /**
33
22
  * Publishes a message to the provided topic
34
23
  *
@@ -36,6 +25,10 @@ export declare const unsubscribe: (topic: string, subRef: number) => void;
36
25
  * @param data The data to publish to subscribers
37
26
  */
38
27
  export declare const publish: (topic: string, data: any) => void;
28
+ export declare const onFirstContentfulPaint: (portalName: string, callback: (duration: number) => void) => Promise<void>;
29
+ export declare const onFirstInputDelay: (portalName: string, callback: (duration: number) => void) => Promise<void>;
30
+ export declare const onTimeToFirstByte: (portalName: string, callback: (duration: number) => void) => Promise<void>;
31
+ export declare const registerWebVitals: (portalName: string, firstContentfulPaint: (duration: number) => void, firstInputDelay: (duration: number) => void, timeToFirstByte: (duration: number) => void) => Promise<void>;
39
32
  /**
40
33
  * Validates that a valid registration key has been procured from http://ionic.io/register-portals
41
34
  * @param key The registration key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ionic/portals-react-native",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Ionic Portals for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ts CHANGED
@@ -24,7 +24,7 @@ export interface Message {
24
24
 
25
25
  const PortalsPubSub = new NativeEventEmitter(IONPortalPubSub);
26
26
 
27
- const subscriptionMap = new Map<number, EmitterSubscription>();
27
+ // const subscriptionMap = new Map<number, EmitterSubscription>();
28
28
 
29
29
  /**
30
30
  * Subscribes to messages for a topic
@@ -33,24 +33,27 @@ const subscriptionMap = new Map<number, EmitterSubscription>();
33
33
  * @param onMessageReceived The callback to invoke when a message is received
34
34
  * @returns A Promise<number> containing the unique subscription reference. This will need to be stored for calling {@link unsubscribe}.
35
35
  */
36
- export const subscribe = async (
36
+ export const subscribe = (
37
37
  topic: string,
38
38
  onMessageReceived: (message: Message) => void
39
- ): Promise<number> => {
40
- const subscriptionRef = await IONPortalPubSub.subscribe(topic);
41
-
42
- const subscriber = PortalsPubSub.addListener(
43
- 'PortalsSubscription',
39
+ ): EmitterSubscription => {
40
+ return PortalsPubSub.addListener(
41
+ `PortalsSubscription:${topic}`,
44
42
  (message: Message) => {
45
- if (message.subscriptionRef === subscriptionRef) {
46
- onMessageReceived(message);
47
- }
43
+ onMessageReceived(message);
48
44
  }
49
45
  );
46
+ };
50
47
 
51
- subscriptionMap.set(subscriptionRef, subscriber);
52
-
53
- return subscriptionRef;
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
+ export const publish = (topic: string, data: any) => {
55
+ const msg = { message: data };
56
+ IONPortalPubSub.publish(topic, msg);
54
57
  };
55
58
 
56
59
  const webVitalsMap = new Map<string, EmitterSubscription>();
@@ -75,7 +78,6 @@ export const onFirstContentfulPaint = async (
75
78
  );
76
79
 
77
80
  await IONPortalsWebVitals.registerOnFirstContentfulPaint(portalName);
78
-
79
81
  webVitalsMap.set(`${portalName}-vitals:fcp`, listener);
80
82
  };
81
83
 
@@ -94,8 +96,7 @@ export const onFirstInputDelay = async (
94
96
  );
95
97
 
96
98
  await IONPortalsWebVitals.registerOnFirstInputDelay(portalName);
97
-
98
- webVitalsMap.set(`${portalName}-vitals:fcp`, listener);
99
+ webVitalsMap.set(`${portalName}-vitals:fid`, listener);
99
100
  }
100
101
  };
101
102
 
@@ -114,7 +115,6 @@ export const onTimeToFirstByte = async (
114
115
  );
115
116
 
116
117
  await IONPortalsWebVitals.registerOnTimeToFirstByte(portalName);
117
-
118
118
  webVitalsMap.set(`${portalName}-vitals:ttfb`, listener);
119
119
  }
120
120
  };
@@ -130,33 +130,6 @@ export const registerWebVitals = async (
130
130
  onTimeToFirstByte(portalName, timeToFirstByte);
131
131
  };
132
132
 
133
- /**
134
- * Unsubscribes from events for the provided topic and subscription reference
135
- *
136
- * @param topic The topic to unsubscribe from
137
- * @param subRef The unique subscription reference received when initially calling {@link subscribe}
138
- */
139
- export const unsubscribe = (topic: string, subRef: number) => {
140
- IONPortalPubSub.unsubscribe(topic, subRef);
141
-
142
- const subscription = subscriptionMap.get(subRef);
143
- if (subscription !== undefined) {
144
- subscription.remove();
145
- subscriptionMap.delete(subRef);
146
- }
147
- };
148
-
149
- /**
150
- * Publishes a message to the provided topic
151
- *
152
- * @param topic The topic to publish the message to
153
- * @param data The data to publish to subscribers
154
- */
155
- export const publish = (topic: string, data: any) => {
156
- const msg = { message: data };
157
- IONPortalPubSub.publish(topic, msg);
158
- };
159
-
160
133
  /**
161
134
  * Validates that a valid registration key has been procured from http://ionic.io/register-portals
162
135
  * @param key The registration key