Browse Source

Add id as a parameter to C API callbacks.

Hanseul Jun 5 years ago
parent
commit
c38edd089b
2 changed files with 25 additions and 25 deletions
  1. 12 12
      include/rtc/rtc.h
  2. 13 13
      src/capi.cpp

+ 12 - 12
include/rtc/rtc.h

@@ -88,18 +88,18 @@ typedef struct {
 } rtcReliability;
 
 typedef void (RTC_API *rtcLogCallbackFunc)(rtcLogLevel level, const char *message);
-typedef void (RTC_API *rtcDescriptionCallbackFunc)(const char *sdp, const char *type, void *ptr);
-typedef void (RTC_API *rtcCandidateCallbackFunc)(const char *cand, const char *mid, void *ptr);
-typedef void (RTC_API *rtcStateChangeCallbackFunc)(rtcState state, void *ptr);
-typedef void (RTC_API *rtcGatheringStateCallbackFunc)(rtcGatheringState state, void *ptr);
-typedef void (RTC_API *rtcDataChannelCallbackFunc)(int dc, void *ptr);
-typedef void (RTC_API *rtcTrackCallbackFunc)(int tr, void *ptr);
-typedef void (RTC_API *rtcOpenCallbackFunc)(void *ptr);
-typedef void (RTC_API *rtcClosedCallbackFunc)(void *ptr);
-typedef void (RTC_API *rtcErrorCallbackFunc)(const char *error, void *ptr);
-typedef void (RTC_API *rtcMessageCallbackFunc)(const char *message, int size, void *ptr);
-typedef void (RTC_API *rtcBufferedAmountLowCallbackFunc)(void *ptr);
-typedef void (RTC_API *rtcAvailableCallbackFunc)(void *ptr);
+typedef void (RTC_API *rtcDescriptionCallbackFunc)(int pc, const char *sdp, const char *type, void *ptr);
+typedef void (RTC_API *rtcCandidateCallbackFunc)(int pc, const char *cand, const char *mid, void *ptr);
+typedef void (RTC_API *rtcStateChangeCallbackFunc)(int pc, rtcState state, void *ptr);
+typedef void (RTC_API *rtcGatheringStateCallbackFunc)(int pc, rtcGatheringState state, void *ptr);
+typedef void (RTC_API *rtcDataChannelCallbackFunc)(int pc, int dc, void *ptr);
+typedef void (RTC_API *rtcTrackCallbackFunc)(int pc, int tr, void *ptr);
+typedef void (RTC_API *rtcOpenCallbackFunc)(int id, void *ptr);
+typedef void (RTC_API *rtcClosedCallbackFunc)(int id, void *ptr);
+typedef void (RTC_API *rtcErrorCallbackFunc)(int id, const char *error, void *ptr);
+typedef void (RTC_API *rtcMessageCallbackFunc)(int id, const char *message, int size, void *ptr);
+typedef void (RTC_API *rtcBufferedAmountLowCallbackFunc)(int id, void *ptr);
+typedef void (RTC_API *rtcAvailableCallbackFunc)(int id, void *ptr);
 
 // Log
 // NULL cb on the first call will log to stdout

+ 13 - 13
src/capi.cpp

