npm install --save @egym/mwa-utils
getPortalsInitialContextis the same asgetInitialContextfrom the standard@ionic/portalspackage, but with support for both v4 and v5 Capacitor versionsportalsPublishis the same aspublishfrom the standard@ionic/portalspackage, but with extra logging with the help of@egym/mwa-loggerportalsSubscribeis the same assubscribefrom the standard@ionic/portalspackage, 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 theauthTokento the BMA.publishDismiss()publishes thedismisscommand to the BMA.publishExerciserInfo()publishes theexerciserInfoto the BMA.publishOpenFeature(startingRoute: string)publishes theopenFeaturecommand to the BMA.startingRouteis the route to open the feature at.
publishOpenNativeFeature(featureId: string, data?: { [key: string]: string })publishes theopenNativeFeaturecommand to the BMA.featureIdis the id of the feature to open.datais an optional object with key-value pairs to pass to the feature.
publishOpenWebView(url: string, endFlowUrlPatterns: string[] = [])publishes theopenWebViewcommand to the BMA.urlis the url to open in the webview.endFlowUrlPatternsis 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 theopenUrlExternallycommand to the BMA.urlis the url to open in the external web view.
publishTrackEvent(eventName: string, feature?: string, parameters?: { [key: string]: string })publishes thetrackEventcommand to the BMA.eventNameis the name of the event to track.featureis an optional string parameter represents the feature where the event is tracked. If not specified, Firebase Analytics tracking will be used by default. If specified, the event will be tracked using a custom Backend or Segment analytics, depending on whether Segment settings are enabled for the brand.parametersis an optional object with key-value pairs to pass to the event.
publishOpenAppSettings()publishes theopenAppSettingscommand to the BMA.- This command requests the native app to open the device’s app settings screen, allowing the user to enable permissions such as location access.
The following functions are available to subscribe to the BMA messages:
subscribeBack(callback: (result: PortalMessage<void>) => void)subscribes to thebacksubscription. The BMA will send abackmessage when the user presses the back button for instance.callbackis a function that will be called when thebackmessage is received.
subscribeAuthToken(callback: (result: PortalMessage<string>)subscribes to theauthTokensubscription. The BMA will send theauthTokenmessage when the MWA send the commandpublishAuthToken().callbackis a function that will be called when theauthTokenmessage is received.
subscribeExerciserInfo(callback: (result: PortalMessage<MwaExerciserInfo>) => void)subscribes to theexerciserInfosubscription. The BMA will send theexerciserInfomessage when the MWA send the commandpublishExerciserInfo().callbackis a function that will be called when theexerciserInfomessage 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 theauthTokensent by the BMA over theauthTokensubscription topic. When this function is invoked, the subscription to theauthTokenis done as part of invocation, and, theauthTokencommand is sent to the BMA. When the BMA send theauthTokenmessage, the promise resolves with the message data and unsubscribes from theauthTokensubscription.getExerciserInfoFlow()returns a promise that resolves with theexerciserInfosent by the BMA over theexerciserInfosubscription topic. When this function is invoked, the subscription to theexerciserInfois done as part of invocation, and, theexerciserInfocommand is sent to the BMA. When the BMA App send theexerciserInfomessage, the promise resolves with the message data and unsubscribes from theexerciserInfosubscription.
Install the dependencies:
npm run installRun and debug the module:
npm run devRun test cases:
npm run testBuild the module for production:
npm run buildEnable optional features:
npm run newRelease/publish changes to npm:
npm run lint # Lint and fix source files
npm run change # Add a new changeset
npm run bump # Update version and changelog via changesetPush changes to the branch, create tag and draft release
For more information, see the Modern.js Module documentation.