|
@@ -48,9 +48,8 @@ namespace rtc {
|
|
IceTransport::IceTransport(const Configuration &config, Description::Role role,
|
|
IceTransport::IceTransport(const Configuration &config, Description::Role role,
|
|
candidate_callback candidateCallback, state_callback stateChangeCallback,
|
|
candidate_callback candidateCallback, state_callback stateChangeCallback,
|
|
gathering_state_callback gatheringStateChangeCallback)
|
|
gathering_state_callback gatheringStateChangeCallback)
|
|
- : mRole(role), mMid("0"), mState(State::Disconnected), mGatheringState(GatheringState::New),
|
|
|
|
- mCandidateCallback(std::move(candidateCallback)),
|
|
|
|
- mStateChangeCallback(std::move(stateChangeCallback)),
|
|
|
|
|
|
+ : Transport(nullptr, std::move(stateChangeCallback)), mRole(role), mMid("0"),
|
|
|
|
+ mGatheringState(GatheringState::New), mCandidateCallback(std::move(candidateCallback)),
|
|
mGatheringStateChangeCallback(std::move(gatheringStateChangeCallback)),
|
|
mGatheringStateChangeCallback(std::move(gatheringStateChangeCallback)),
|
|
mAgent(nullptr, nullptr) {
|
|
mAgent(nullptr, nullptr) {
|
|
|
|
|
|
@@ -108,8 +107,6 @@ bool IceTransport::stop() {
|
|
|
|
|
|
Description::Role IceTransport::role() const { return mRole; }
|
|
Description::Role IceTransport::role() const { return mRole; }
|
|
|
|
|
|
-IceTransport::State IceTransport::state() const { return mState; }
|
|
|
|
-
|
|
|
|
Description IceTransport::getLocalDescription(Description::Type type) const {
|
|
Description IceTransport::getLocalDescription(Description::Type type) const {
|
|
char sdp[JUICE_MAX_SDP_STRING_LEN];
|
|
char sdp[JUICE_MAX_SDP_STRING_LEN];
|
|
if (juice_get_local_description(mAgent.get(), sdp, JUICE_MAX_SDP_STRING_LEN) < 0)
|
|
if (juice_get_local_description(mAgent.get(), sdp, JUICE_MAX_SDP_STRING_LEN) < 0)
|
|
@@ -161,7 +158,8 @@ std::optional<string> IceTransport::getRemoteAddress() const {
|
|
}
|
|
}
|
|
|
|
|
|
bool IceTransport::send(message_ptr message) {
|
|
bool IceTransport::send(message_ptr message) {
|
|
- if (!message || (mState != State::Connected && mState != State::Completed))
|
|
|
|
|
|
+ auto s = state();
|
|
|
|
+ if (!message || (s != State::Connected && s != State::Completed))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
PLOG_VERBOSE << "Send size=" << message->size();
|
|
PLOG_VERBOSE << "Send size=" << message->size();
|
|
@@ -173,18 +171,29 @@ bool IceTransport::outgoing(message_ptr message) {
|
|
message->size()) >= 0;
|
|
message->size()) >= 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void IceTransport::changeState(State state) {
|
|
|
|
- if (mState.exchange(state) != state)
|
|
|
|
- mStateChangeCallback(mState);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void IceTransport::changeGatheringState(GatheringState state) {
|
|
void IceTransport::changeGatheringState(GatheringState state) {
|
|
if (mGatheringState.exchange(state) != state)
|
|
if (mGatheringState.exchange(state) != state)
|
|
mGatheringStateChangeCallback(mGatheringState);
|
|
mGatheringStateChangeCallback(mGatheringState);
|
|
}
|
|
}
|
|
|
|
|
|
void IceTransport::processStateChange(unsigned int state) {
|
|
void IceTransport::processStateChange(unsigned int state) {
|
|
- changeState(static_cast<State>(state));
|
|
|
|
|
|
+ switch (state) {
|
|
|
|
+ case JUICE_STATE_DISCONNECTED:
|
|
|
|
+ changeState(State::Disconnected);
|
|
|
|
+ break;
|
|
|
|
+ case JUICE_STATE_CONNECTING:
|
|
|
|
+ changeState(State::Connecting);
|
|
|
|
+ break;
|
|
|
|
+ case JUICE_STATE_CONNECTED:
|
|
|
|
+ changeState(State::Connected);
|
|
|
|
+ break;
|
|
|
|
+ case JUICE_STATE_COMPLETED:
|
|
|
|
+ changeState(State::Completed);
|
|
|
|
+ break;
|
|
|
|
+ case JUICE_STATE_FAILED:
|
|
|
|
+ changeState(State::Failed);
|
|
|
|
+ break;
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
void IceTransport::processCandidate(const string &candidate) {
|
|
void IceTransport::processCandidate(const string &candidate) {
|
|
@@ -263,9 +272,8 @@ namespace rtc {
|
|
IceTransport::IceTransport(const Configuration &config, Description::Role role,
|
|
IceTransport::IceTransport(const Configuration &config, Description::Role role,
|
|
candidate_callback candidateCallback, state_callback stateChangeCallback,
|
|
candidate_callback candidateCallback, state_callback stateChangeCallback,
|
|
gathering_state_callback gatheringStateChangeCallback)
|
|
gathering_state_callback gatheringStateChangeCallback)
|
|
- : mRole(role), mMid("0"), mState(State::Disconnected), mGatheringState(GatheringState::New),
|
|
|
|
- mCandidateCallback(std::move(candidateCallback)),
|
|
|
|
- mStateChangeCallback(std::move(stateChangeCallback)),
|
|
|
|
|
|
+ : Transport(nullptr, std::move(stateChangeCallback)), mRole(role), mMid("0"),
|
|
|
|
+ mGatheringState(GatheringState::New), mCandidateCallback(std::move(candidateCallback)),
|
|
mGatheringStateChangeCallback(std::move(gatheringStateChangeCallback)),
|
|
mGatheringStateChangeCallback(std::move(gatheringStateChangeCallback)),
|
|
mNiceAgent(nullptr, nullptr), mMainLoop(nullptr, nullptr) {
|
|
mNiceAgent(nullptr, nullptr), mMainLoop(nullptr, nullptr) {
|
|
|
|
|
|
@@ -457,8 +465,6 @@ bool IceTransport::stop() {
|
|
|
|
|
|
Description::Role IceTransport::role() const { return mRole; }
|
|
Description::Role IceTransport::role() const { return mRole; }
|
|
|
|
|
|
-IceTransport::State IceTransport::state() const { return mState; }
|
|
|
|
-
|
|
|
|
Description IceTransport::getLocalDescription(Description::Type type) const {
|
|
Description IceTransport::getLocalDescription(Description::Type type) const {
|
|
// RFC 8445: The initiating agent that started the ICE processing MUST take the controlling
|
|
// RFC 8445: The initiating agent that started the ICE processing MUST take the controlling
|
|
// role, and the other MUST take the controlled role.
|
|
// role, and the other MUST take the controlled role.
|
|
@@ -529,7 +535,8 @@ std::optional<string> IceTransport::getRemoteAddress() const {
|
|
}
|
|
}
|
|
|
|
|
|
bool IceTransport::send(message_ptr message) {
|
|
bool IceTransport::send(message_ptr message) {
|
|
- if (!message || (mState != State::Connected && mState != State::Completed))
|
|
|
|
|
|
+ auto s = state();
|
|
|
|
+ if (!message || (s != State::Connected && s != State::Completed))
|
|
return false;
|
|
return false;
|
|
|
|
|
|
PLOG_VERBOSE << "Send size=" << message->size();
|
|
PLOG_VERBOSE << "Send size=" << message->size();
|
|
@@ -541,11 +548,6 @@ bool IceTransport::outgoing(message_ptr message) {
|
|
reinterpret_cast<const char *>(message->data())) >= 0;
|
|
reinterpret_cast<const char *>(message->data())) >= 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void IceTransport::changeState(State state) {
|
|
|
|
- if (mState.exchange(state) != state)
|
|
|
|
- mStateChangeCallback(mState);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void IceTransport::changeGatheringState(GatheringState state) {
|
|
void IceTransport::changeGatheringState(GatheringState state) {
|
|
if (mGatheringState.exchange(state) != state)
|
|
if (mGatheringState.exchange(state) != state)
|
|
mGatheringStateChangeCallback(mGatheringState);
|
|
mGatheringStateChangeCallback(mGatheringState);
|
|
@@ -576,7 +578,23 @@ void IceTransport::processStateChange(unsigned int state) {
|
|
mTimeoutId = 0;
|
|
mTimeoutId = 0;
|
|
}
|
|
}
|
|
|
|
|
|
- changeState(static_cast<State>(state));
|
|
|
|
|
|
+ switch (state) {
|
|
|
|
+ case NICE_COMPONENT_STATE_DISCONNECTED:
|
|
|
|
+ changeState(State::Disconnected);
|
|
|
|
+ break;
|
|
|
|
+ case NICE_COMPONENT_STATE_CONNECTING:
|
|
|
|
+ changeState(State::Connecting);
|
|
|
|
+ break;
|
|
|
|
+ case NICE_COMPONENT_STATE_CONNECTED:
|
|
|
|
+ changeState(State::Connected);
|
|
|
|
+ break;
|
|
|
|
+ case NICE_COMPONENT_STATE_READY:
|
|
|
|
+ changeState(State::Completed);
|
|
|
|
+ break;
|
|
|
|
+ case NICE_COMPONENT_STATE_FAILED:
|
|
|
|
+ changeState(State::Failed);
|
|
|
|
+ break;
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
string IceTransport::AddressToString(const NiceAddress &addr) {
|
|
string IceTransport::AddressToString(const NiceAddress &addr) {
|