[+] 结构

This commit is contained in:
acgist
2023-11-28 17:20:39 +08:00
parent dd0d80df5c
commit e58d82af99
28 changed files with 458 additions and 140 deletions

View File

@@ -1,10 +1,10 @@
{
"app": {
"bundleName": "com.acgist.taoyao",
"icon" : "$media:app_icon",
"label" : "$string:app_name",
"vendor": "acgist",
"bundleName" : "com.acgist.taoyao",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}

View File

@@ -1,8 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "taoyao"
"name" : "app_name",
"value": "桃夭"
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -13,13 +13,13 @@
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.cer",
"storePassword": "0000001B6B72744A79D44F625FF6D295CE824032D543A50BF93BD6985B89C7B657379C8735401C2A9700CC",
"signAlg" : "SHA256withECDSA",
"keyAlias": "debugKey",
"keyPassword": "0000001B6120DA129145E921FE4068BC61E7D7B5F4BF9386D51C895374C65BF9FE5890AFCD0F992B21E509",
"profile": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p12"
"profile" : "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p7b",
"certpath" : "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.cer",
"storeFile": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p12",
"keyPassword" : "0000001B6120DA129145E921FE4068BC61E7D7B5F4BF9386D51C895374C65BF9FE5890AFCD0F992B21E509",
"storePassword": "0000001B6B72744A79D44F625FF6D295CE824032D543A50BF93BD6985B89C7B657379C8735401C2A9700CC",
}
}
],

View File

@@ -1,11 +1,10 @@
{
"apiType": 'stageMode',
"apiType": "stageMode",
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
// "cFlags": "-std=c17",
"cppFlags": "-std=c++17",
"cppFlags" : "-std=c++17",
"arguments" : "",
"abiFilters": [ "arm64-v8a" ]
}
},

View File

