[*] 信令
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// "cppFlags" : "-D_LIBCPP_STD_VER=17",
|
||||
// "arguments" : "-DOHOS_STL=c++_static",
|
||||
// "arguments" : "-DOHOS_STL=c++_shared",
|
||||
// "abiFilters": [ "arm64-v8a" ]
|
||||
// "abiFilters": [ "arm64-v8a" ]
|
||||
"abiFilters": [ "armeabi-v7a" ]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -40,9 +40,10 @@ static std::mutex taoyaoMutex;
|
||||
napi_value args[size] = { nullptr }; \
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); \
|
||||
size_t length; \
|
||||
char chars[2048]; \
|
||||
char chars[2048] = { 0 }; \
|
||||
napi_get_value_string_utf8(env, args[0], chars, sizeof(chars), &length); \
|
||||
nlohmann::json json = nlohmann::json::parse(chars); \
|
||||
OH_LOG_INFO(LOG_APP, "解析JSON:%s", chars); \
|
||||
nlohmann::json json = nlohmann::json::parse(chars, chars + length); \
|
||||
nlohmann::json body = json["body"];
|
||||
#endif
|
||||
|
||||
@@ -163,15 +164,15 @@ static napi_value init(napi_env env, napi_callback_info info) {
|
||||
napi_create_reference(env, args[1], 1, &acgist::pushRef);
|
||||
napi_create_reference(env, args[2], 1, &acgist::requestRef);
|
||||
printSupportCodec();
|
||||
acgist::clientId = json["clientId"];
|
||||
acgist::name = json["name"];
|
||||
OH_LOG_INFO(LOG_APP, "加载libtaoyao");
|
||||
std::string version = mediasoupclient::Version();
|
||||
OH_LOG_INFO(LOG_APP, "加载MediasoupClient:%s", version.data());
|
||||
mediasoupclient::Initialize();
|
||||
OH_LOG_INFO(LOG_APP, "加载媒体功能");
|
||||
mediaManager = new MediaManager();
|
||||
mediaManager->init();
|
||||
// acgist::clientId = json["clientId"];
|
||||
// acgist::name = json["name"];
|
||||
// OH_LOG_INFO(LOG_APP, "加载libtaoyao");
|
||||
// std::string version = mediasoupclient::Version();
|
||||
// OH_LOG_INFO(LOG_APP, "加载MediasoupClient:%s", version.data());
|
||||
// mediasoupclient::Initialize();
|
||||
// OH_LOG_INFO(LOG_APP, "加载媒体功能");
|
||||
// mediaManager = new MediaManager();
|
||||
// mediaManager->init();
|
||||
napi_create_int32(env, 0, &ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -465,7 +466,7 @@ static napi_value Init(napi_env env, napi_value exports) {
|
||||
{ "mediaProducerPause", nullptr, acgist::mediaProducerPause, nullptr, nullptr, nullptr, napi_default, nullptr },
|
||||
{ "mediaProducerResume", nullptr, acgist::mediaProducerResume, nullptr, nullptr, nullptr, napi_default, nullptr },
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libtaoyao.so",
|
||||
"types": "./index.d.ts",
|
||||
"version": "1.0.0",
|
||||
"name" : "libtaoyao.so",
|
||||
"types" : "./index.d.ts",
|
||||
"version" : "1.0.0",
|
||||
"description": "桃夭媒体依赖"
|
||||
}
|
||||
@@ -4,6 +4,9 @@
|
||||
* @author acgist
|
||||
*/
|
||||
|
||||
import fs from '@ohos.file.fs';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
|
||||
class Signal {
|
||||
|
||||
// 终端名称
|
||||
@@ -22,19 +25,26 @@ class Signal {
|
||||
class Setting {
|
||||
|
||||
// 信令地址
|
||||
signalAddress: string = "wss://192.168.8.57:8888/websocket.signal";
|
||||
// signalAddress: string = "wss://192.168.1.100:8888/websocket.signal";
|
||||
// signalAddress: string = "wss://192.168.8.57:8888/websocket.signal";
|
||||
signalAddress: string = "wss://192.168.1.100:8888/websocket.signal";
|
||||
// 信令版本
|
||||
version: string = "1.0.0";
|
||||
// 信令配置
|
||||
signal : Signal = new Signal();
|
||||
// CA证书
|
||||
caPath : string = getContext(this) + "/cacert.pem";
|
||||
caPath : string = "/cacert.pem";
|
||||
|
||||
};
|
||||
|
||||
const setting = new Setting();
|
||||
|
||||
// 拷贝证书
|
||||
const caPath = getContext(this).filesDir + setting.caPath;
|
||||
const caFile = fs.createRandomAccessFileSync(caPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
|
||||
const caText = getContext(this).resourceManager.getRawFileContentSync("cacert.pem").buffer;
|
||||
caFile.writeSync(caText);
|
||||
caFile.close();
|
||||
|
||||
export {
|
||||
setting
|
||||
}
|
||||
|
||||
@@ -32,10 +32,12 @@ class TaoyaoSignal {
|
||||
clientIndex: number = 99999;
|
||||
|
||||
init() {
|
||||
taoyaoModule.init(JSON.stringify(setting.signal), signal.nativePush, signal.nativeRequest);
|
||||
hilog.info(0x0000, "TaoyaoSignal", "加载系统");
|
||||
taoyaoModule.init(JSON.stringify(setting.signal), this.nativePush, this.nativeRequest);
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
hilog.info(0x0000, "TaoyaoSignal", "卸载系统");
|
||||
taoyaoModule.shutdown(JSON.stringify(setting.signal));
|
||||
}
|
||||
|
||||
@@ -43,9 +45,13 @@ class TaoyaoSignal {
|
||||
* 连接信令
|
||||
*/
|
||||
connect() {
|
||||
if(this.connected) {
|
||||
return;
|
||||
}
|
||||
if(this.socket) {
|
||||
hilog.info(0x0000, "TaoyaoSignal", "信令已经连接关闭旧的连接:%{public}s", setting.signalAddress);
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
this.connected = false;
|
||||
this.socket = webSocket.createWebSocket();
|
||||
@@ -65,17 +71,21 @@ class TaoyaoSignal {
|
||||
});
|
||||
this.socket.on("close", (err: BusinessError, value: Object) => {
|
||||
hilog.error(0x0000, "TaoyaoSignal", "关闭信令:%{public}s %{public}s %{public}s", setting.signalAddress, JSON.stringify(value), JSON.stringify(err));
|
||||
this.connected = false;
|
||||
this.reconnect();
|
||||
});
|
||||
this.socket.on("error", (err: BusinessError) => {
|
||||
hilog.error(0x0000, "TaoyaoSignal", "信令异常:%{public}s %{public}s", setting.signalAddress, JSON.stringify(err));
|
||||
this.connected = false;
|
||||
this.reconnect();
|
||||
});
|
||||
// 配置CA证书
|
||||
const caPath = getContext(this).filesDir + setting.caPath;
|
||||
hilog.info(0x0000, "TaoyaoSignal", "配置证书:%{public}s", caPath);
|
||||
const options: webSocket.WebSocketRequestOptions = {
|
||||
caPath: setting.caPath
|
||||
caPath: caPath
|
||||
};
|
||||
hilog.info(0x0000, "TaoyaoSignal", "连接信令:%{public}s %{public}s", setting.signalAddress, setting.caPath);
|
||||
hilog.info(0x0000, "TaoyaoSignal", "连接信令:%{public}s", setting.signalAddress);
|
||||
this.socket.connect(setting.signalAddress, options, (err: BusinessError, value: boolean) => {
|
||||
hilog.info(0x0000, "TaoyaoSignal", "信令连接:%{public}s %{public}s %{public}s", setting.signalAddress, JSON.stringify(value), JSON.stringify(err));
|
||||
});
|
||||
@@ -102,6 +112,11 @@ class TaoyaoSignal {
|
||||
this.connected = false;
|
||||
if(this.socket) {
|
||||
this.socket.close();
|
||||
this.socket = null;
|
||||
}
|
||||
if(this.heartbeatTimer) {
|
||||
clearInterval(this.heartbeatTimer);
|
||||
this.heartbeatTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,9 +344,6 @@ class TaoyaoSignal {
|
||||
|
||||
const signal = new TaoyaoSignal();
|
||||
|
||||
// 加载系统
|
||||
taoyaoModule.init(JSON.stringify(setting.signal), signal.nativePush, signal.nativeRequest);
|
||||
|
||||
export {
|
||||
signal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user