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_
|
||||
#define _RTC_H_
|
||||
#ifndef _X_H_
|
||||
#define _X_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -10,6 +10,8 @@ enum ws_status { WS_CONNECTING = 0, WS_OPEN, WS_FAILED, WS_CLOSED, WS_UNKNOWN };
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct Peer PeerPtr;
|
||||
|
||||
typedef void (*OnReceiveBuffer)(unsigned char*, size_t, const char*,
|
||||
const size_t);
|
||||
|
||||
@@ -21,15 +23,13 @@ typedef struct {
|
||||
NetStatusReport net_status_report;
|
||||
} 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 RegisterPeer();
|
||||
int SendData(PeerPtr* peer_ptr, const char* data, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -19,7 +19,7 @@ PeerConnection::PeerConnection() {}
|
||||
|
||||
PeerConnection::~PeerConnection() {}
|
||||
|
||||
int PeerConnection::Init(Params params) {
|
||||
int PeerConnection::Init(PeerConnectionParams params) {
|
||||
INIReader reader(params.cfg_path);
|
||||
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
||||
std::string cfg_signal_server_port =
|
||||
@@ -78,7 +78,7 @@ int PeerConnection::Init(Params params) {
|
||||
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);
|
||||
std::string cfg_signal_server_ip = reader.Get("signal server", "ip", "-1");
|
||||
std::string cfg_signal_server_port =
|
||||
|
||||
@@ -8,26 +8,25 @@
|
||||
|
||||
enum SignalStatus { Connecting = 0, Connected, Closed };
|
||||
|
||||
typedef void (*OnReceiveBuffer)(unsigned char *, size_t, const char *,
|
||||
const size_t);
|
||||
|
||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
||||
|
||||
typedef struct {
|
||||
const char *cfg_path;
|
||||
OnReceiveBuffer on_receive_buffer;
|
||||
NetStatusReport net_status_report;
|
||||
} PeerConnectionParams;
|
||||
|
||||
class PeerConnection {
|
||||
public:
|
||||
typedef void (*OnReceiveBuffer)(unsigned char *, size_t, const char *,
|
||||
const size_t);
|
||||
|
||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
||||
|
||||
typedef struct {
|
||||
const char *cfg_path;
|
||||
OnReceiveBuffer on_receive_buffer;
|
||||
NetStatusReport net_status_report;
|
||||
} Params;
|
||||
|
||||
public:
|
||||
PeerConnection();
|
||||
~PeerConnection();
|
||||
|
||||
public:
|
||||
int Init(Params params);
|
||||
int Init(Params params, std::string const &id);
|
||||
int Init(PeerConnectionParams params);
|
||||
int Init(PeerConnectionParams params, std::string const &id);
|
||||
int Destroy();
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user