Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Allows you to connect React Native Mobile apps with WearOS.
- [Jetpack Compose API Documentation](#jetpack-compose-api-documentation)
- [How to run the example](#how-to-run-the-example)
- [Alternative methods of installation](#alternative-methods-of-installation)
- [Huawei Setup](#huawei-setup)
- [FAQ on Troubleshooting Errors](#faq-on-troubleshooting-errors)
- [Contributing](#contributing)

Expand Down Expand Up @@ -321,6 +322,10 @@ You can copy the [implementation](https://github.com/fabOnReact/wearos-communica

The instructions for writing the WearOS apps with react-native are available at [alternative-installation.md](docs/alternative-installation.md). React Native does not officially support WearOS, some essential components like CircularScrollView are not available in React Native. More info in Issues https://github.com/fabOnReact/react-native-wear-connectivity/issues/12 and https://github.com/andrew-levy/jetpack-compose-react-native/issues/9.

## Huawei Setup

Instructions for integrating Huawei wearables and HMS Core are available in [docs/huawei-setup.md](docs/huawei-setup.md).

## FAQ on Troubleshooting Errors

While some error messages are displayed on the metro server for the mobile or wearOS device (port 8082), other warnings are only available through logcat.
Expand Down
12 changes: 12 additions & 0 deletions android/agconnect-services.json
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"
}
5 changes: 5 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
classpath 'com.huawei.agconnect:agcp:1.9.1.301'
}
}

Expand All @@ -14,6 +16,7 @@ def isNewArchitectureEnabled() {
}

apply plugin: "com.android.library"
apply plugin: 'com.huawei.agconnect'

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
Expand Down Expand Up @@ -93,6 +96,7 @@ android {
repositories {
mavenCentral()
google()
maven { url 'https://developer.huawei.com/repo/' }
}


Expand All @@ -102,6 +106,7 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation 'com.google.android.gms:play-services-wearable:18.1.0'
implementation 'com.huawei.hms:wearengine:5.0.0.300'
}

if (isNewArchitectureEnabled()) {
Expand Down
21 changes: 21 additions & 0 deletions docs/huawei-setup.md
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.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"react-native-wear-engine": "^1.0.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^17.0.2",
"@react-native/eslint-config": "^0.72.2",
Expand Down
40 changes: 40 additions & 0 deletions src/huawei/HuaweiConnector.ts
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) => {
Comment on lines +17 to +26

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 public watchEvents helper listens via a NativeEventEmitter attached to the Android module. Because nothing subscribes to DeviceEventEmitter for 'message', consumers calling watchEvents.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 👍 / 👎.

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);
}