mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 20:22:27 +02:00
Fix data channel ID
This commit is contained in:
parent
6c37628468
commit
e6c49cf407
2 changed files with 20 additions and 8 deletions
|
@ -129,7 +129,7 @@ WDCConnection::WDCConnection(quint16 webSocketID, WebRTCDataChannels* parent) :
|
|||
_parent(parent)
|
||||
{
|
||||
#ifdef WEBRTC_DEBUG
|
||||
qCDebug(networking_webrtc) << "WebRTCDataChannels::WebRTCDataChannels()";
|
||||
qCDebug(networking_webrtc) << "WDCConnection::WDCConnection() :" << webSocketID;
|
||||
#endif
|
||||
|
||||
// Create observers.
|
||||
|
@ -267,7 +267,7 @@ void WDCConnection::onDataChannelOpened(rtc::scoped_refptr<DataChannelInterface>
|
|||
#endif
|
||||
|
||||
_dataChannel = dataChannel;
|
||||
_dataChannelID = dataChannel->id();
|
||||
_dataChannelID = _parent->getNewDataChannelID(); // Not dataChannel->id() because it's only unique per peer connection.
|
||||
_dataChannel->RegisterObserver(_dataChannelObserver.get());
|
||||
|
||||
_parent->onDataChannelOpened(this, _dataChannelID);
|
||||
|
@ -346,7 +346,7 @@ WebRTCDataChannels::WebRTCDataChannels(NodeType_t nodeType, QObject* parent) :
|
|||
}
|
||||
|
||||
WebRTCDataChannels::~WebRTCDataChannels() {
|
||||
QHashIterator<int, WDCConnection*> i(_connectionsByDataChannel);
|
||||
QHashIterator<quint16, WDCConnection*> i(_connectionsByDataChannel);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
delete i.value();
|
||||
|
@ -363,14 +363,20 @@ WebRTCDataChannels::~WebRTCDataChannels() {
|
|||
_rtcNetworkThread = nullptr;
|
||||
}
|
||||
|
||||
void WebRTCDataChannels::onDataChannelOpened(WDCConnection* connection, int dataChannelID) {
|
||||
quint16 WebRTCDataChannels::getNewDataChannelID() {
|
||||
static const int QUINT16_LIMIT = std::numeric_limits<uint16_t>::max() + 1;
|
||||
_lastDataChannelID = std::max((_lastDataChannelID + 1) % QUINT16_LIMIT, 1);
|
||||
return _lastDataChannelID;
|
||||
}
|
||||
|
||||
void WebRTCDataChannels::onDataChannelOpened(WDCConnection* connection, quint16 dataChannelID) {
|
||||
#ifdef WEBRTC_DEBUG
|
||||
qCDebug(networking_webrtc) << "WebRTCDataChannels::onDataChannelOpened() :" << dataChannelID;
|
||||
#endif
|
||||
_connectionsByDataChannel.insert(dataChannelID, connection);
|
||||
}
|
||||
|
||||
void WebRTCDataChannels::onDataChannelClosed(WDCConnection* connection, int dataChannelID) {
|
||||
void WebRTCDataChannels::onDataChannelClosed(WDCConnection* connection, quint16 dataChannelID) {
|
||||
#ifdef WEBRTC_DEBUG
|
||||
qCDebug(networking_webrtc) << "WebRTCDataChannels::onDataChannelClosed() :" << dataChannelID;
|
||||
#endif
|
||||
|
|
|
@ -206,15 +206,19 @@ public:
|
|||
return _nodeType;
|
||||
}
|
||||
|
||||
/// @brief Get a new data channel ID to uniquely identify a WDCConnection.
|
||||
/// @return A new data channel ID.
|
||||
quint16 getNewDataChannelID();
|
||||
|
||||
/// @brief Handles a WebRTC data channel opening.
|
||||
/// @param connection The WebRTC data channel connection.
|
||||
/// @param dataChannelID The WebRTC data channel ID.
|
||||
void onDataChannelOpened(WDCConnection* connection, int dataChannelID);
|
||||
void onDataChannelOpened(WDCConnection* connection, quint16 dataChannelID);
|
||||
|
||||
/// @brief Handles a WebRTC data channel closing.
|
||||
/// @param connection The WebRTC data channel connection.
|
||||
/// @param dataChannelID The WebRTC data channel ID.
|
||||
void onDataChannelClosed(WDCConnection* connection, int dataChannelID);
|
||||
void onDataChannelClosed(WDCConnection* connection, quint16 dataChannelID);
|
||||
|
||||
/// @brief Emits a signalingMessage received for the Interface client.
|
||||
/// @param message The WebRTC signaling message to send.
|
||||
|
@ -268,8 +272,10 @@ private:
|
|||
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> _peerConnectionFactory { nullptr };
|
||||
|
||||
quint16 _lastDataChannelID { 0 };
|
||||
|
||||
QHash<quint16, WDCConnection*> _connectionsByWebSocket;
|
||||
QHash<int, WDCConnection*> _connectionsByDataChannel;
|
||||
QHash<quint16, WDCConnection*> _connectionsByDataChannel;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue