mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Add callback for connection status
This commit is contained in:
@@ -4,8 +4,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum ws_status { WS_CONNECTING = 0, WS_OPEN, WS_FAILED, WS_CLOSED, WS_UNKNOWN };
|
||||
enum DATA_TYPE { VIDEO = 0, AUDIO, DATA };
|
||||
enum ConnectionStatus {
|
||||
Connecting = 0,
|
||||
Connected,
|
||||
Failed,
|
||||
Closed,
|
||||
IncorrectPassword
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -15,6 +21,8 @@ typedef struct Peer PeerPtr;
|
||||
|
||||
typedef void (*OnReceiveBuffer)(const char*, size_t, const char*, size_t);
|
||||
|
||||
typedef void (*OnConnectionStatus)(ConnectionStatus status);
|
||||
|
||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
||||
|
||||
typedef struct {
|
||||
@@ -22,6 +30,7 @@ typedef struct {
|
||||
OnReceiveBuffer on_receive_video_buffer;
|
||||
OnReceiveBuffer on_receive_audio_buffer;
|
||||
OnReceiveBuffer on_receive_data_buffer;
|
||||
OnConnectionStatus on_connection_status;
|
||||
NetStatusReport net_status_report;
|
||||
} Params;
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
||||
on_receive_video_buffer_ = params.on_receive_video_buffer;
|
||||
on_receive_audio_buffer_ = params.on_receive_audio_buffer;
|
||||
on_receive_data_buffer_ = params.on_receive_data_buffer;
|
||||
on_connection_status_ = params.on_connection_status;
|
||||
|
||||
on_receive_ws_msg_ = [this](const std::string &msg) { ProcessSignal(msg); };
|
||||
|
||||
@@ -97,6 +98,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
||||
on_ice_status_change_ = [this](std::string ice_status) {
|
||||
if ("completed" == ice_status) {
|
||||
ice_ready_ = true;
|
||||
on_connection_status_(ConnectionStatus::Connected);
|
||||
b_force_i_frame_ = true;
|
||||
LOG_INFO("Ice finish");
|
||||
} else {
|
||||
@@ -111,7 +113,7 @@ int PeerConnection::Init(PeerConnectionParams params,
|
||||
}
|
||||
|
||||
do {
|
||||
} while (SignalStatus::Connected != GetSignalStatus());
|
||||
} while (SignalStatus::SignalConnected != GetSignalStatus());
|
||||
|
||||
nv12_data_ = new char[1280 * 720 * 3 / 2];
|
||||
|
||||
@@ -238,7 +240,7 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
||||
LOG_INFO("Receive local peer websocket connection id [{}]",
|
||||
ws_connection_id_);
|
||||
std::lock_guard<std::mutex> l(signal_status_mutex_);
|
||||
signal_status_ = SignalStatus::Connected;
|
||||
signal_status_ = SignalStatus::SignalConnected;
|
||||
break;
|
||||
}
|
||||
case "transmission_id"_H: {
|
||||
@@ -260,6 +262,7 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
||||
if (status == "failed") {
|
||||
std::string reason = j["reason"].get<std::string>();
|
||||
LOG_ERROR("{}", reason);
|
||||
on_connection_status_(ConnectionStatus::IncorrectPassword);
|
||||
} else {
|
||||
if (user_id_list_.empty()) {
|
||||
LOG_WARN("Wait for host create transmission [{}]", transmission_id);
|
||||
@@ -295,6 +298,8 @@ void PeerConnection::ProcessSignal(const std::string &signal) {
|
||||
cfg_turn_server_password_);
|
||||
ice_transmission_list_[remote_user_id]->JoinTransmission();
|
||||
}
|
||||
|
||||
on_connection_status_(ConnectionStatus::Connecting);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -9,12 +9,15 @@
|
||||
#include "video_decoder_factory.h"
|
||||
#include "video_encoder_factory.h"
|
||||
#include "ws_transmission.h"
|
||||
#include "x.h"
|
||||
|
||||
enum SignalStatus { Connecting = 0, Connected, Closed };
|
||||
enum SignalStatus { SignalConnecting = 0, SignalConnected, SignalClosed };
|
||||
|
||||
typedef void (*OnReceiveBuffer)(const char *, size_t, const char *,
|
||||
const size_t);
|
||||
|
||||
typedef void (*OnConnectionStatus)(ConnectionStatus status);
|
||||
|
||||
typedef void (*NetStatusReport)(const unsigned short, const unsigned short);
|
||||
|
||||
typedef struct {
|
||||
@@ -22,6 +25,7 @@ typedef struct {
|
||||
OnReceiveBuffer on_receive_video_buffer;
|
||||
OnReceiveBuffer on_receive_audio_buffer;
|
||||
OnReceiveBuffer on_receive_data_buffer;
|
||||
OnConnectionStatus on_connection_status;
|
||||
NetStatusReport net_status_report;
|
||||
} PeerConnectionParams;
|
||||
|
||||
@@ -81,7 +85,7 @@ class PeerConnection {
|
||||
std::string user_id_ = "";
|
||||
std::string transmission_id_ = "";
|
||||
std::vector<std::string> user_id_list_;
|
||||
SignalStatus signal_status_ = SignalStatus::Closed;
|
||||
SignalStatus signal_status_ = SignalStatus::SignalClosed;
|
||||
std::mutex signal_status_mutex_;
|
||||
|
||||
private:
|
||||
@@ -99,6 +103,7 @@ class PeerConnection {
|
||||
OnReceiveBuffer on_receive_video_buffer_;
|
||||
OnReceiveBuffer on_receive_audio_buffer_;
|
||||
OnReceiveBuffer on_receive_data_buffer_;
|
||||
OnConnectionStatus on_connection_status_;
|
||||
char *nv12_data_ = nullptr;
|
||||
bool inited_ = false;
|
||||
std::string password_;
|
||||
|
||||
@@ -19,6 +19,7 @@ PeerPtr *CreatePeer(const Params *params) {
|
||||
peer_ptr->pc_params.on_receive_video_buffer = params->on_receive_video_buffer;
|
||||
peer_ptr->pc_params.on_receive_audio_buffer = params->on_receive_audio_buffer;
|
||||
peer_ptr->pc_params.on_receive_data_buffer = params->on_receive_data_buffer;
|
||||
peer_ptr->pc_params.on_connection_status = params->on_connection_status;
|
||||
peer_ptr->pc_params.net_status_report = params->net_status_report;
|
||||
|
||||
return peer_ptr;
|
||||
|
||||
Reference in New Issue
Block a user