@@ -422,7 +422,7 @@ int rtcSetLocalDescriptionCallback(int pc, rtcDescriptionCallbackFunc cb) {
 		if (cb)
 			peerConnection->onLocalDescription([pc, cb](Description desc) {
 				if (auto ptr = getUserPointer(pc))
-					cb(string(desc).c_str(), desc.typeString().c_str(), *ptr);
+					cb(pc, string(desc).c_str(), desc.typeString().c_str(), *ptr);
 			});
 		else
 			peerConnection->onLocalDescription(nullptr);
@@ -435,7 +435,7 @@ int rtcSetLocalCandidateCallback(int pc, rtcCandidateCallbackFunc cb) {
 		if (cb)
 			peerConnection->onLocalCandidate([pc, cb](Candidate cand) {
 				if (auto ptr = getUserPointer(pc))
-					cb(cand.candidate().c_str(), cand.mid().c_str(), *ptr);
+					cb(pc, cand.candidate().c_str(), cand.mid().c_str(), *ptr);
 			});
 		else
 			peerConnection->onLocalCandidate(nullptr);
@@ -448,7 +448,7 @@ int rtcSetStateChangeCallback(int pc, rtcStateChangeCallbackFunc cb) {
 		if (cb)
 			peerConnection->onStateChange([pc, cb](PeerConnection::State state) {
 				if (auto ptr = getUserPointer(pc))
-					cb(static_cast<rtcState>(state), *ptr);
+					cb(pc, static_cast<rtcState>(state), *ptr);
 			});
 		else
 			peerConnection->onStateChange(nullptr);
@@ -461,7 +461,7 @@ int rtcSetGatheringStateChangeCallback(int pc, rtcGatheringStateCallbackFunc cb)
 		if (cb)
 			peerConnection->onGatheringStateChange([pc, cb](PeerConnection::GatheringState state) {
 				if (auto ptr = getUserPointer(pc))
-					cb(static_cast<rtcGatheringState>(state), *ptr);
+					cb(pc, static_cast<rtcGatheringState>(state), *ptr);
 			});
 		else
 			peerConnection->onGatheringStateChange(nullptr);
@@ -476,7 +476,7 @@ int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb) {
 				int dc = emplaceDataChannel(dataChannel);
 				if (auto ptr = getUserPointer(pc)) {
 					rtcSetUserPointer(dc, *ptr);
-					cb(dc, *ptr);
+					cb(pc, dc, *ptr);
 				}
 			});
 		else
@@ -492,7 +492,7 @@ int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb) {
 				int tr = emplaceTrack(track);
 				if (auto ptr = getUserPointer(pc)) {
 					rtcSetUserPointer(tr, *ptr);
-					cb(tr, *ptr);
+					cb(pc, tr, *ptr);
 				}
 			});
 		else
@@ -686,7 +686,7 @@ int rtcSetOpenCallback(int id, rtcOpenCallbackFunc cb) {
 		if (cb)
 			channel->onOpen([id, cb]() {
 				if (auto ptr = getUserPointer(id))
-					cb(*ptr);
+					cb(id, *ptr);
 			});
 		else
 			channel->onOpen(nullptr);
@@ -699,7 +699,7 @@ int rtcSetClosedCallback(int id, rtcClosedCallbackFunc cb) {
 		if (cb)
 			channel->onClosed([id, cb]() {
 				if (auto ptr = getUserPointer(id))
-					cb(*ptr);
+					cb(id, *ptr);
 			});
 		else
 			channel->onClosed(nullptr);
@@ -712,7 +712,7 @@ int rtcSetErrorCallback(int id, rtcErrorCallbackFunc cb) {
 		if (cb)
 			channel->onError([id, cb](string error) {
 				if (auto ptr = getUserPointer(id))
-					cb(error.c_str(), *ptr);
+					cb(id, error.c_str(), *ptr);
 			});
 		else
 			channel->onError(nullptr);
@@ -726,11 +726,11 @@ int rtcSetMessageCallback(int id, rtcMessageCallbackFunc cb) {
 			channel->onMessage(
 			    [id, cb](binary b) {
 				    if (auto ptr = getUserPointer(id))
-					    cb(reinterpret_cast<const char *>(b.data()), int(b.size()), *ptr);
+					    cb(id, reinterpret_cast<const char *>(b.data()), int(b.size()), *ptr);
 			    },
 			    [id, cb](string s) {
 				    if (auto ptr = getUserPointer(id))
-					    cb(s.c_str(), -int(s.size() + 1), *ptr);
+					    cb(id, s.c_str(), -int(s.size() + 1), *ptr);
 			    });
 		else
 			channel->onMessage(nullptr);
@@ -777,7 +777,7 @@ int rtcSetBufferedAmountLowCallback(int id, rtcBufferedAmountLowCallbackFunc cb)
 		if (cb)
 			channel->onBufferedAmountLow([id, cb]() {
 				if (auto ptr = getUserPointer(id))
-					cb(*ptr);
+					cb(id, *ptr);
 			});
 		else
 			channel->onBufferedAmountLow(nullptr);
@@ -794,7 +794,7 @@ int rtcSetAvailableCallback(int id, rtcAvailableCallbackFunc cb) {
 		if (cb)
 			channel->onOpen([id, cb]() {
 				if (auto ptr = getUserPointer(id))
-					cb(*ptr);
+					cb(id, *ptr);
 			});
 		else
 			channel->onOpen(nullptr);