{"_id":"@bingtang-rn/react-native-notification-sounds","_rev":"2-00db80cb54c463c2e802e8e16094b619","name":"@bingtang-rn/react-native-notification-sounds","dist-tags":{"latest":"0.5.9"},"versions":{"0.5.8":{"name":"@bingtang-rn/react-native-notification-sounds","version":"0.5.8","keywords":["react-native","harmony","harmonyos","react-native-notification-sounds"],"license":"MIT","_id":"@bingtang-rn/react-native-notification-sounds@0.5.8","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","dist":{"shasum":"4728090ea20a85f0a643c7e217ab9a661ad20225","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-notification-sounds/-/react-native-notification-sounds-0.5.8.tgz","fileCount":40,"integrity":"sha512-StLuBTT6qlOY0GQrcJqWW0/51AwUH5wlbilgnknvksaFYLzz4WYublcVS5sT6LtYsMy77L7v17iWaPxJigMWBg==","signatures":[{"sig":"MEYCIQCtp2ZkY+PgBKPY4Ow8aBXEPjaomGu6AbUXK9Hwj4wRXwIhAJ9OTyomsICXcOHp4WzNr0rQDvfLQT+Hs7IjTfy9c5bT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":130347},"main":"./src/index.ts","module":"./src/index.ts","engines":{"node":">=18"},"gitHead":"1cbd78efd6f239d6046ece5015fe1dcd7a4d8a7c","harmony":{"alias":"react-native-notification-sounds","autolinking":{"ohPackageName":"@oh-rn/react-native-notification-sounds","cppPackageClassName":"NotificationSoundsPackage","etsPackageClassName":"NotificationSoundsPackage","cmakeLibraryTargetName":"notification_sounds"},"codegenConfig":[{"version":1,"specPaths":["./src/specs/v1"]}]},"private":false,"scripts":{"prepare":"echo skip","codegen-lib":"react-native codegen-harmony --cpp-output-path ./harmony/notification_sounds/src/main/cpp/generated --ets-output-path ./harmony/notification_sounds/src/main/ets/generated"},"_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_notification_sounds组件。","directories":{},"_nodeVersion":"24.15.0","react-native":"./src/index.ts","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.3","metro":"^0.81.0","react":"18.2.0","typescript":"5.0.4","@types/react":"18.2.79","react-native":"0.72.5","@react-native/typescript-config":"0.79.5","@react-native-oh/react-native-harmony-cli":"^0.77.50"},"peerDependencies":{"react-native":">=0.72"},"_npmOperationalInternal":{"tmp":"tmp/react-native-notification-sounds_0.5.8_1785417771242_0.6883054636182573","host":"s3://npm-registry-packages-npm-production"}},"0.5.9":{"_id":"@bingtang-rn/react-native-notification-sounds@0.5.9","dist":{"shasum":"8fa7e5f7076f5288c6617615986e89f187bcb58f","tarball":"https://registry.npmjs.org/@bingtang-rn/react-native-notification-sounds/-/react-native-notification-sounds-0.5.9.tgz","fileCount":40,"integrity":"sha512-d7vhgd8EZmPuPx1qTzI/CBIXa4uTuGpBBoyZmHLjxYTQy2ZPl4gvxvaPgjTBNiFKRdNuzg9ZWS14hJZid03qmQ==","signatures":[{"sig":"MEUCIBXmwH09bM/S4U46RDziU8lkskCPyU/PiUHu7WU4gOidAiEAuMfjbhayIjZ16XCo6j23saTzkvKPs0pJSjnZklqFNLQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD3j2WDmJQsmAu1Yzz7pdBMdFZRk5qYRfTjROs2xLIpLAIhAPgxWksUuyIyLI7+zgXFAAju4NSjZ56YeXieMs5faCWz"}],"unpackedSize":130774},"main":"./src/index.ts","name":"@bingtang-rn/react-native-notification-sounds","_from":"file:bingtang-rn-react-native-notification-sounds-0.5.9.tgz","module":"./src/index.ts","engines":{"node":">=18"},"harmony":{"alias":"react-native-notification-sounds","autolinking":{"ohPackageName":"@bingtang-rn/react-native-notification-sounds","cppPackageClassName":"NotificationSoundsPackage","etsPackageClassName":"NotificationSoundsPackage","cmakeLibraryTargetName":"notification_sounds"},"codegenConfig":[{"version":1,"specPaths":["./src/specs/v1"]}]},"license":"MIT","private":false,"scripts":{"prepare":"echo skip","codegen-lib":"react-native codegen-harmony --cpp-output-path ./harmony/notification_sounds/src/main/cpp/generated --ets-output-path ./harmony/notification_sounds/src/main/ets/generated"},"version":"0.5.9","_npmUser":{"name":"luyizouyuan","email":"189605613@qq.com"},"homepage":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","keywords":["react-native","harmony","harmonyos","react-native-notification-sounds"],"_resolved":"D:\\code\\rn\\npm\\batch\\react_native_notification_sounds\\bingtang-rn-react-native-notification-sounds-0.5.9.tgz","_integrity":"sha512-d7vhgd8EZmPuPx1qTzI/CBIXa4uTuGpBBoyZmHLjxYTQy2ZPl4gvxvaPgjTBNiFKRdNuzg9ZWS14hJZid03qmQ==","repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","type":"git"},"_npmVersion":"11.12.1","description":"适配鸿蒙版本，提供react_native_notification_sounds组件。","directories":{},"maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"_nodeVersion":"24.15.0","react-native":"./src/index.ts","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.6.3","metro":"^0.81.0","react":"18.2.0","typescript":"5.0.4","@types/react":"18.2.79","react-native":"0.72.5","@react-native/typescript-config":"0.79.5","@react-native-oh/react-native-harmony-cli":"^0.77.50"},"peerDependencies":{"react-native":">=0.72"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-native-notification-sounds_0.5.9_1790569232747_0.7560448816901717"}}},"time":{"created":"2026-07-30T13:22:50.933Z","modified":"2026-09-28T04:20:34.054Z","0.5.8":"2026-07-30T13:22:51.410Z","0.5.9":"2026-09-28T04:20:32.855Z"},"license":"MIT","homepage":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","keywords":["react-native","harmony","harmonyos","react-native-notification-sounds"],"repository":{"url":"https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds","type":"git"},"description":"适配鸿蒙版本，提供react_native_notification_sounds组件。","maintainers":[{"name":"luyizouyuan","email":"189605613@qq.com"}],"readme":"# @bingtang-rn/react-native-notification-sounds for HarmonyOS\r\n\r\n本项目基于 [react-native-notification-sounds](https://github.com/saadqbal/react-native-notification-sounds) 开发，为 React Native 鸿蒙（OpenHarmony）适配版本。如果在使用过程中有任何问题，可以在GitCode提Issue，会及时跟进。issue地址：[issues](https://gitcode.com/rn_ohos_plugin/react_native_notification_sounds/issues)。\r\n\r\n## 版本对应关系\r\n\r\n| 鸿蒙适配包版本 | 原始库版本 | 支持 RN 版本 | Autolink | 编译 API 版本 |\r\n| ------------ | ---------- | ------------ | -------- | ------------- |\r\n| 0.5.8 | 0.5.8 | 0.72+ | 是 | API17+ |\r\n\r\n## 安装\r\n\r\n```bash\r\nnpm install @bingtang-rn/react-native-notification-sounds\r\n```\r\n\r\n## 使用\r\n\r\n```tsx\r\nimport NotificationSounds, {\r\n  playSampleSound,\r\n  stopSampleSound,\r\n} from 'react-native-notification-sounds';\r\n\r\n// 获取声音列表\r\nconst sounds = await NotificationSounds.getNotifications('notification');\r\n\r\n// 试听播放\r\nplaySampleSound(sounds[0]);\r\n\r\n// 停止试听\r\nstopSampleSound();\r\n```\r\n\r\n> import 时使用原库名 `'react-native-notification-sounds'`，而非鸿蒙包名（由 RNOH alias 自动映射）。\r\n\r\n**平台差异**：\r\n- HarmonyOS 上 `getNotifications` 返回的是应用内置示例铃声资源列表，而非系统铃声列表（鸿蒙公开 API 不提供枚举系统铃声能力）。\r\n- `url` 字段语义为 rawfile 相对路径（如 `\"notification/notification_01.wav\"`），非 Android 的 `content://` 或 iOS 的 `file://` URI。\r\n\r\n**权限要求**：\r\n- 无需额外权限（rawfile 资源访问与 SoundPool 播放均不需要运行时权限）。\r\n\r\n## Link\r\n\r\n| 版本 | 是否支持 Autolink |\r\n|------|------------------|\r\n| 当前版本 | 是 |\r\n\r\n如使用版本支持 Autolink 且工程已接入，可跳过手动配置。\r\n\r\n<details>\r\n<summary>Manual Link 配置</summary>\r\n\r\n> **说明**：本模块需要同时在 C++ 侧和 ETS 侧注册 Package。\r\n\r\n### 1. Overrides RN SDK\r\n\r\n在工程根目录 `oh-package.json5` 添加：\r\n\r\n```json\r\n{\r\n  \"overrides\": {\r\n    \"@rnoh/react-native-openharmony\": \"./react_native_openharmony\"\r\n  }\r\n}\r\n```\r\n\r\n### 2. 引入原生端依赖\r\n\r\n打开 `entry/oh-package.json5`，添加：\r\n\r\n```json\r\n\"dependencies\": {\r\n  \"@bingtang-rn/react-native-notification-sounds\": \"file:../../node_modules/@bingtang-rn/react-native-notification-sounds/harmony/notification_sounds.har\"\r\n}\r\n```\r\n\r\n执行 `ohpm install`。\r\n\r\n### 3. 配置 CMakeLists\r\n\r\n打开 `entry/src/main/cpp/CMakeLists.txt`，添加：\r\n\r\n```cmake\r\nset(OH_MODULES \"${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules\")\r\n\r\nadd_subdirectory(\"${OH_MODULES}/@bingtang-rn/react-native-notification-sounds/src/main/cpp\" ./notification_sounds)\r\n\r\ntarget_link_libraries(rnoh_app PUBLIC notification_sounds)\r\n```\r\n\r\n### 4. 注册 Package（C++ 侧）\r\n\r\n打开 `entry/src/main/cpp/PackageProvider.cpp`，添加：\r\n\r\n```cpp\r\n#include \"NotificationSoundsPackage.h\"\r\n\r\nstd::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {\r\n    return {\r\n        std::make_shared<NotificationSoundsPackage>(ctx),\r\n    };\r\n}\r\n```\r\n\r\n### 5. 注册 Package（ETS 侧）\r\n\r\n打开 `entry/src/main/ets/RNPackagesFactory.ets`，添加：\r\n\r\n```typescript\r\nimport { NotificationSoundsPackage } from '@bingtang-rn/react-native-notification-sounds/ts';\r\n\r\nexport function createRNPackages(ctx: RNPackageContext): RNPackage[] {\r\n  return [\r\n    new NotificationSoundsPackage(ctx),\r\n  ];\r\n}\r\n```\r\n\r\n</details>\r\n\r\n## 属性 / API\r\n\r\n| API | 描述 | 参数 | 返回值 | HarmonyOS 支持 |\r\n|-----|------|------|--------|----------------|\r\n| getNotifications | 按类型获取声音列表 | type: 'notification' \\| 'ringtone' \\| 'alarm' | Promise<Sound[]> | ⚠️ 部分支持（降级为应用内置铃声资源，非系统铃声） |\r\n| playSample | 试听播放指定声音 | uri: string | void | ✅ 完全支持（使用 SoundPool） |\r\n| stopSample | 停止当前试听播放 | 无 | void | ✅ 完全支持（使用 SoundPool.stop/unload） |\r\n| playSampleSound | 试听播放（JS 封装，取 sound.url 调 playSample） | sound: Sound | void | ✅ 完全支持 |\r\n| stopSampleSound | 停止试听（JS 封装，调 stopSample） | 无 | void | ✅ 完全支持 |\r\n\r\n### 平台差异\r\n\r\n- `getNotifications`：鸿蒙公开 API 不支持枚举系统通知/铃声/闹钟条目。`@kit.RingtoneKit` 仅提供 `getSupportedRingtoneTypes`/`getSupportedDataTypes`/`getSupportedMaxDuration`/`startRingtoneSetting`（查询可设置类型，不枚举条目）；`@kit.AudioKit` 的 `systemSoundManager.SystemSoundType` 仅含 `PHOTO_SHUTTER`/`VIDEO_RECORDING_BEGIN`/`VIDEO_RECORDING_END`。故降级为枚举应用 `rawfile` 内置铃声资源，保持「获取列表 + 试听」主流程可用。\r\n- `url` 字段语义差异：原 Android 返回 `content://media/...` content Uri，原 iOS 返回 `file:///...` 绝对路径；鸿蒙侧为 rawfile 相对路径（如 `\"notification/notification_01.wav\"`），原生侧通过 `resourceManager.getRawFd` 加载。\r\n- `soundID` 字段语义差异：原 Android 为系统铃声数据库 id，原 iOS 为 `SystemSoundID`（整数）；鸿蒙侧为文件名去扩展名（如 `\"notification_01\"`）。\r\n- `alarm` 类型：原库标注 *android only*，鸿蒙侧降级方案下同样支持（返回应用内置 alarm 类铃声）。\r\n\r\n### 未实现功能\r\n\r\n无。三个核心 API 均已实现，行为对齐原库（含空值回退默认通知音、已有播放先停止再播放等边界行为）。\r\n\r\n### 使用限制\r\n\r\n- 声音来源为应用 `rawfile` 内置铃声资源（`resources/rawfile/{notification,ringtone,alarm}/`），非系统铃声。\r\n- SoundPool 起始 API 10，短音效试听场景适用；不支持后台播放、音频焦点、跳过静音帧。\r\n- 需 HarmonyOS SDK API17+（SoundPool + resourceManager.getRawFileList 均可用）。\r\n\r\n## 快速验证（运行 Example）\r\n\r\n### 前置条件\r\n\r\n| 依赖 | 版本要求 |\r\n|------|----------|\r\n| Node.js | >= 18 |\r\n| DevEco Studio | 5.0+ / 6.0+ |\r\n| HarmonyOS SDK | API 17+ |\r\n\r\n### 运行步骤\r\n\r\n**1. 克隆仓库**\r\n\r\n```bash\r\ngit clone <仓库地址>\r\ncd <仓库目录>\r\n```\r\n\r\n**2. 安装依赖并构建**\r\n\r\n```bash\r\nnpm install --legacy-peer-deps\r\nnpm pack           # 生成 tgz 包（会自动触发 prepare 构建 JS 产物）\r\n```\r\n\r\n**3. 进入 example 目录，安装依赖**\r\n\r\n```bash\r\ncd example\r\nnpm install --legacy-peer-deps\r\n```\r\n\r\n**4. 生成 JS Bundle**\r\n\r\n```bash\r\nnpm run dev\r\n```\r\n\r\n产物：`harmony/entry/src/main/resources/rawfile/bundle.harmony.js`\r\n\r\n**5. 用 DevEco Studio 打开鸿蒙工程**\r\n\r\n- 打开 DevEco Studio\r\n- 选择 `example/harmony` 目录\r\n- 等待 Sync 完成\r\n\r\n**6. 编译并运行 HAP**\r\n\r\n在 DevEco Studio 中点击运行按钮，将 HAP 安装到设备/模拟器。\r\n\r\n> **注意**：Example 中已预置插件依赖和 Package 注册，无需手动配置 Link。\r\n\r\n## 约束与限制\r\n\r\n### 兼容性\r\n\r\n- RNOH: 0.72+\r\n- HarmonyOS SDK: API 17+\r\n- DevEco Studio: 5.0+\r\n\r\n## 遗留问题\r\n\r\n- `getNotifications` 返回应用内置铃声资源而非系统铃声（鸿蒙公开 API 不支持枚举系统铃声条目）。\r\n\r\n## 开源协议\r\n\r\n本项目基于 [MIT](https://github.com/saadqbal/react-native-notification-sounds/blob/master/LICENSE)，详见 [LICENSE](./LICENSE) 文件。\r\n","readmeFilename":"README.md"}