Skip to content

Commit b47bae7

Browse files
authored
Merge branch 'paullouisageneau:master' into feat/expose-callback-for-unknown-stun-ufrag
2 parents d15c2cd + 6fa7cff commit b47bae7

13 files changed

+210
-102
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.13)
22
project(libdatachannel
3-
VERSION 0.22.3
3+
VERSION 0.22.4
44
LANGUAGES CXX)
55
set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets")
66

DOC.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ Initiates the handshake process. Following this call, the local description call
207207
Arguments:
208208

209209
- `pc`: the Peer Connection identifier
210-
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
210+
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for automatic (recommended).
211+
212+
Warning: This function expects the optional type for the local description and not an SDP description. It is not possible to set an existing SDP description.
211213

212214
#### rtcSetRemoteDescription
213215

@@ -220,7 +222,8 @@ Sets the remote description received from the remote peer by the user's method o
220222
Arguments:
221223

222224
- `pc`: the Peer Connection identifier
223-
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
225+
- `sdp`: the remote description in SDP format
226+
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for automatic (not recommended).
224227

225228
If the remote description is an offer and `disableAutoNegotiation` was not set in `rtcConfiguration`, the library will automatically answer by calling `rtcSetLocalDescription` internally. Otherwise, the user must call it to answer the remote description.
226229

@@ -296,7 +299,7 @@ Return value: the length of the string copied in buffer (including the terminati
296299

297300
If `buffer` is `NULL`, the description is not copied but the size is still returned.
298301

299-
#### rtcGetRemoteDescription
302+
#### rtcGetRemoteDescriptionType
300303

301304
```
302305
int rtcGetRemoteDescriptionType(int pc, char *buffer, int size)
@@ -314,6 +317,22 @@ Return value: the length of the string copied in buffer (including the terminati
314317

315318
If `buffer` is `NULL`, the description is not copied but the size is still returned.
316319

320+
#### rtcCreateOffer/rtcCreateAnswer
321+
322+
```
323+
int rtcCreateOffer(int pc, char *buffer, int size)
324+
int rtcCreateAnswer(int pc, char *buffer, int size)
325+
```
326+
327+
Create a local offer or answer description in SDP format. These functions are intended only for specific use cases where the application needs to generate a description without setting it. It is useless to call them before `rtcSetLocalDescription` as it doesn't expect the user to supply a description.
328+
329+
- `pc`: the Peer Connection identifier
330+
- `buffer`: a user-supplied buffer to store the description
331+
- `size`: the size of `buffer`
332+
333+
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
334+
335+
If `buffer` is `NULL`, the description is not copied but the size is still returned.
317336

318337
#### rtcGetLocalAddress
319338

include/rtc/description.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ class RTC_CPP_EXPORT Description {
6666
bool ended() const;
6767

6868
void hintType(Type type);
69-
void setFingerprint(CertificateFingerprint f);
7069
void addIceOption(string option);
7170
void removeIceOption(const string &option);
71+
void setIceAttribute(string ufrag, string pwd);
72+
void setFingerprint(CertificateFingerprint f);
7273

7374
std::vector<string> attributes() const;
7475
void addAttribute(string attr);

include/rtc/peerconnection.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
9797
bool getSelectedCandidatePair(Candidate *local, Candidate *remote);
9898

9999
void setLocalDescription(Description::Type type = Description::Type::Unspec, LocalDescriptionInit init = {});
100+
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});
100101
void setRemoteDescription(Description description);
101102
void addRemoteCandidate(Candidate candidate);
102-
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});
103+
104+
// For specific use cases only
105+
Description createOffer();
106+
Description createAnswer();
103107

104108
void setMediaHandler(shared_ptr<MediaHandler> handler);
105109
shared_ptr<MediaHandler> getMediaHandler();

include/rtc/rtc.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ RTC_C_EXPORT int rtcSetIceStateChangeCallback(int pc, rtcIceStateChangeCallbackF
211211
RTC_C_EXPORT int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb);
212212
RTC_C_EXPORT int rtcSetSignalingStateChangeCallback(int pc, rtcSignalingStateCallbackFunc cb);
213213

214-
RTC_C_EXPORT int rtcSetLocalDescription(int pc, const char *type);
214+
RTC_C_EXPORT int rtcSetLocalDescription(int pc, const char *type); // type may be NULL
215215
RTC_C_EXPORT int rtcSetRemoteDescription(int pc, const char *sdp, const char *type);
216216
RTC_C_EXPORT int rtcAddRemoteCandidate(int pc, const char *cand, const char *mid);
217217

@@ -221,6 +221,10 @@ RTC_C_EXPORT int rtcGetRemoteDescription(int pc, char *buffer, int size);
221221
RTC_C_EXPORT int rtcGetLocalDescriptionType(int pc, char *buffer, int size);
222222
RTC_C_EXPORT int rtcGetRemoteDescriptionType(int pc, char *buffer, int size);
223223

224+
// For specific use cases only
225+
RTC_C_EXPORT int rtcCreateOffer(int pc, char *buffer, int size);
226+
RTC_C_EXPORT int rtcCreateAnswer(int pc, char *buffer, int size);
227+
224228
RTC_C_EXPORT int rtcGetLocalAddress(int pc, char *buffer, int size);
225229
RTC_C_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);
226230

include/rtc/version.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define RTC_VERSION_MAJOR 0
55
#define RTC_VERSION_MINOR 22
6-
#define RTC_VERSION_PATCH 3
7-
#define RTC_VERSION "0.22.3"
6+
#define RTC_VERSION_PATCH 4
7+
#define RTC_VERSION "0.22.4"
88

99
#endif

pages/content/pages/reference.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ Initiates the handshake process. Following this call, the local description call
210210
Arguments:
211211

212212
- `pc`: the Peer Connection identifier
213-
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
213+
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for automatic (recommended).
214+
215+
Warning: This function expects the optional type for the local description and not an SDP description. It is not possible to set an existing SDP description.
214216

215217
#### rtcSetRemoteDescription
216218

@@ -223,7 +225,8 @@ Sets the remote description received from the remote peer by the user's method o
223225
Arguments:
224226

225227
- `pc`: the Peer Connection identifier
226-
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for autodetection.
228+
- `sdp`: the remote description in SDP format
229+
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for automatic (not recommended).
227230

228231
If the remote description is an offer and `disableAutoNegotiation` was not set in `rtcConfiguration`, the library will automatically answer by calling `rtcSetLocalDescription` internally. Otherwise, the user must call it to answer the remote description.
229232

@@ -299,7 +302,7 @@ Return value: the length of the string copied in buffer (including the terminati
299302

300303
If `buffer` is `NULL`, the description is not copied but the size is still returned.
301304

302-
#### rtcGetRemoteDescription
305+
#### rtcGetRemoteDescriptionType
303306

304307
```
305308
int rtcGetRemoteDescriptionType(int pc, char *buffer, int size)
@@ -317,6 +320,22 @@ Return value: the length of the string copied in buffer (including the terminati
317320

318321
If `buffer` is `NULL`, the description is not copied but the size is still returned.
319322

323+
#### rtcCreateOffer/rtcCreateAnswer
324+
325+
```
326+
int rtcCreateOffer(int pc, char *buffer, int size)
327+
int rtcCreateAnswer(int pc, char *buffer, int size)
328+
```
329+
330+
Create a local offer or answer description in SDP format. These functions are intended only for specific use cases where the application needs to generate a description without setting it. It is useless to call them before `rtcSetLocalDescription` as it doesn't expect the user to supply a description.
331+
332+
- `pc`: the Peer Connection identifier
333+
- `buffer`: a user-supplied buffer to store the description
334+
- `size`: the size of `buffer`
335+
336+
Return value: the length of the string copied in buffer (including the terminating null character) or a negative error code
337+
338+
If `buffer` is `NULL`, the description is not copied but the size is still returned.
320339

321340
#### rtcGetLocalAddress
322341

src/capi.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,24 @@ int rtcGetRemoteDescriptionType(int pc, char *buffer, int size) {
631631
});
632632
}
633633

