Added Candidate.candidate() method for symmetry with web API

This commit is contained in:
Paul-Louis Ageneau
2019-09-08 15:12:38 +02:00
parent 378135b413
commit 65813e4e31
4 changed files with 7 additions and 4 deletions

View File

@ -38,7 +38,7 @@ pc->onLocalDescription([](const rtc::Description &sdp) {
pc->onLocalCandidate([](const optional<rtc::Candidate> &candidate) {
if (candidate) {
MY_SEND_CANDIDATE_TO_REMOTE(string(*candidate), candidate->mid());
MY_SEND_CANDIDATE_TO_REMOTE(candidate->candidate(), candidate->mid());
} else {
// Gathering finished
}
@ -60,7 +60,7 @@ auto dc = pc->createDataChannel("test");
dc->onOpen([]() {
cout << "Open" << endl;
});
dc->onMessage([](variant<binary, string> message) {
dc->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) {
cout << "Received: " << get<string>(message) << endl;
}

View File

@ -29,6 +29,7 @@ class Candidate {
public:
Candidate(string candidate, string mid = "");
string candidate() const;
string mid() const;
operator string() const;

View File

@ -92,11 +92,13 @@ Candidate::Candidate(string candidate, string mid) {
}
}
string Candidate::candidate() const { return "candidate:" + mCandidate; }
string Candidate::mid() const { return mMid; }
Candidate::operator string() const {
std::ostringstream line;
line << "a=candidate:" << mCandidate;
line << "a=" << candidate();
return line.str();
}

View File

@ -65,7 +65,7 @@ int main(int argc, char **argv) {
dc1->onOpen([dc1]() {
cout << "DataChannel open: " << dc1->label() << endl;
});
dc1->onMessage([](variant<binary, string> message) {
dc1->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) {
cout << "Received: " << get<string>(message) << endl;
}