mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
Added optional stream to emplaceDataChannel()
This commit is contained in:
@ -135,7 +135,8 @@ private:
|
|||||||
void forwardBufferedAmount(uint16_t stream, size_t amount);
|
void forwardBufferedAmount(uint16_t stream, size_t amount);
|
||||||
|
|
||||||
std::shared_ptr<DataChannel> emplaceDataChannel(Description::Role role, string label,
|
std::shared_ptr<DataChannel> emplaceDataChannel(Description::Role role, string label,
|
||||||
string protocol, Reliability reliability);
|
string protocol, Reliability reliability,
|
||||||
|
std::optional<unsigned int> stream = nullopt);
|
||||||
std::shared_ptr<DataChannel> findDataChannel(uint16_t stream);
|
std::shared_ptr<DataChannel> findDataChannel(uint16_t stream);
|
||||||
void iterateDataChannels(std::function<void(std::shared_ptr<DataChannel> channel)> func);
|
void iterateDataChannels(std::function<void(std::shared_ptr<DataChannel> channel)> func);
|
||||||
void openDataChannels();
|
void openDataChannels();
|
||||||
|
@ -735,18 +735,21 @@ void PeerConnection::forwardBufferedAmount(uint16_t stream, size_t amount) {
|
|||||||
|
|
||||||
shared_ptr<DataChannel> PeerConnection::emplaceDataChannel(Description::Role role, string label,
|
shared_ptr<DataChannel> PeerConnection::emplaceDataChannel(Description::Role role, string label,
|
||||||
string protocol,
|
string protocol,
|
||||||
Reliability reliability) {
|
Reliability reliability,
|
||||||
// The active side must use streams with even identifiers, whereas the passive side must use
|
std::optional<unsigned int> stream) {
|
||||||
// streams with odd identifiers.
|
|
||||||
// See https://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-09#section-6
|
|
||||||
std::unique_lock lock(mDataChannelsMutex); // we are going to emplace
|
std::unique_lock lock(mDataChannelsMutex); // we are going to emplace
|
||||||
unsigned int stream = (role == Description::Role::Active) ? 0 : 1;
|
if(!stream) {
|
||||||
while (mDataChannels.find(stream) != mDataChannels.end()) {
|
// The active side must use streams with even identifiers, whereas the passive side must use
|
||||||
stream += 2;
|
// streams with odd identifiers.
|
||||||
if (stream >= 65535)
|
// See https://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-09#section-6
|
||||||
throw std::runtime_error("Too many DataChannels");
|
*stream = (role == Description::Role::Active) ? 0 : 1;
|
||||||
|
while (mDataChannels.find(*stream) != mDataChannels.end()) {
|
||||||
|
*stream += 2;
|
||||||
|
if (*stream >= 65535)
|
||||||
|
throw std::runtime_error("Too many DataChannels");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto channel = std::make_shared<DataChannel>(shared_from_this(), stream, std::move(label),
|
auto channel = std::make_shared<DataChannel>(shared_from_this(), *stream, std::move(label),
|
||||||
std::move(protocol), std::move(reliability));
|
std::move(protocol), std::move(reliability));
|
||||||
mDataChannels.emplace(std::make_pair(stream, channel));
|
mDataChannels.emplace(std::make_pair(stream, channel));
|
||||||
return channel;
|
return channel;
|
||||||
|
Reference in New Issue
Block a user