diff --git a/taoyao-client-harmony/README.md b/taoyao-client-harmony/README.md
index 421b2b1..82bd49f 100644
--- a/taoyao-client-harmony/README.md
+++ b/taoyao-client-harmony/README.md
@@ -1,7 +1,5 @@
# 鸿蒙终端
-提供嵌入式开发能力,选择开发板`Hi3518E`。
-
## C++终端
* [libmediasoupclient源码](https://github.com/versatica/libmediasoupclient)
@@ -10,119 +8,6 @@
## 学习资料
-https://hpm.harmonyos.com/#/cn/home
-https://repo.harmonyos.com/#/cn/home
-https://www.hihope.org/download/download.aspx
-https://device.harmonyos.com/cn/develop/ide/
-https://device.harmonyos.com/cn/documentation/
-https://www.openharmony.cn/docs/zh-cn/overview/
-https://www.openharmony.cn/docs/zh-cn/device-dev/
-https://docs.openharmony.cn/pages/v3.1/zh-cn/OpenHarmony-Overview_zh.md/
-https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/
-https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/
-
-## 环境
-
-```
-# Ubuntu
-# https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04.5/
-
-# `Ubuntu`选择版本`20.04.5`,建议选择相同版本,不然很多软件版本需要自己调整。
-
-# 环境搭建
-# https://device.harmonyos.com/cn/docs/documentation/guide/ide-install-windows-ubuntu-0000001194073744
-```
-
-## 源码
-
-```
-# 下载源码
-# https://gitee.com/openharmony/manifest/tree/OpenHarmony-3.2-Release/
-# https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md
-
-repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-3.2-Release -m chipsets/hispark_aries.xml -g ohos:mini --no-repo-verify
-repo sync -c
-repo forall -c 'git lfs pull'
-
-# Marketplace
-# https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries
-# https://repo.harmonyos.com/#/cn/solution/@opensource%2Fhoperun_hm_door_3518
-# https://gitee.com/openharmony-sig/knowledge_demo_smart_home/blob/master/dev/docs/smart_door_viewer_3518/README.md
-
-sudo apt install nodejs
-sudo apt install npm
-npm config set registry https://repo.huaweicloud.com/repository/npm
-npm install -g @ohos/hpm-cli
-```
-
-## 编译
-
-https://hpm.harmonyos.com/#/cn/home
-https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/
-
-```
-# 下载依赖
-hpm install
-
-# hpm编译
-hpm dist
-
-# hb编译
-pip3 install build/lite
-# hp增量编译
-hb build
-# hp完整编译
-hb build -f
-
-# build编译
-./build.sh \
- --ccache \
- --product-name Hi3518EV300 \
- --build-target build_kernel \
- --gn-args linux_kernel_version=\"linux-5.10\"
-```
-
-## 烧录
-
-https://www.hihope.org/download/download.aspx
-
-```
-# out/hispark_aries/ipcamera_hispark_aries
-# device/hisilicon/hispark_aries/sdk_liteos/uboot/out/boot
-
-u-boot-hi3518ev300.bin:fastboot
-OHOS_Image.bin:kernel
-rootfs_jffs2.img:rootfs
-userfs_jffs2.img:userfs
-```
-
-## 配置
-
-串口:`115200`
-
-```
-setenv bootcmd "sf probe 0;sf read 0x40000000 0x100000 0x600000;go 0x40000000"
-setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=7M rootsize=8M"
-save
-reset
-./bin/wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf
-```
-
-## 代码目录
-
-```
-applications 应用程序样例,包括camera等
-base 基础软件服务子系统集&硬件服务子系统集
-build 组件化编译、构建和配置脚本
-docs 说明文档
-domains 增强软件服务子系统集
-drivers 驱动子系统
-foundation 系统基础能力子系统集
-kernel 内核子系统
-prebuilts 编译器及工具链子系统
-test 测试子系统
-third_party 开源第三方组件
-utils 常用的工具集
-vendor 厂商提供的软件
-build.py 编译脚本文件
-```
+https://developer.harmonyos.com/cn/develop/
+https://developer.harmonyos.com/cn/docs/documentation/doc-guides/start-overview-0000000000029602
+https://developer.harmonyos.com/cn/docs/documentation/doc-references/reference-document-outline-0000001115016824
diff --git a/taoyao-client-harmony/hi3518e.xml b/taoyao-client-harmony/hi3518e.xml
deleted file mode 100644
index c64171b..0000000
--- a/taoyao-client-harmony/hi3518e.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/taoyao-client-harmony/os/.gitignore b/taoyao-client-harmony/os/.gitignore
deleted file mode 100644
index f48ed97..0000000
--- a/taoyao-client-harmony/os/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-.vscode/
-ohos_bundles
\ No newline at end of file
diff --git a/taoyao-client-harmony/os/README.md b/taoyao-client-harmony/os/README.md
deleted file mode 100644
index 4fcb103..0000000
--- a/taoyao-client-harmony/os/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# 桃夭鸿蒙系统
-
-https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries
diff --git a/taoyao-client-harmony/os/bundle.json b/taoyao-client-harmony/os/bundle.json
deleted file mode 100644
index e8c8671..0000000
--- a/taoyao-client-harmony/os/bundle.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "name": "taoyao",
- "version": "1.0.0",
- "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE",
- "hompage": "https://gitee.com/acgist/taoyao",
- "repository": "https://gitee.com/acgist/taoyao.git",
- "description": "桃夭鸿蒙终端",
- "publishAs": "distribution",
- "ohos": {
- "os": "3.0.0",
- "board": "hi3518",
- "kernel": "liteos_a"
- },
- "base": {
- "name": "@ohos/hispark_aries",
- "version": "3.0.3"
- },
- "author": {
- "url": "https://www.acgist.com",
- "name": "acgist",
- "email": "rei@acgist.com"
- },
- "dirs": {},
- "envs": {},
- "scripts": {},
- "excludes": [],
- "dependencies": {}
-}
diff --git a/taoyao-client-harmony/os/bundle.release.json b/taoyao-client-harmony/os/bundle.release.json
deleted file mode 100644
index e059025..0000000
--- a/taoyao-client-harmony/os/bundle.release.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "name": "taoyao",
- "version": "1.0.0",
- "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE",
- "hompage": "https://gitee.com/acgist/taoyao",
- "repository": "https://gitee.com/acgist/taoyao.git",
- "description": "桃夭鸿蒙终端",
- "publishAs": "distribution",
- "ohos": {
- "os": "3.0.0",
- "board": "hi3518",
- "kernel": "liteos_a"
- },
- "base": {
- "name": "@ohos/hispark_aries",
- "version": "3.0.3"
- },
- "author": {
- "url": "https://www.acgist.com",
- "name": "acgist",
- "email": "rei@acgist.com"
- },
- "dirs": {},
- "envs": {
- "debug": false
- },
- "scripts": {},
- "excludes": ["applications_sample_camera"],
- "dependencies": {}
-}
diff --git a/taoyao-client-harmony/taoyao/.gitignore b/taoyao-client-harmony/taoyao/.gitignore
index 99e1bca..a7c9c0c 100644
--- a/taoyao-client-harmony/taoyao/.gitignore
+++ b/taoyao-client-harmony/taoyao/.gitignore
@@ -1,10 +1,12 @@
-CMakeCache.txt
+local.properties
-**/*.so
-**/*.exe
-**/*.lib
+.clangd
+.clang-tidy
+.clang-format
-.vscode/**
+**/.cxx
+**/.idea
+**/.gradle
-build/**
-openharmony/**
\ No newline at end of file
+**/build
+**/node_modules
diff --git a/taoyao-client-harmony/taoyao/.gitmodules b/taoyao-client-harmony/taoyao/.gitmodules
deleted file mode 100644
index 92176b2..0000000
--- a/taoyao-client-harmony/taoyao/.gitmodules
+++ /dev/null
@@ -1,4 +0,0 @@
-[submodule "googletest"]
- path = test/lib/googletest
- url = https://github.com/google/googletest.git
- branch = master
diff --git a/taoyao-client-harmony/taoyao/CMakeLists.txt b/taoyao-client-harmony/taoyao/CMakeLists.txt
deleted file mode 100644
index fcc9dfb..0000000
--- a/taoyao-client-harmony/taoyao/CMakeLists.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-cmake_minimum_required(VERSION 3.2)
-
-#define CMAKE_TEMPLATE_VERSION_MAJOR @CMakeTemplate_VERSION_MAJOR@
-#define CMAKE_TEMPLATE_VERSION_MINOR @CMakeTemplate_VERSION_MINOR@
-#define CMAKE_TEMPLATE_VERSION_PATCH @CMakeTemplate_VERSION_PATCH@
-project(taoyao-client-camera VERSION 1.0.0 LANGUAGES C CXX)
-
-# Debug | Release
-# DCMAKE_BUILD_TYPE=Debug
-set(CMAKE_BUILD_TYPE Debug)
-
-# set(CMAKE_C_COMPILER gcc)
-# set(CMAKE_CXX_COMPILER g++)
-
-# 全局宏定义
-# add_definitions(-DDEBUG)
-
-# 全局编译选项
-# add_compile_options()
-
-# C编译选项
-set(CMAKE_C_STANDARD 11)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -O3")
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
-
-# C++编译选项
-set(CMAKE_CXX_STANDARD 11)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
-
-# 输出目录
-set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
-
-# 包含源代码
-# add_subdirectory(src)
-# add_subdirectory(test)
-
-file(
- GLOB SOURCE_FILE
- "include/*.h"
- "include/*.hpp"
- "src/main.cpp"
- "src/media/*.c"
- "src/signal/*.c"
- "src/media/*.cpp"
- "src/signal/*.cpp"
-)
-
-# -lpthread
-
-add_executable(${PROJECT_NAME} ${SOURCE_FILE})
-
-# message("源码地址:" ${SOURCE_FILE})
-
-# 配置
-# cmake -B build
-# Windows:-G "Unix Makefiles"
-# 安装位置:-DCMAKE_INSTALL_PREFIX=`pwd`/output | --install --prefix
-# 打包位置:-DCPACK_OUTPUT_FILE_PREFIX=`pwd`/output
-
-# 编译
-# cmake --build build
-
-# 安装
-# cd build && make install && cd -
-
-# install(
-# TARGETS taoyao
-# RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
-# LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
-# ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
-# )
-
-# 打包
-# cd build && cpack && cd -
-
-# include(CPack)
-# set(CPACK_GENERATOR "ZIP")
-# set(CPACK_SET_DESTDIR ON)
-# set(CPACK_INSTALL_PREFIX "")
-# set(CPACK_PACKAGE_NAME "taoyao")
-# set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
diff --git a/taoyao-client-harmony/taoyao/README.md b/taoyao-client-harmony/taoyao/README.md
deleted file mode 100644
index deb89d5..0000000
--- a/taoyao-client-harmony/taoyao/README.md
+++ /dev/null
@@ -1 +0,0 @@
-# 桃夭鸿蒙终端
diff --git a/taoyao-client-harmony/taoyao/build.gradle b/taoyao-client-harmony/taoyao/build.gradle
new file mode 100644
index 0000000..430c913
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/build.gradle
@@ -0,0 +1,41 @@
+apply plugin: 'com.huawei.ohos.app'
+
+ohos {
+ signingConfigs {
+ debug {
+ storeFile file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p12')
+ storePassword '0000001BF429DD369062C4630873F17257C6AE37F3B5CCC5BE92C1DE60CEBE94E3592C9A6423F38CA5C88E'
+ keyAlias = 'debugKey'
+ keyPassword '0000001B814502DD14E5F3430066B6F451C85FFB36AB7ADB13AC53823EB7A3F644FED4758F5053827B968D'
+ signAlg = 'SHA256withECDSA'
+ profile file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p7b')
+ certpath file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.cer')
+ }
+ }
+ compileSdkVersion 7
+}
+
+buildscript {
+ repositories {
+ maven {
+ url 'https://repo.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ }
+ dependencies {
+ classpath 'com.huawei.ohos:hap:3.1.2.0'
+ classpath 'com.huawei.ohos:decctest:1.2.7.19'
+ }
+}
+allprojects {
+ repositories {
+ maven {
+ url 'https://repo.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ }
+}
diff --git a/taoyao-client-harmony/taoyao/client/build.gradle b/taoyao-client-harmony/taoyao/client/build.gradle
new file mode 100644
index 0000000..34a6fdd
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/build.gradle
@@ -0,0 +1,34 @@
+apply plugin: 'com.huawei.ohos.hap'
+apply plugin: 'com.huawei.ohos.decctest'
+
+ohos {
+ compileSdkVersion 7
+ defaultConfig {
+ compatibleSdkVersion 7
+ }
+ buildTypes {
+ release {
+ proguardOpt {
+ proguardEnabled false
+ rulesFiles 'proguard-rules.pro'
+ }
+ }
+ }
+ externalNativeBuild {
+ path "src/main/cpp/CMakeLists.txt"
+ arguments ""
+ abiFilters "arm64-v8a"
+ cppFlags ""
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
+ implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
+ implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'
+ testImplementation 'junit:junit:4.13.1'
+ ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.400'
+}
+decc {
+ supportType = ['html', 'xml']
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/config.json b/taoyao-client-harmony/taoyao/client/src/main/config.json
new file mode 100644
index 0000000..274e2f1
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/config.json
@@ -0,0 +1,60 @@
+{
+ "app": {
+ "bundleName": "com.acgist.taoyao",
+ "vendor": "acgist",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {
+ "default": {
+ "keepAlive": true
+ }
+ },
+ "module": {
+ "package": "com.acgist.taoyao",
+ "name": "com.acgist.taoyao.TaoyaoApplication",
+ "mainAbility": "com.acgist.taoyao.MainAbility",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "client",
+ "moduleType": "entry",
+ "installationFree": false
+ },
+ "abilities": [
+ {
+ "name": "com.acgist.taoyao.MainAbility",
+ "icon": "$media:icon",
+ "label": "$string:main_label",
+ "description": "$string:main_description",
+ "launchType": "standard",
+ "orientation": "unspecified",
+ "visible": true,
+ "skills": [
+ {
+ "actions": [
+ "action.system.home",
+ "main",
+ "setting"
+ ],
+ "entities": [
+ "entity.system.home"
+ ]
+ }
+ ],
+ "type": "page"
+ },
+ {
+ "name": "com.acgist.taoyao.MediaAbility",
+ "description": "$string:media_description",
+ "type": "service",
+ "backgroundModes": [],
+ "icon": "$media:icon"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt b/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt
new file mode 100644
index 0000000..d026331
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,41 @@
+cmake_minimum_required(VERSION 3.2)
+
+project(taoyao VERSION 1.0.0 LANGUAGES C CXX)
+
+# Debug | Release
+# DCMAKE_BUILD_TYPE=Debug
+# set(CMAKE_BUILD_TYPE Debug)
+
+# C编译选项
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c17 -O3")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c17 -O0 -g")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c17 -O3")
+
+# C++编译选项
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -O0 -g")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17 -O3")
+
+# 输出目录
+# set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
+
+file(
+ GLOB SOURCE_FILE
+ "main.hpp"
+ "include/*.hpp"
+ "mediasoup/*.hpp"
+ "main.cpp"
+ "media/*.cpp"
+)
+
+add_library(taoyao SHARED ${SOURCE_FILE})
+target_link_libraries(taoyao libhilog_ndk.z.so)
+
+# 配置
+# cmake -B build
+# Windows:cmake -B build -G "Unix Makefiles"
+# 编译
+# cmake --build build
+# 标准线程:-lpthread
diff --git a/taoyao-client-harmony/taoyao/include/MediaClient.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp
similarity index 59%
rename from taoyao-client-harmony/taoyao/include/MediaClient.hpp
rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp
index f7b3e96..f7883f8 100644
--- a/taoyao-client-harmony/taoyao/include/MediaClient.hpp
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp
@@ -1,8 +1,5 @@
#pragma once
-/**
- * 媒体终端
- */
namespace acgist {
}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/Publisher.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp
similarity index 98%
rename from taoyao-client-harmony/taoyao/include/Publisher.hpp
rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp
index 7eb2543..7cfff5c 100644
--- a/taoyao-client-harmony/taoyao/include/Publisher.hpp
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp
@@ -7,6 +7,4 @@
namespace acgist {
-
-
}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp
similarity index 61%
rename from taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp
index 07b7629..4a088fe 100644
--- a/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp
@@ -1,8 +1,5 @@
#pragma once
-/**
- * 媒体录制
- */
namespace acgist {
}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp
similarity index 59%
rename from taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp
index c41be2f..4a088fe 100644
--- a/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp
@@ -1,8 +1,5 @@
#pragma once
-/**
- * 视频推送器
- */
namespace acgist {
}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp
new file mode 100644
index 0000000..9a35099
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp
@@ -0,0 +1,16 @@
+#include
+#include
+#include
+
+#include "main.hpp"
+
+extern "C" JNIEXPORT jstring JNICALL
+Java_com_acgist_taoyao_slice_MainAbilitySlice_stringFromJNI(JNIEnv *env, jobject obj) {
+ std::string hello = "Hello from JNI C++ codes";
+ int len = hello.size();
+ jchar res[len];
+ for (int i = 0; i < len; i++) {
+ res[i] = (jchar)hello[i];
+ }
+ return env->NewString(res, len);
+}
diff --git a/taoyao-client-harmony/taoyao/include/main.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.hpp
similarity index 100%
rename from taoyao-client-harmony/taoyao/include/main.hpp
rename to taoyao-client-harmony/taoyao/client/src/main/cpp/main.hpp
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp
new file mode 100644
index 0000000..39fd603
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp
@@ -0,0 +1,5 @@
+#include "../include/AudioPublisher.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaPublisher.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp
new file mode 100644
index 0000000..75e8d63
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp
@@ -0,0 +1,5 @@
+#include "../include/MediaRecorder.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp
new file mode 100644
index 0000000..fc40e38
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp
@@ -0,0 +1,5 @@
+#include "../include/VideoPublisher.hpp"
+
+namespace acgist {
+
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java
new file mode 100644
index 0000000..3c077ff
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java
@@ -0,0 +1,16 @@
+package com.acgist.taoyao;
+
+import com.acgist.taoyao.slice.MainAbilitySlice;
+import com.acgist.taoyao.slice.SettingAbilitySlice;
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.content.Intent;
+
+public class MainAbility extends Ability {
+ @Override
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setMainRoute(MainAbilitySlice.class.getName());
+ super.addActionRoute("main", MainAbilitySlice.class.getName());
+ super.addActionRoute("setting", SettingAbilitySlice.class.getName());
+ }
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java
new file mode 100644
index 0000000..10b493f
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java
@@ -0,0 +1,43 @@
+package com.acgist.taoyao;
+
+import ohos.aafwk.ability.Ability;
+import ohos.aafwk.content.Intent;
+import ohos.rpc.IRemoteObject;
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
+public class MediaAbility extends Ability {
+
+ private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Media");
+
+ @Override
+ public void onStart(Intent intent) {
+ HiLog.error(LABEL_LOG, "MediaAbility::onStart");
+ super.onStart(intent);
+ }
+
+ @Override
+ public void onBackground() {
+ super.onBackground();
+ HiLog.info(LABEL_LOG, "MediaAbility::onBackground");
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ HiLog.info(LABEL_LOG, "MediaAbility::onStop");
+ }
+
+ @Override
+ public void onCommand(Intent intent, boolean restart, int startId) {
+ }
+
+ @Override
+ public IRemoteObject onConnect(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public void onDisconnect(Intent intent) {
+ }
+}
\ No newline at end of file
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java
new file mode 100644
index 0000000..f345238
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java
@@ -0,0 +1,16 @@
+package com.acgist.taoyao;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+public class TaoyaoApplication extends AbilityPackage {
+
+ static {
+ System.loadLibrary("taoyao");
+ }
+
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java
new file mode 100644
index 0000000..469f4cb
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java
@@ -0,0 +1,10 @@
+package com.acgist.taoyao.config;
+
+/**
+ * 配置
+ *
+ * @author acgist
+ */
+public class Config {
+
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java
new file mode 100644
index 0000000..66455bd
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java
@@ -0,0 +1,4 @@
+package com.acgist.taoyao.media;
+
+public class AudioPublisher {
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java
new file mode 100644
index 0000000..c3ea446
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java
@@ -0,0 +1,7 @@
+package com.acgist.taoyao.media;
+
+/**
+ * 终端
+ */
+public class MediaClient {
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java
new file mode 100644
index 0000000..b9b6d7b
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java
@@ -0,0 +1,4 @@
+package com.acgist.taoyao.media;
+
+public class MediaRecorder {
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java
new file mode 100644
index 0000000..47a6735
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java
@@ -0,0 +1,4 @@
+package com.acgist.taoyao.media;
+
+public class VideoPublisher {
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java
new file mode 100644
index 0000000..53fa79e
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java
@@ -0,0 +1,64 @@
+package com.acgist.taoyao.model;
+
+import java.io.Serializable;
+
+/**
+ * 消息头部
+ *
+ * @author acgist
+ */
+public class Header implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 消息版本
+ */
+ private String v;
+ /**
+ * 消息标识
+ */
+ private Long id;
+ /**
+ * 信令标识
+ */
+ private String signal;
+
+ @Override
+ public Header clone() {
+ return new Header(this.v, this.id, this.signal);
+ }
+
+ public Header() {
+ }
+
+ public Header(String v, Long id, String signal) {
+ this.v = v;
+ this.id = id;
+ this.signal = signal;
+ }
+
+ public String getV() {
+ return v;
+ }
+
+ public void setV(String v) {
+ this.v = v;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getSignal() {
+ return signal;
+ }
+
+ public void setSignal(String signal) {
+ this.signal = signal;
+ }
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java
new file mode 100644
index 0000000..3207229
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java
@@ -0,0 +1,224 @@
+package com.acgist.taoyao.model;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.acgist.taoyao.utils.JSONUtils;
+import com.fasterxml.jackson.annotation.JsonIncludeProperties;
+
+
+/**
+ * 消息
+ * 接口、信令、媒体信令通用消息模型
+ *
+ * @author acgist
+ */
+@JsonIncludeProperties(value = { "code", "message", "header", "body" })
+public class Message implements Cloneable, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 状态编码
+ */
+ private String code;
+ /**
+ * 状态描述
+ */
+ private String message;
+ /**
+ * 消息头部
+ */
+ private Header header;
+ /**
+ * 消息主体
+ */
+ private Object body;
+
+ /**
+ * @param code 状态编码
+ */
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ /**
+ * @param code 状态编码
+ */
+ public void setCode(MessageCode code) {
+ this.setCode(code, null);
+ }
+
+ /**
+ * @param code 状态编码
+ * @param message 状态描述
+ *
+ * @return this
+ */
+ public Message setCode(MessageCode code, String message) {
+ this.code = code.getCode();
+ this.message = message == null || message.isEmpty() ? code.getMessage() : message;
+ return this;
+ }
+
+ /**
+ * @return 成功消息
+ */
+ public static final Message success() {
+ return success(null);
+ }
+
+ /**
+ * @param body 消息主体
+ *
+ * @return 成功消息
+ */
+ public static final Message success(Object body) {
+ final Message message = new Message();
+ message.setCode(MessageCode.CODE_0000, null);
+ message.body = body;
+ return message;
+ }
+
+ /**
+ * @return 失败消息
+ */
+ public static final Message fail() {
+ return fail(null, null, null);
+ }
+
+ /**
+ * @param code 状态编码
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(MessageCode code) {
+ return fail(code, null, null);
+ }
+
+ /**
+ * @param code 状态编码
+ * @param body 消息主体
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(MessageCode code, Object body) {
+ return fail(code, null, body);
+ }
+
+ /**
+ * @param message 状态描述
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(String message) {
+ return fail(null, message, null);
+ }
+
+ /**
+ * @param message 状态描述
+ * @param body 消息主体
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(String message, Object body) {
+ return fail(null, message, body);
+ }
+
+ /**
+ * @param code 状态编码
+ * @param message 状态描述
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(MessageCode code, String message) {
+ return fail(code, message, null);
+ }
+
+ /**
+ * @param code 状态编码
+ * @param message 状态描述
+ * @param body 消息主体
+ *
+ * @return 失败消息
+ */
+ public static final Message fail(MessageCode code, String message, Object body) {
+ final Message failMessage = new Message();
+ failMessage.setCode(code == null ? MessageCode.CODE_9999 : code, message);
+ failMessage.body = body;
+ return failMessage;
+ }
+
+ @Override
+ public Message clone() {
+ return new Message(this.code, this.message, this.header.clone(), this.body);
+ }
+
+ /**
+ * 克隆消息排除消息主体
+ *
+ * @return 克隆消息
+ */
+ public Message cloneWithoutBody() {
+ return new Message(this.code, this.message, this.header.clone(), null);
+ }
+
+ /**
+ * @return Map消息主体
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public Map body() {
+ if(this.body instanceof Map) {
+ return (Map) this.body;
+ } else if(this.body == null) {
+ return new HashMap<>();
+ } else {
+ throw MessageCodeException.of("信令主体类型错误:" + this.body);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return JSONUtils.toJSON(this);
+ }
+
+ public Message() {
+ }
+
+ public Message(String code, String message, Header header, Object body) {
+ this.code = code;
+ this.message = message;
+ this.header = header;
+ this.body = body;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public Header getHeader() {
+ return header;
+ }
+
+ public void setHeader(Header header) {
+ this.header = header;
+ }
+
+ public Object getBody() {
+ return body;
+ }
+
+ public void setBody(Object body) {
+ this.body = body;
+ }
+
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java
new file mode 100644
index 0000000..ec63d2e
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java
@@ -0,0 +1,99 @@
+package com.acgist.taoyao.model;
+
+/**
+ * 状态编码
+ *
+ * 1xxx = 前置错误
+ * 2xxx = 内部错误
+ * 3xxx = 请求错误
+ * 9999 = 未知错误
+ *
+ * @author acgist
+ */
+public enum MessageCode {
+
+ // 成功
+ CODE_0000("0000", 200, "成功"),
+ // 1xxx
+ CODE_1000("1000", 404, "未知接口"),
+ CODE_1001("1001", 400, "上次请求没有完成"),
+ CODE_1002("1002", 400, "数据格式错误"),
+ CODE_1003("1003", 400, "验签失败"),
+ // 2xxx
+ CODE_2000("2000", 500, "服务错误"),
+ CODE_2001("2001", 504, "服务超时"),
+ // 3xxx
+ CODE_3400("3400", 400, "请求错误"),
+ CODE_3401("3401", 401, "没有授权"),
+ CODE_3403("3403", 403, "请求拒绝"),
+ CODE_3404("3404", 404, "资源失效"),
+ CODE_3405("3405", 405, "请求方法错误"),
+ CODE_3406("3406", 406, "请求不可接受"),
+ CODE_3415("3415", 415, "请求资源类型错误"),
+ CODE_3500("3500", 500, "系统异常"),
+ CODE_3502("3502", 502, "服务无效"),
+ CODE_3503("3503", 503, "服务正在维护"),
+ CODE_3504("3504", 504, "服务超时"),
+ // 9999
+ CODE_9999("9999", 500, "未知错误");
+
+ /**
+ * HTTP状态编码前缀
+ */
+ private static final String HTTP_STATUS = "3";
+
+ /**
+ * 状态编码
+ */
+ private final String code;
+ /**
+ * 状态数值
+ */
+ private final Integer status;
+ /**
+ * 状态描述
+ */
+ private final String message;
+
+ private MessageCode(String code, Integer status, String message) {
+ this.code = code;
+ this.status = status;
+ this.message = message;
+ }
+
+ /**
+ * @param code 状态编码
+ *
+ * @return 状态编码
+ */
+ public static final MessageCode of(String code) {
+ final MessageCode[] values = MessageCode.values();
+ for (MessageCode value : values) {
+ if (value.code.equals(code)) {
+ return value;
+ }
+ }
+ return CODE_9999;
+ }
+
+ /**
+ * @param status HTTP Status
+ *
+ * @return 状态编码
+ */
+ public static final MessageCode of(Integer status) {
+ return of(HTTP_STATUS + status);
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java
new file mode 100644
index 0000000..be73ba0
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java
@@ -0,0 +1,75 @@
+package com.acgist.taoyao.model;
+
+import java.util.Objects;
+
+/**
+ * 状态编码异常
+ *
+ * @author acgist
+ */
+public class MessageCodeException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 状态编码
+ */
+ private final MessageCode code;
+
+ /**
+ * @param message 异常消息
+ *
+ * @return 状态编码异常
+ */
+ public static final MessageCodeException of(String message) {
+ return of(null, null, message);
+ }
+
+ /**
+ * @param t 异常
+ * @param message 异常消息
+ *
+ * @return 状态编码异常
+ */
+ public static final MessageCodeException of(Throwable t, String message) {
+ return of(t, null, message);
+ }
+
+ /**
+ * @param code 状态编码
+ * @param message 异常消息
+ *
+ * @return 状态编码异常
+ */
+ public static final MessageCodeException of(MessageCode code, String message) {
+ return of(null, code, message);
+ }
+
+ /**
+ * @param t 异常
+ * @param code 状态编码
+ * @param message 异常消息
+ *
+ * @return 状态编码异常
+ */
+ public static final MessageCodeException of(Throwable t, MessageCode code, String message) {
+ if(code == null) {
+ code = MessageCode.CODE_9999;
+ }
+ if(message == null || message.isEmpty()) {
+ message = Objects.isNull(t) ? code.getMessage() : t.getMessage();
+ }
+ return new MessageCodeException(t, code, message);
+ }
+
+ /**
+ * @param t 异常
+ * @param code 状态编码
+ * @param message 异常消息
+ */
+ public MessageCodeException(Throwable t, MessageCode code, String message) {
+ super(message, t);
+ this.code = code;
+ }
+
+}
diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java
new file mode 100644
index 0000000..212e32b
--- /dev/null
+++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java
@@ -0,0 +1,319 @@
+package com.acgist.taoyao.signal;
+
+import com.acgist.taoyao.model.Header;
+import com.acgist.taoyao.model.Message;
+import com.acgist.taoyao.utils.CloseableUtils;
+import com.acgist.taoyao.utils.JSONUtils;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.time.LocalDateTime;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 桃夭信令
+ *
+ * @author acgist
+ */
+public class Taoyao {
+
+// private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0, "[信令]");
+
+ private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(8);
+
+ /**
+ * 端口
+ */
+ private int port;
+ /**
+ * 地址
+ */
+ private String host;
+ /**
+ * Socket
+ */
+ private Socket socket;
+ private InputStream input;
+ private OutputStream output;
+ private String username;
+ private String password;
+ private boolean close;
+ /**
+ * 是否连接
+ */
+ private boolean connect;
+ private final Cipher encrypt;
+ private final Cipher decrypt;
+
+ public Taoyao(int port, String host, String algo, String secret) {
+ this.port = port;
+ this.host = host;
+ this.close = false;
+ this.connect = false;
+ if(algo == null || algo.isEmpty() || algo.equals("PLAINTEXT")) {
+ // 明文
+ this.encrypt = null;
+ this.decrypt = null;
+ } else {
+ this.encrypt = this.buildCipher(Cipher.ENCRYPT_MODE, algo, secret);
+ this.decrypt = this.buildCipher(Cipher.DECRYPT_MODE, algo, secret);
+ }
+ EXECUTOR.submit(this::read);
+ }
+
+ private Cipher buildCipher(int mode, String name, String secret) {
+ try {
+ final String algo = name.equals("DES") ? "DES/ECB/PKCS5Padding" : "AES/ECB/PKCS5Padding";
+ final Cipher cipher = Cipher.getInstance(algo);
+ cipher.init(mode, new SecretKeySpec(Base64.getMimeDecoder().decode(secret), name));
+ return cipher;
+ } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
+ // TODO:日志
+ }
+ return null;
+ }
+
+ /**
+ * 连接信令
+ */
+ public void connect() {
+ this.close();
+// HiLog.debug(this.label, "连接信令:%s:%d", this.host, this.port);
+ this.socket = new Socket();
+ try {
+// socket.setSoTimeout(5000);
+ this.socket.connect(new InetSocketAddress(this.host, this.port), 5000);
+ if(this.socket.isConnected()) {
+ this.input = this.socket.getInputStream();
+ this.output = this.socket.getOutputStream();
+ this.register();
+ synchronized (this) {
+ this.notifyAll();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+// HiLog.error(this.label, "连接信令异常:%s:%d", this.host, this.port);
+ }
+ }
+
+ private void read() {
+ int length = 0;
+ short messageLength = 0;
+ final byte[] bytes = new byte[1024];
+ final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
+ while(!this.close) {
+ try {
+ while(this.input == null) {
+ this.connect();
+ synchronized (this) {
+ this.wait(5000);
+ }
+ }
+ while ((length = this.input.read(bytes)) >= 0) {
+ buffer.put(bytes, 0, length);
+ while (buffer.position() > 0) {
+ if (messageLength <= 0) {
+ if (buffer.position() < Short.BYTES) {
+ // 不够消息长度
+ break;
+ } else {
+ buffer.flip();
+ messageLength = buffer.getShort();
+ buffer.compact();
+ if (messageLength > 16 * 1024) {
+ throw new RuntimeException("超过最大数据大小:" + messageLength);
+ }
+ }
+ } else {
+ if (buffer.position() < messageLength) {
+ // 不够消息长度
+ break;
+ } else {
+ final byte[] message = new byte[messageLength];
+ messageLength = 0;
+ buffer.flip();
+ buffer.get(message);
+ buffer.compact();
+ final String content = new String(this.decrypt.doFinal(message));
+ EXECUTOR.submit(() -> {
+ Taoyao.this.on(content);
+ });
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.connect();
+ // TODO:日志
+// log.error("读取异常", e);
+ }
+ }
+ }
+
+ /**
+ * @param message 消息
+ *
+ * @return 加密消息
+ */
+ private byte[] encrypt(Message message) {
+ final byte[] bytes = message.toString().getBytes();
+ if(this.encrypt != null) {
+ try {
+ // 加密
+ final byte[] encryptBytes = this.encrypt.doFinal(bytes);
+ // 发送
+ final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length);
+ buffer.putShort((short) encryptBytes.length);
+ buffer.put(encryptBytes);
+ buffer.flip();
+ final byte[] sendBytes = new byte[buffer.capacity()];
+ buffer.get(sendBytes);
+ return sendBytes;
+ } catch (IllegalBlockSizeException | BadPaddingException e) {
+ e.printStackTrace();
+// log.error("加密异常:{}", message);
+ }
+ }
+ return bytes;
+ }
+
+ public void push(Message message) {
+ if(this.output == null) {
+ return;
+ }
+ try {
+ this.output.write(this.encrypt(message));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Message request(Message request) {
+ return null;
+ }
+
+ private void register() {
+ final Header header = new Header();
+ this.push(this.buildMessage(
+ "client::register",
+ "clientId", "harmony",
+ "name", "harmony",
+ "clientType", "camera",
+ "username", "taoyao",
+ "password","taoyao"
+ ));
+ }
+
+ private void close() {
+ this.connect = false;
+ CloseableUtils.close(this.input);
+ CloseableUtils.close(this.output);
+ CloseableUtils.close(this.socket);
+ this.input = null;
+ this.output = null;
+ this.socket = null;
+ }
+
+ private void shutdown() {
+ this.close();
+ this.close = true;
+ EXECUTOR.shutdownNow();
+ }
+
+ /**
+ * 当前索引
+ */
+ private int index;
+ /**
+ * 当前终端索引
+ */
+ private int clientIndex = 99999;
+
+ private static final int MAX_INDEX = 999;
+
+ public long buildId() {
+ int index;
+ synchronized (this) {
+ if (++this.index > MAX_INDEX) {
+ this.index = 0;
+ }
+ index = this.index;
+ }
+ final LocalDateTime time = LocalDateTime.now();
+ return
+ 100000000000000L * time.getDayOfMonth() +
+ 1000000000000L * time.getHour() +
+ 10000000000L * time.getMinute() +
+ 100000000L * time.getSecond() +
+ 1000000L * this.clientIndex +
+ index;
+ }
+
+ private String version;
+
+ public Message buildMessage(String signal, Object ... args) {
+ final Map