npm install --save @egym/mwa-utils
getPortalsInitialContext
is the same asgetInitialContext
from the standard@ionic/portals
package, but with support for both v4 and v5 Capacitor versionsportalsPublish
is the same aspublish
from the standard@ionic/portals
package, but with extra logging with the help of@egym/mwa-logger
portalsSubscribe
is the same assubscribe
from the standard@ionic/portals
package, but with extra logging with the help of@egym/mwa-logger
getMwaInitialContext()
returns the initial context typed asMwaInitialContext
.
The following functions are available to send commands to the BMA:
publishAuthToken()
publishes theauthToken
to the BMA.publishDismiss()
publishes thedismiss
command to the BMA.publishExerciserInfo()
publishes theexerciserInfo
to the BMA.publishOpenFeature(startingRoute: string)
publishes theopenFeature
command to the BMA.startingRoute
is the route to open the feature at.
publishOpenNativeFeature(featureId: string, data?: { [key: string]: string })
publishes theopenNativeFeature
command to the BMA.featureId
is the id of the feature to open.data
is an optional object with key-value pairs to pass to the feature.
publishOpenWebView(url: string, endFlowUrlPatterns: string[] = [])
publishes theopenWebView
command to the BMA.url
is the url to open in the webview.endFlowUrlPatterns
is an optional array of strings that will be used to close the webview when a url matches any of the patterns.
publishOpenUrlExternally(url: string)
publishes theopenUrlExternally
command to the BMA.url
is the url to open in the external web view.
publishTrackEvent(eventName: string, parameters?: { [key: string]: string })
publishes thetrackEvent
command to the BMA.eventName
is the name of the event to track.parameters
is an optional object with key-value pairs to pass to the event.
The following functions are available to subscribe to the BMA messages:
subscribeBack(callback: (result: PortalMessage<void>) => void)
subscribes to theback
subscription. The BMA will send aback
message when the user presses the back button for instance.callback
is a function that will be called when theback
message is received.
subscribeAuthToken(callback: (result: PortalMessage<string>)
subscribes to theauthToken
subscription. The BMA will send theauthToken
message when the MWA send the commandpublishAuthToken()
.callback
is a function that will be called when theauthToken
message is received.
subscribeExerciserInfo(callback: (result: PortalMessage<MwaExerciserInfo>) => void)
subscribes to theexerciserInfo
subscription. The BMA will send theexerciserInfo
message when the MWA send the commandpublishExerciserInfo()
.callback
is a function that will be called when theexerciserInfo
message is received.
The MWA Flows are an abstraction that combines the commands and subscriptions to provide a more user-friendly API. The following functions that implement the MWA Flows are available:
getAuthTokenFlow()
returns a promise that resolves with theauthToken
sent by the BMA over theauthToken
subscription topic. When this function is invoked, the subscription to theauthToken
is done as part of invocation, and, theauthToken
command is sent to the BMA. When the BMA send theauthToken
message, the promise resolves with the message data and unsubscribes from theauthToken
subscription.getExerciserInfoFlow()
returns a promise that resolves with theexerciserInfo
sent by the BMA over theexerciserInfo
subscription topic. When this function is invoked, the subscription to theexerciserInfo
is done as part of invocation, and, theexerciserInfo
command is sent to the BMA. When the BMA App send theexerciserInfo
message, the promise resolves with the message data and unsubscribes from theexerciserInfo
subscription.
Install the dependencies:
npm run install
Run and debug the module:
npm run dev
Run test cases:
npm run test
Build the module for production:
npm run build
Enable optional features:
npm run new
Other commands:
npm run lint # Lint and fix source files
npm run change # Add a new changeset
npm run bump # Update version and changelog via changeset
npm run release # Release the package
For more information, see the Modern.js Module documentation.