634+
int rtcCreateOffer(int pc, char *buffer, int size) {
635+
return wrap([&] {
636+
auto peerConnection = getPeerConnection(pc);
637+
638+
auto desc = peerConnection->createOffer();
639+
return copyAndReturn(string(desc), buffer, size);
640+
});
641+
}
642+
643+
int rtcCreateAnswer(int pc, char *buffer, int size) {
644+
return wrap([&] {
645+
auto peerConnection = getPeerConnection(pc);
646+
647+
auto desc = peerConnection->createAnswer();
648+
return copyAndReturn(string(desc), buffer, size);
649+
});
650+
}
651+
634652
int rtcGetLocalAddress(int pc, char *buffer, int size) {
635653
return wrap([&] {
636654
auto peerConnection = getPeerConnection(pc);

src/description.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ void Description::hintType(Type type) {
216216
mType = type;
217217
}
218218

219+
void Description::addIceOption(string option) {
220+
if (std::find(mIceOptions.begin(), mIceOptions.end(), option) == mIceOptions.end())
221+
mIceOptions.emplace_back(std::move(option));
222+
}
223+
224+
void Description::removeIceOption(const string &option) {
225+
mIceOptions.erase(std::remove(mIceOptions.begin(), mIceOptions.end(), option),
226+
mIceOptions.end());
227+
}
228+
229+
void Description::setIceAttribute(string ufrag, string pwd) {
230+
mIceUfrag = std::move(ufrag);
231+
mIcePwd = std::move(pwd);
232+
}
233+
219234
void Description::setFingerprint(CertificateFingerprint f) {
220235
if (!f.isValid())
221236
throw std::invalid_argument("Invalid " +
@@ -227,16 +242,6 @@ void Description::setFingerprint(CertificateFingerprint f) {
227242
mFingerprint = std::move(f);
228243
}
229244

230-
void Description::addIceOption(string option) {
231-
if (std::find(mIceOptions.begin(), mIceOptions.end(), option) == mIceOptions.end())
232-
mIceOptions.emplace_back(std::move(option));
233-
}
234-
235-
void Description::removeIceOption(const string &option) {
236-
mIceOptions.erase(std::remove(mIceOptions.begin(), mIceOptions.end(), option),
237-
mIceOptions.end());
238-
}
239-
240245
std::vector<string> Description::Entry::attributes() const { return mAttributes; }
241246

242247
void Description::Entry::addAttribute(string attr) {

0 commit comments

Comments
 (0)