Use config to declare signal/stun server info

This commit is contained in:
dijunkun
2023-07-18 16:58:53 +08:00
parent ea9ffbd6d8
commit 03cb767f1f
16 changed files with 830 additions and 34 deletions

View File

@@ -6,7 +6,7 @@
#include "log.h"
IceAgent::IceAgent() {}
IceAgent::IceAgent(std::string &ip, uint16_t port) : ip_(ip), port_(port) {}
IceAgent::~IceAgent() {}
@@ -20,8 +20,8 @@ int IceAgent::CreateIceAgent(juice_cb_state_changed_t on_state_changed,
memset(&config, 0, sizeof(config));
// STUN server example
config.stun_server_host = "120.77.216.215";
config.stun_server_port = 3478;
config.stun_server_host = ip_.c_str();
config.stun_server_port = port_;
config.cb_state_changed = on_state_changed;
config.cb_candidate = on_candidate;

View File

@@ -1,11 +1,13 @@
#ifndef _ICE_AGENT_H_
#define _ICE_AGENT_H_
#include <iostream>
#include "juice/juice.h"
class IceAgent {
public:
IceAgent();
IceAgent(std::string& ip, uint16_t port);
~IceAgent();
int CreateIceAgent(juice_cb_state_changed_t on_state_changed,
@@ -34,6 +36,8 @@ class IceAgent {
int Send(const char* data, size_t size);
private:
std::string ip_ = "";
uint16_t port_ = 0;
juice_agent_t* agent_ = nullptr;
char local_sdp_[JUICE_MAX_SDP_STRING_LEN];
juice_state_t state_;

View File

@@ -27,8 +27,8 @@ IceTransport::IceTransport(
IceTransport::~IceTransport() {}
int IceTransport::InitIceTransport() {
ice_agent_ = new IceAgent();
int IceTransport::InitIceTransport(std::string &ip, int port) {
ice_agent_ = new IceAgent(ip, port);
ice_agent_->CreateIceAgent(
[](juice_agent_t *agent, juice_state_t state, void *user_ptr) {
@@ -60,10 +60,11 @@ int IceTransport::InitIceTransport() {
return 0;
}
int IceTransport::InitIceTransport(std::string const &id) {
int IceTransport::InitIceTransport(std::string &ip, int port,
std::string const &id) {
transport_id_ = id;
ice_agent_ = new IceAgent();
ice_agent_ = new IceAgent(ip, port);
ice_agent_->CreateIceAgent(
[](juice_agent_t *agent, juice_state_t state, void *user_ptr) {

View File

@@ -13,8 +13,8 @@ class IceTransport {
~IceTransport();
int InitIceTransport();
int InitIceTransport(std::string const &id);
int InitIceTransport(std::string &ip, int port);
int InitIceTransport(std::string &ip, int port, std::string const &id);
int DestroyIceTransport();