Browse Source

Pass user pointer to data channel

Paul-Louis Ageneau 5 years ago
parent
commit
56198372fd
1 changed files with 9 additions and 4 deletions
  1. 9 4
      src/rtc.cpp

+ 9 - 4
src/rtc.cpp

@@ -108,9 +108,9 @@ void rtcSetUserPointer(int i, void *ptr) {
 
 int rtcCreatePeerConnection(const char **iceServers, int iceServersCount) {
 	Configuration config;
-	for (int i = 0; i < iceServersCount; ++i) {
+	for (int i = 0; i < iceServersCount; ++i)
 		config.iceServers.emplace_back(IceServer(string(iceServers[i])));
-	}
+
 	return emplacePeerConnection(std::make_shared<PeerConnection>(config));
 }
 
@@ -121,7 +121,10 @@ int rtcCreateDataChannel(int pc, const char *label) {
 	if (!peerConnection)
 		return -1;
 
-	return emplaceDataChannel(peerConnection->createDataChannel(string(label)));
+	int dc = emplaceDataChannel(peerConnection->createDataChannel(string(label)));
+	void *ptr = getUserPointer(pc);
+	rtcSetUserPointer(dc, ptr);
+	return dc;
 }
 
 int rtcDeleteDataChannel(int dc) { return eraseDataChannel(dc) ? 0 : -1; }
@@ -133,7 +136,9 @@ int rtcSetDataChannelCallback(int pc, dataChannelCallbackFunc cb) {
 
 	peerConnection->onDataChannel([pc, cb](std::shared_ptr<DataChannel> dataChannel) {
 		int dc = emplaceDataChannel(dataChannel);
-		cb(dc, getUserPointer(pc));
+		void *ptr = getUserPointer(pc);
+		rtcSetUserPointer(dc, ptr);
+		cb(dc, ptr);
 	});
 	return 0;
 }