mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Init project
This commit is contained in:
101
src/rtc/rtc.cpp
Normal file
101
src/rtc/rtc.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "rtc.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "ice_agent.h"
|
||||
#include "log.h"
|
||||
#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;
|
||||
}
|
||||
|
||||
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();
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
30
src/rtc/rtc.h
Normal file
30
src/rtc/rtc.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef _RTC_H_
|
||||
#define _RTC_H_
|
||||
|
||||
enum ws_status { WS_CONNECTING = 0, WS_OPEN, WS_FAILED, WS_CLOSED, WS_UNKNOWN };
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int CreatePeerConnection(const char* uri);
|
||||
|
||||
int CreatePeerConnectionWithID(const char* uri, const char* id);
|
||||
|
||||
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
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user