mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Add test interface for ice data transport
This commit is contained in:
@@ -41,7 +41,10 @@ int PeerConnection::Init(std::string const &uri) {
|
||||
}
|
||||
};
|
||||
|
||||
on_receive_ice_msg_ = [this](const char *data, size_t size) {};
|
||||
on_receive_ice_msg_ = [this](const char *data, size_t size) {
|
||||
std::string msg(data, size);
|
||||
LOG_INFO("Receive data: [{}]", msg.c_str());
|
||||
};
|
||||
|
||||
ws_transport_ = new WsTransport(on_receive_ws_msg_);
|
||||
if (ws_transport_) {
|
||||
@@ -83,7 +86,10 @@ int PeerConnection::Init(std::string const &uri, std::string const &id) {
|
||||
}
|
||||
};
|
||||
|
||||
on_receive_ice_msg_ = [this](const char *data, size_t size) {};
|
||||
on_receive_ice_msg_ = [this](const char *data, size_t size) {
|
||||
std::string msg(data, size);
|
||||
LOG_INFO("Receive data: [{}]", msg.c_str());
|
||||
};
|
||||
|
||||
transport_id_ = id;
|
||||
|
||||
@@ -110,4 +116,9 @@ int PeerConnection::Destroy() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SignalStatus PeerConnection::GetSignalStatus() { return signal_status_; }
|
||||
SignalStatus PeerConnection::GetSignalStatus() { return signal_status_; }
|
||||
|
||||
int PeerConnection::SendData(const char *data, size_t size) {
|
||||
ice_transport_->SendData(data, size);
|
||||
return 0;
|
||||
}
|
||||
@@ -20,6 +20,8 @@ class PeerConnection {
|
||||
|
||||
SignalStatus GetSignalStatus();
|
||||
|
||||
int SendData(const char *data, size_t size);
|
||||
|
||||
private:
|
||||
WsTransport *ws_transport_ = nullptr;
|
||||
IceTransport *ice_transport_ = nullptr;
|
||||
|
||||
@@ -1,44 +1,21 @@
|
||||
#include "rtc.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "ice_agent.h"
|
||||
#include "log.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "peer_connection.h"
|
||||
#include "ws_transport.h"
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
static const std::vector<std::string> siganl_status = {"Connecting",
|
||||
"Connected", "Closed"};
|
||||
|
||||
class WsSender : public WsCore {
|
||||
public:
|
||||
WsSender() {}
|
||||
~WsSender() {}
|
||||
|
||||
void OnReceiveMessage(const std::string &msg) {
|
||||
LOG_INFO("Receive msg: {}", msg);
|
||||
}
|
||||
};
|
||||
|
||||
static WsSender *ws_client;
|
||||
static PeerConnection *peer_connection;
|
||||
|
||||
int CreatePeerConnection(const char *uri) {
|
||||
peer_connection = new PeerConnection();
|
||||
peer_connection->Init(uri);
|
||||
|
||||
// do {
|
||||
// } while (SignalStatus::Connected != peer_connection->GetSignalStatus());
|
||||
|
||||
// LOG_INFO("Signal status: {}",
|
||||
// siganl_status[peer_connection->GetSignalStatus()]);
|
||||
|
||||
// peer_connection->CreateTransport();
|
||||
// peer_connection->CreateOffer();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -46,56 +23,12 @@ int CreatePeerConnectionWithID(const char *uri, const char *id) {
|
||||
peer_connection = new PeerConnection();
|
||||
peer_connection->Init(uri, id);
|
||||
|
||||
// do {
|
||||
// } while (SignalStatus::Connected != peer_connection->GetSignalStatus());
|
||||
|
||||
// LOG_INFO("Signal status: {}",
|
||||
// siganl_status[peer_connection->GetSignalStatus()]);
|
||||
|
||||
// peer_connection->CreateTransport(id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc() {
|
||||
ws_client = new WsSender();
|
||||
int SendData(const char *data, size_t size) {
|
||||
peer_connection->SendData(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CreateWsClient(const char *uri) {
|
||||
ws_client->Connect(uri);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WsSendMsg(const char *message) {
|
||||
ws_client->Send(message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ws_status GetWsStatus()
|
||||
// {
|
||||
// std::string ws_status = ws_client->GetStatus();
|
||||
|
||||
// if ("Connecting" == ws_status)
|
||||
// {
|
||||
// return ws_status::WS_CONNECTING;
|
||||
// }
|
||||
// else if ("Open" == ws_status)
|
||||
// {
|
||||
// return ws_status::WS_OPEN;
|
||||
// }
|
||||
// else if ("Failed" == ws_status)
|
||||
// {
|
||||
// return ws_status::WS_FAILED;
|
||||
// }
|
||||
// else if ("Closed" == ws_status)
|
||||
// {
|
||||
// return ws_status::WS_CLOSED;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return ws_status::WS_UNKNOWN;
|
||||
// }
|
||||
// }
|
||||
int rtc() { return 0; }
|
||||
@@ -11,18 +11,12 @@ int CreatePeerConnection(const char* uri);
|
||||
|
||||
int CreatePeerConnectionWithID(const char* uri, const char* id);
|
||||
|
||||
int SendData(const char* data, size_t size);
|
||||
|
||||
int rtc();
|
||||
|
||||
int ConnectToServer(const char* uri);
|
||||
|
||||
int RegisterPeer();
|
||||
|
||||
int CreateWsClient(const char* uri);
|
||||
|
||||
int WsSendMsg(const char* message);
|
||||
|
||||
ws_status GetWsStatus();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
int main(int argc, char **argv) {
|
||||
CreatePeerConnectionWithID("ws://localhost:9002", "000000");
|
||||
|
||||
std::cout << "Finish CreatePeerConnectionWithID" << std::endl;
|
||||
|
||||
std::string msg = "Hello world";
|
||||
|
||||
int i = 100;
|
||||
while (i--) {
|
||||
getchar();
|
||||
std::cout << "Send data: [" << msg << "]" << std::endl;
|
||||
SendData(msg.data(), msg.size());
|
||||
}
|
||||
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user