@@ -10,16 +10,28 @@ 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
19
24
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,62 +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. */
66
104
index ?: string ;
105
+ /** Any data needed at initial render when a portal is loaded. */
67
106
initialContext ?: {
68
107
[ key : string ] : any ;
69
108
} ;
70
109
liveUpdate ?: LiveUpdateConfig ;
71
110
}
72
111
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
+ */
73
116
export type PortalProp = {
74
117
portal : Pick < Portal , 'name' | 'initialContext' > ;
75
118
} ;
76
119
120
+ /**
121
+ * Props needed for rendering a {@link Portal}
122
+ */
77
123
export type PortalProps = PortalProp & ViewProps ;
78
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
+ */
79
130
export const addPortal = ( portal : Portal ) => {
80
131
IONPortalManager . addPortal ( portal ) ;
81
132
} ;
82
133
83
134
export interface LiveUpdate {
135
+ /** The AppFlow application ID */
84
136
appId : string ;
137
+ /** The AppFlow distribution channel */
85
138
channel : string ;
86
139
}
87
140
141
+ /** Data needed to register a live update to be managed */
88
142
export type LiveUpdateConfig = LiveUpdate & { syncOnAdd : boolean } ;
89
143
90
144
export interface LiveUpdateError {
145
+ /** The AppFlow application ID relating to the failure */
91
146
appId : string ;
147
+ /** The step in the sync process the LiveUpdate failed on. (e.g. CHECK, UNPACK)*/
92
148
failStep : string ;
149
+ /** A human readable error message */
93
150
message : string ;
94
151
}
95
152
153
+ /** Used for communicating sync results of multiple live updates */
96
154
export interface SyncResults {
97
155
liveUpdates : LiveUpdate [ ] ;
98
156
errors : LiveUpdateError [ ] ;
99
157
}
100
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
+ */
101
165
export const syncOne = ( appId : string ) : Promise < LiveUpdate > => {
102
166
return IONLiveUpdatesManager . syncOne ( appId ) ;
103
167
} ;
104
168
169
+ /**
170
+ * Syncs many live updates.
171
+ *
172
+ * @param appIds The AppFlow application IDs to sync.
173
+ * @returns Promise<SyncResults>
174
+ */
105
175
export const syncSome = ( appIds : string [ ] ) : Promise < SyncResults > => {
106
176
return IONLiveUpdatesManager . syncSome ( appIds ) ;
107
177
} ;
108
178
179
+ /**
180
+ * Syncs all registered LiveUpdates
181
+ * @returns Promise<SyncResults>
182
+ */
109
183
export const syncAll = ( ) : Promise < SyncResults > => {
110
184
return IONLiveUpdatesManager . syncAll ( ) ;
111
185
} ;
0 commit comments