@@ -1,10 +1,10 @@
{
"name": "media",
"main": "",
"name" : "media",
"main" : "",
"author": "acgist",
"description": "桃夭媒体终端",
"license": "Apache-2.0",
"version": "1.0.0",
"description" : "桃夭媒体终端",
"dependencies": {},
"devDependencies": {
"@types/libtaoyao.so": "file:./src/main/cpp/types/libtaoyao"

View File

@@ -23,7 +23,16 @@ set(LIBWEBRTC_BINARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/webrtc/lib/arm64-v8
add_subdirectory("./deps/libmediasoupclient")
add_library(${PROJECT_NAME} SHARED hello.cpp)
add_library(
${PROJECT_NAME} SHARED
bind.cpp
media/Room.cpp
media/Client.cpp
media/LocalClient.cpp
media/RemoteClient.cpp
media/MediaManager.cpp
media/SessionClient.cpp
)
target_include_directories(
${PROJECT_NAME} PUBLIC

View File

@@ -0,0 +1,86 @@
/**
* 方法绑定
*/
#include <map>
#include <string>
#include "hilog/log.h"
#include "napi/native_api.h"
#include "./include/Room.hpp"
#include "./include/MediaManager.hpp"
#include "./include/SessionClient.hpp"
namespace acgist {
acgist::MediaManager* mediaManager;
std::map<std::string, acgist::Room*> roomMap;
std::map<std::string, acgist::SessionClient*> sessionMap;
static void init() {
// OH_LOG_INFO(LOG_APP, "加载bind");
}
static napi_value sessionCall(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionExchange(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsume(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomClientList(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomEnter(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomExpel(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomInvite(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomLeave(napi_env env, napi_callback_info info) { return 0; }
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc[] = {
{ "sessionCall", nullptr, acgist::sessionCall, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionPause", nullptr, acgist::sessionPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionResume", nullptr, acgist::sessionResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionExchange", nullptr, acgist::sessionExchange, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionClose", nullptr, acgist::sessionClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsume", nullptr, acgist::mediaConsume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerClose", nullptr, acgist::mediaConsumerClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerPause", nullptr, acgist::mediaConsumerPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerResume", nullptr, acgist::mediaConsumerResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerClose", nullptr, acgist::mediaProducerClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerPause", nullptr, acgist::mediaProducerPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerResume", nullptr, acgist::mediaProducerResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomClientList", nullptr, acgist::roomClientList, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomClose", nullptr, acgist::roomClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomEnter", nullptr, acgist::roomEnter, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomExpel", nullptr, acgist::roomExpel, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomInvite", nullptr, acgist::roomInvite, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomLeave", nullptr, acgist::roomLeave, nullptr, nullptr, nullptr, napi_default, nullptr },
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);
return exports;
}
EXTERN_C_END
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "taoyao",
.nm_priv = ((void*) 0),
.reserved = { 0 },
};
extern "C" __attribute__((constructor)) void RegisterEntryModule(void) {
napi_module_register(&demoModule);
acgist::init();
}

View File

@@ -1,54 +0,0 @@
#include "napi/native_api.h"
static napi_value Add(napi_env env, napi_callback_info info)
{
size_t requireArgc = 2;
size_t argc = 2;
napi_value args[2] = {nullptr};
napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
napi_valuetype valuetype0;
napi_typeof(env, args[0], &valuetype0);
napi_valuetype valuetype1;
napi_typeof(env, args[1], &valuetype1);
double value0;
napi_get_value_double(env, args[0], &value0);
double value1;
napi_get_value_double(env, args[1], &value1);
napi_value sum;
napi_create_double(env, value0 + value1, &sum);
return sum;
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "taoyao",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
napi_module_register(&demoModule);
}

View File

@@ -16,4 +16,4 @@ public:
}
#endif taoyao_Client_HPP
#endif // taoyao_Client_HPP

View File

@@ -7,4 +7,4 @@
#ifndef taoyao_LocalClient_HPP
#define taoyao_LocalClient_HPP
#endif taoyao_LocalClient_HPP
#endif // taoyao_LocalClient_HPP

View File

@@ -26,4 +26,4 @@ public:
}
#endif taoyao_MediaManager_HPP
#endif // taoyao_MediaManager_HPP

View File

@@ -7,4 +7,4 @@
#ifndef taoyao_RemoteClient_HPP
#define taoyao_RemoteClient_HPP
#endif taoyao_RemoteClient_HPP
#endif // taoyao_RemoteClient_HPP

View File

@@ -4,7 +4,15 @@
* @author acgist
*/
#ifndef taoyao_Room.cpp_HPP
#define taoyao_Room.cpp_HPP
#ifndef taoyao_Room_HPP
#define taoyao_Room_HPP
#endif taoyao_Room.cpp_HPP
namespace acgist {
class Room {
};
}
#endif // taoyao_Room_HPP

View File

@@ -7,4 +7,4 @@
#ifndef taoyao_RoomClient_HPP
#define taoyao_RoomClient_HPP
#endif taoyao_RoomClient_HPP
#endif // taoyao_RoomClient_HPP

View File

@@ -7,4 +7,12 @@
#ifndef taoyao_SessionClient_HPP
#define taoyao_SessionClient_HPP
#endif taoyao_SessionClient_HPP
namespace acgist {
class SessionClient {
};
}
#endif // taoyao_SessionClient_HPP

View File

@@ -1 +1,18 @@
export const add: (a: number, b: number) => number;
export const sessionCall: () => void;
export const sessionPause: () => void;
export const sessionResume: () => void;
export const sessionExchange: () => void;
export const sessionClose: () => void;
export const mediaConsume: () => void;
export const mediaConsumerClose: () => void;
export const mediaConsumerPause: () => void;
export const mediaConsumerResume: () => void;
export const mediaProducerClose: () => void;
export const mediaProducerPause: () => void;
export const mediaProducerResume: () => void;
export const roomClientList: () => void;
export const roomClose: () => void;
export const roomEnter: () => void;
export const roomExpel: () => void;
export const roomInvite: () => void;
export const roomLeave: () => void;

View File

@@ -1,41 +1,33 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'EntryAbility', 'onCreate');
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
hilog.info(0x0000, 'EntryAbility', 'onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
hilog.info(0x0000, 'EntryAbility', 'onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
hilog.info(0x0000, 'EntryAbility', 'onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
hilog.info(0x0000, 'EntryAbility', 'onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
hilog.info(0x0000, 'EntryAbility', 'onBackground');
}
};

View File

@@ -1,25 +1,31 @@
import hilog from '@ohos.hilog';
// import testNapi from 'libtaoyao.so'
import { signal } from "../taoyao/TaoyaoSignal";
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
Button("连接信令")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(() => {
// hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
})
signal.connect();
});
}
.width('100%')
.width('50%');
Column() {
Button("断开信令")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(() => {
signal.close();
});
}
.width('50%');
}
.height('100%')
.height('100%');
}
}

View File

@@ -1,18 +0,0 @@
/**
* 信令连接
*
* @author acgist
*/
// import { BusinessError } from '@ohos.base';
import webSocket from '@ohos.net.webSocket';
export default class TaoyaoSignal {
// const socket;
//
// void connect(address) {
//
// }
}

View File

@@ -0,0 +1,35 @@
/**
* 配置
*
* @author acgist
*/
class Signal {
// 终端名称
name: string = "鸿蒙";
// 终端ID
clientId: string = "harmony";
// 终端类型
clientType: string = "MOBILE";
// 信令账号
username: string = "taoyao";
// 信令密码
password: string = "taoyao";
};
class Setting {
// 信令地址
signalAddress: string = "wss://192.168.8.204:8888/websocket.signal";
// 信令版本
version: string = "1.0.0";
// 信令配置
signal: Signal = new Signal();
};
const setting = new Setting();
export {
setting
}

View File

@@ -0,0 +1,210 @@
/**
* 信令连接
*
* @author acgist
*/
import hilog from '@ohos.hilog';
import webSocket from '@ohos.net.webSocket';
import { setting } from './Setting';
interface BusinessError<T = void> extends Error {
code: number;
data?: T;
}
class TaoyaoSignal {
// WebSocket信令连接
socket: webSocket.WebSocket;
// 是否关闭
closed: boolean = false;
// 是否连接成功
connected: boolean = false;
// 心跳定时
heartbeatTimer: number;
// 同步请求
callbackMapping = new Map();
// 当前消息索引
index: number = 0;
// 最大消息索引
maxIndex: number = 999;
// 当前终端索引
clientIndex: number = 99999;
connect() {
if(this.socket) {
this.socket.close();
}
this.connected = false;
hilog.info(0x0000, 'TaoyaoSignal', '连接信令:%s', setting.signalAddress);
this.socket = webSocket.createWebSocket();
this.socket.on('open', (err: BusinessError, value: Object) => {
hilog.info(0x0000, 'TaoyaoSignal', '打开信令:%s', setting.signalAddress);
this.register();
this.connected = true;
});
this.socket.on('message', (err: BusinessError, value: string | ArrayBuffer) => {
hilog.debug(0x0000, 'TaoyaoSignal', '信令消息:%s', value);
try {
this.onMessage(value);
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '处理信令消息异常:%s', value, error);
}
});
this.socket.on('close', (err: BusinessError, value: Object) => {
hilog.error(0x0000, 'TaoyaoSignal', '关闭信令:%s', setting.signalAddress, err);
this.reconnect();
});
this.socket.on('error', (err: BusinessError) => {
hilog.error(0x0000, 'TaoyaoSignal', '信令异常:%s', setting.signalAddress, err);
this.reconnect();
});
this.socket.connect(setting.signalAddress, (err: BusinessError, value: boolean) => {
hilog.info(0x0000, 'TaoyaoSignal', '信令连接成功:%s', setting.signalAddress);
});
};
reconnect() {
if(!this.closed) {
setTimeout(() => this.connect(), 5000);
}
}
close() {
hilog.info(0x0000, 'TaoyaoSignal', '关闭信令:%s', setting.signalAddress);
this.closed = true;
this.connected = false;
if(this.socket) {
this.socket.close();
}
}
async register() {
const response: any = await this.request("client::register", {
name : setting.signal.name,
clientId : setting.signal.clientId,
clientType: setting.signal.clientType,
username : setting.signal.username,
password : setting.signal.password,
battery : 100,
charging : true,
});
const { body } = response;
const { index } = body;
this.clientIndex = index;
hilog.info(0x0000, "TaoyaoSignal", "信令注册成功:%d", index);
this.heartbeat();
}
heartbeat() {
if(this.heartbeatTimer) {
clearInterval(this.heartbeatTimer);
}
this.heartbeatTimer = setInterval(() => {
this.send("client::heartbeat", {
battery : 100,
charging: true,
});
}, 30 * 1000);
};
buildId() {
if (++this.index > this.maxIndex) {
this.index = 0;
}
const date = new Date();
return (
100000000000000 * date.getDate() +
1000000000000 * date.getHours() +
10000000000 * date.getMinutes() +
100000000 * date.getSeconds() +
1000 * this.clientIndex +
this.index
);
}
send(signal, body) {
const header = {
v: setting.version,
id: this.buildId(),
signal
};
const message = {
header,
body
};
try {
this.socket.send(JSON.stringify(message));
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '发送消息异常:%o', message, error);
}
}
async request(signal, body) {
const id = this.buildId();
return new Promise((resolve, reject) => {
const header = {
v: setting.version,
id,
signal
};
const message = {
header,
body
};
// 设置超时
const rejectTimeout = setTimeout(() => {
this.callbackMapping.delete(id);
reject("请求超时");
}, 5000);
// 请求回调
this.callbackMapping.set(id, (response) => {
resolve(response);
clearTimeout(rejectTimeout);
// 默认不用继续处理
return true;
});
// 发送消息
try {
this.socket.send(JSON.stringify(message));
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '发送消息异常:%o', message, error);
reject(error);
}
});
}
onMessage(message) {
const json = JSON.parse(message);
const {
header,
body,
} = json;
const {
id
} = header;
if (this.callbackMapping.has(id)) {
hilog.info(0x0000, "TaoyaoSignal", "处理同步消息:%s", message);
try {
if(
this.callbackMapping.get(id)(json)
) {
return;
}
} finally {
this.callbackMapping.delete(id);
}
}
hilog.info(0x0000, "TaoyaoSignal", "处理异步消息:%s", message);
// TODO
}
}
const signal = new TaoyaoSignal();
export {
signal
}

View File

@@ -1,11 +1,11 @@
{
"module": {
"name": "media",
"type": "entry",
"name" : "media",
"type" : "entry",
"pages": "$profile:main_pages",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"installationFree": false,
"installationFree" : false,
"deliveryWithInstall": true,
"deviceTypes": [
"phone",
@@ -13,8 +13,8 @@
],
"abilities": [
{
"name": "EntryAbility",
"icon": "$media:icon",
"name" : "EntryAbility",
"icon" : "$media:icon",
"label": "$string:EntryAbility_label",
"exported": true,
"srcEntry": "./ets/entryability/EntryAbility.ts",
@@ -32,6 +32,26 @@
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.CAMERA",
"usedScene": {
"when": "always"
}
},
{
"name": "ohos.permission.INTERNET",
"usedScene": {
"when": "always"
}
},
{
"name": "ohos.permission.MICROPHONE",
"usedScene": {
"when": "always"
}
}
]
}
}

View File

@@ -5,4 +5,4 @@
"value": "#FFFFFF"
}
]
}
}

View File

@@ -6,11 +6,11 @@
},
{
"name": "EntryAbility_desc",
"value": "主界面"
"value": "桃夭媒体服务"
},
{
"name": "EntryAbility_label",
"value": "主界面"
"value": "桃夭"
}
]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -1,10 +1,10 @@
{
"name": "taoyao",
"main": "",
"name" : "taoyao",
"main" : "",
"author": "acgist",
"description": "桃夭鸿蒙终端",
"version": "1.0.0",
"license": "Apache-2.0",
"description" : "桃夭鸿蒙终端",
"dependencies": {},
"devDependencies": {
"@ohos/hypium": "1.0.6"