Skip to content

Commit 7edaf96

Browse files
Add rtcCreateOffer() and rtcCreateAnswer()
1 parent 00ffc07 commit 7edaf96

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

DOC.md

+4-2
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,7 @@ 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+
- `type` (optional): type of the description ("offer", "answer", "pranswer", or "rollback") or NULL for automatic (not recommended).
224226

225227
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.
226228

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

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);

0 commit comments

Comments
 (0)