-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add huawei wear engine support #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabOnReact
wants to merge
1
commit into
main
Choose a base branch
from
codex/add-react-native-wear-engine-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"app_id": "00000000000000000000000000000000", | ||
"cp_id": "00000000000000000000000000000000", | ||
"client": { | ||
"client_info": { | ||
"mobilesdk_app_id": "00000000000000000000000000000000", | ||
"package_name": "com.example.app" | ||
}, | ||
"oauth_client": [] | ||
}, | ||
"configuration_version": "1.0" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Huawei Setup | ||
|
||
To use Huawei wearables with this library you must configure Huawei Mobile Services (HMS) and pair the watch with your phone. | ||
|
||
## HMS Core configuration | ||
|
||
1. Create an app in the [Huawei Developer Console](https://developer.huawei.com/). | ||
2. Download the `agconnect-services.json` file and place it in your Android project under `android/agconnect-services.json`. | ||
3. Ensure the following are added to your `android/build.gradle`: | ||
- `maven { url 'https://developer.huawei.com/repo/' }` | ||
- `classpath 'com.huawei.agconnect:agcp:1.9.1.301'` | ||
- `implementation 'com.huawei.hms:wearengine:5.0.0.300'` | ||
4. Apply the `com.huawei.agconnect` plugin and sync your project. | ||
|
||
## Pairing the watch | ||
|
||
1. Install the Huawei Health app on your mobile device. | ||
2. Sign in with your Huawei ID and add your wearable device. | ||
3. Ensure the watch is connected via Bluetooth before testing message or file transfer APIs. | ||
|
||
These steps prepare the environment so `react-native-wear-engine` can communicate with the paired Huawei watch through this library's unified API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DeviceEventEmitter } from 'react-native'; | ||
import type { Payload } from '../NativeWearConnectivity'; | ||
|
||
let WearEngine: any; | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
WearEngine = require('react-native-wear-engine'); | ||
} catch (e) { | ||
// Module might not be available in development environments. | ||
WearEngine = null; | ||
} | ||
|
||
/** | ||
* Maps Huawei Wear Engine callbacks to the library unified events. | ||
* Call this once when the app starts to bridge incoming messages. | ||
*/ | ||
export function registerHuaweiListeners() { | ||
if (!WearEngine || !WearEngine.addListener) { | ||
return; | ||
} | ||
|
||
WearEngine.addListener('message', (payload: Payload) => { | ||
DeviceEventEmitter.emit('message', payload); | ||
}); | ||
|
||
WearEngine.addListener('fileTransfer', (event: any) => { | ||
DeviceEventEmitter.emit('FileTransferEvent', event); | ||
}); | ||
} | ||
|
||
/** | ||
* Sends a message to the connected Huawei wearable using Wear Engine. | ||
*/ | ||
export function sendHuaweiMessage(message: Payload) { | ||
if (!WearEngine || !WearEngine.sendMessage) { | ||
return Promise.reject('react-native-wear-engine not available'); | ||
} | ||
|
||
return WearEngine.sendMessage(message); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Huawei events never reach watchEvents API
registerHuaweiListeners forwards Wear Engine callbacks to
DeviceEventEmitter
, but the library’s publicwatchEvents
helper listens via aNativeEventEmitter
attached to the Android module. Because nothing subscribes toDeviceEventEmitter
for'message'
, consumers callingwatchEvents.on('message')
will miss Huawei messages even after registering these listeners, so the new connector doesn’t actually integrate with the existing event API.Useful? React with 👍 / 👎.