mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Modify interface
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#ifndef _RTC_H_
|
#ifndef _X_H_
|
||||||
#define _RTC_H_
|
#define _X_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -10,6 +10,8 @@ enum ws_status { WS_CONNECTING = 0, WS_OPEN, WS_FAILED, WS_CLOSED, WS_UNKNOWN };
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct Peer PeerPtr;
|
||||||
|
|
||||||
typedef void (*OnReceiveBuffer)(unsigned char*, size_t, const char*,
|
typedef void (*OnReceiveBuffer)(unsigned char*, size_t, const char*,
|
||||||
const size_t);
|
const size_t);
|
||||||
|
|
||||||
@@ -21,15 +23,13 @@ typedef struct {
|
|||||||
NetStatusReport net_status_report;
|
NetStatusReport net_status_report;
|
||||||
} Params;
|
} Params;
|
||||||
|
|
||||||
int CreatePeerConnection(Params params);
|
PeerPtr* CreatePeer(const Params* params);
|
||||||
|
|
||||||
int CreatePeerConnectionWithID(Params params, const char* id);
|
int CreateConnection(PeerPtr* peer_ptr);
|
||||||
|
|
||||||
int SendData(const char* data, size_t size);
|
int JoinConnection(PeerPtr* peer_ptr, const char* connection_id);
|
||||||
|
|
||||||
int rtc();
|
int SendData(PeerPtr* peer_ptr, const char* data, size_t size);
|
||||||
|
|
||||||
int RegisterPeer();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ PeerConnection::PeerConnection() {}
|
|||||||
|
|
||||||
PeerConnection::~PeerConnection() {}
|
PeerConnection::~PeerConnection() {}
|
||||||
|
|
||||||
int PeerConnection::Init(Params params) {
|
int PeerConnection::Init(PeerConnectionParams params) {
|
||||||
INIReader reader(params.cfg_path);
|
INIReader reader(params.cfg_path);
|
||||||
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
||||||
std::string cfg_signal_server_port =
|
std::string cfg_signal_server_port =
|
||||||
@@ -78,7 +78,7 @@ int PeerConnection::Init(Params params) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeerConnection::Init(Params params, std::string const &id) {
|
int PeerConnection::Init(PeerConnectionParams params, std::string const &id) {
|
||||||
INIReader reader(params.cfg_path);
|
INIReader reader(params.cfg_path);
|
||||||
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
||||||
std::string cfg_signal_server_port =
|
std::string cfg_signal_server_port =
|
||||||
|
|||||||
@@ -8,26 +8,25 @@
|
|||||||
|
|
||||||
enum SignalStatus { Connecting = 0, Connected, Closed };
|
enum SignalStatus { Connecting = 0, Connected, Closed };
|
||||||
|
|
||||||
class PeerConnection {
|
typedef void (*OnReceiveBuffer)(unsigned char *, size_t, const char *,
|
||||||
public:
|
|
||||||
typedef void (*OnReceiveBuffer)(unsigned char *, size_t, const char *,
|
|
||||||
const size_t);
|
const size_t);
|
||||||
|
|
||||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *cfg_path;
|
const char *cfg_path;
|
||||||
OnReceiveBuffer on_receive_buffer;
|
OnReceiveBuffer on_receive_buffer;
|
||||||
NetStatusReport net_status_report;
|
NetStatusReport net_status_report;
|
||||||
} Params;
|
} PeerConnectionParams;
|
||||||
|
|
||||||
|
class PeerConnection {
|
||||||
public:
|
public:
|
||||||
PeerConnection();
|
PeerConnection();
|
||||||
~PeerConnection();
|
~PeerConnection();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int Init(Params params);
|
int Init(PeerConnectionParams params);
|
||||||
int Init(Params params, std::string const &id);
|
int Init(PeerConnectionParams params, std::string const &id);
|
||||||
int Destroy();
|
int Destroy();
|
||||||
|
|
||||||
SignalStatus GetSignalStatus();
|
SignalStatus GetSignalStatus();
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
#include "rtc.h"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "ice_agent.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "nlohmann/json.hpp"
|
|
||||||
#include "peer_connection.h"
|
|
||||||
#include "ws_transport.h"
|
|
||||||
|
|
||||||
using nlohmann::json;
|
|
||||||
|
|
||||||
static PeerConnection *peer_connection;
|
|
||||||
|
|
||||||
int CreatePeerConnection(Params params) {
|
|
||||||
PeerConnection::Params pc_params;
|
|
||||||
pc_params.cfg_path = params.cfg_path;
|
|
||||||
pc_params.on_receive_buffer = params.on_receive_buffer;
|
|
||||||
pc_params.net_status_report = params.net_status_report;
|
|
||||||
|
|
||||||
peer_connection = new PeerConnection();
|
|
||||||
peer_connection->Init(pc_params);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CreatePeerConnectionWithID(Params params, const char *id) {
|
|
||||||
PeerConnection::Params pc_params;
|
|
||||||
pc_params.cfg_path = params.cfg_path;
|
|
||||||
pc_params.on_receive_buffer = params.on_receive_buffer;
|
|
||||||
pc_params.net_status_report = params.net_status_report;
|
|
||||||
|
|
||||||
peer_connection = new PeerConnection();
|
|
||||||
peer_connection->Init(pc_params, id);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SendData(const char *data, size_t size) {
|
|
||||||
peer_connection->SendData(data, size);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rtc() { return 0; }
|
|
||||||
40
src/rtc/x_inner.cpp
Normal file
40
src/rtc/x_inner.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "x_inner.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include "ice_agent.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "ws_transport.h"
|
||||||
|
#include "x.h"
|
||||||
|
|
||||||
|
using nlohmann::json;
|
||||||
|
|
||||||
|
static PeerConnection *peer_connection;
|
||||||
|
|
||||||
|
PeerPtr *CreatePeer(const Params *params) {
|
||||||
|
PeerPtr *peer_ptr = new PeerPtr;
|
||||||
|
peer_ptr->peer_connection = new PeerConnection();
|
||||||
|
peer_ptr->pc_params.cfg_path = params->cfg_path;
|
||||||
|
peer_ptr->pc_params.on_receive_buffer = params->on_receive_buffer;
|
||||||
|
peer_ptr->pc_params.net_status_report = params->net_status_report;
|
||||||
|
|
||||||
|
return peer_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CreateConnection(PeerPtr *peer_ptr) {
|
||||||
|
peer_ptr->peer_connection->Init(peer_ptr->pc_params);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JoinConnection(PeerPtr *peer_ptr, const char *connection_id) {
|
||||||
|
peer_ptr->peer_connection->Init(peer_ptr->pc_params, connection_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SendData(PeerPtr *peer_ptr, const char *data, size_t size) {
|
||||||
|
peer_ptr->peer_connection->SendData(data, size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rtc() { return 0; }
|
||||||
11
src/rtc/x_inner.h
Normal file
11
src/rtc/x_inner.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef _X_INNER_H_
|
||||||
|
#define _X_INNER_H_
|
||||||
|
|
||||||
|
#include "peer_connection.h"
|
||||||
|
|
||||||
|
struct Peer {
|
||||||
|
PeerConnection *peer_connection;
|
||||||
|
PeerConnectionParams pc_params;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "rtc.h"
|
#include "x.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv) {
|
||||||
Params params;
|
Params params;
|
||||||
params.cfg_path = "../../../../config/config.ini";
|
params.cfg_path = "../../../../config/config.ini";
|
||||||
CreatePeerConnectionWithID(params, "000000");
|
|
||||||
|
|
||||||
std::cout << "Finish CreatePeerConnectionWithID" << std::endl;
|
PeerPtr* peer = CreatePeer(¶ms);
|
||||||
|
JoinConnection(peer, "000000");
|
||||||
|
|
||||||
std::string msg = "Hello world";
|
std::string msg = "Hello world";
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ int main(int argc, char **argv) {
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
getchar();
|
getchar();
|
||||||
std::cout << "Send data: [" << msg << "]" << std::endl;
|
std::cout << "Send data: [" << msg << "]" << std::endl;
|
||||||
SendData(msg.data(), msg.size());
|
SendData(peer, msg.data(), msg.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
getchar();
|
getchar();
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "rtc.h"
|
#include "x.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv) {
|
||||||
Params params;
|
Params params;
|
||||||
params.cfg_path = "../../../../config/config.ini";
|
params.cfg_path = "../../../../config/config.ini";
|
||||||
CreatePeerConnection(params);
|
|
||||||
|
PeerPtr* peer = CreatePeer(¶ms);
|
||||||
|
CreateConnection(peer);
|
||||||
|
|
||||||
getchar();
|
getchar();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ target("projectx")
|
|||||||
add_deps("ice", "ws", "pc")
|
add_deps("ice", "ws", "pc")
|
||||||
add_files("src/rtc/*.cpp")
|
add_files("src/rtc/*.cpp")
|
||||||
add_packages("asio", "nlohmann_json")
|
add_packages("asio", "nlohmann_json")
|
||||||
add_includedirs("src/rtc", "src/ice", "src/ws", "src/pc")
|
add_includedirs("src/rtc", "src/ice", "src/ws", "src/pc", "src/interface")
|
||||||
add_rules("utils.symbols.export_all", {export_classes = true})
|
add_rules("utils.symbols.export_all", {export_classes = true})
|
||||||
-- set_policy("build.merge_archive", true)
|
-- set_policy("build.merge_archive", true)
|
||||||
-- set_targetdir("$(projectdir)/libdrtc/lib")
|
-- set_targetdir("$(projectdir)/libdrtc/lib")
|
||||||
@@ -82,10 +82,10 @@ target("Offer")
|
|||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("projectx")
|
add_deps("projectx")
|
||||||
add_files("tests/peerconnection/offer.cpp")
|
add_files("tests/peerconnection/offer.cpp")
|
||||||
add_includedirs("src/rtc")
|
add_includedirs("src/interface")
|
||||||
|
|
||||||
target("Answer")
|
target("Answer")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
add_deps("projectx")
|
add_deps("projectx")
|
||||||
add_files("tests/peerconnection/answer.cpp")
|
add_files("tests/peerconnection/answer.cpp")
|
||||||
add_includedirs("src/rtc")
|
add_includedirs("src/interface")
|
||||||
Reference in New Issue
Block a user