@@ -863,24 +863,6 @@ void PeerConnection::processLocalDescription(Description description) {
863
863
864
864
if (description.type () == Description::Type::Offer) {
865
865
// This is an offer, add locally created data channels and tracks
866
- // Add application for data channels
867
- if (!description.hasApplication ()) {
868
- std::shared_lock lock (mDataChannelsMutex );
869
- if (!mDataChannels .empty ()) {
870
- unsigned int m = 0 ;
871
- while (description.hasMid (std::to_string (m)))
872
- ++m;
873
- Description::Application app (std::to_string (m));
874
- app.setSctpPort (localSctpPort);
875
- app.setMaxMessageSize (localMaxMessageSize);
876
-
877
- PLOG_DEBUG << " Adding application to local description, mid=\" " << app.mid ()
878
- << " \" " ;
879
-
880
- description.addMedia (std::move (app));
881
- }
882
- }
883
-
884
866
// Add media for local tracks
885
867
std::shared_lock lock (mTracksMutex );
886
868
for (auto it = mTrackLines .begin (); it != mTrackLines .end (); ++it) {
@@ -901,6 +883,25 @@ void PeerConnection::processLocalDescription(Description description) {
901
883
}
902
884
}
903
885
886
+ // Add application for data channels
887
+ if (!description.hasApplication ()) {
888
+ std::shared_lock lock (mDataChannelsMutex );
889
+ if (!mDataChannels .empty ()) {
890
+ // Prevents mid collision with remote or local tracks
891
+ unsigned int m = 0 ;
892
+ while (description.hasMid (std::to_string (m)))
893
+ ++m;
894
+ Description::Application app (std::to_string (m));
895
+ app.setSctpPort (localSctpPort);
896
+ app.setMaxMessageSize (localMaxMessageSize);
897
+
898
+ PLOG_DEBUG << " Adding application to local description, mid=\" " << app.mid ()
899
+ << " \" " ;
900
+
901
+ description.addMedia (std::move (app));
902
+ }
903
+ }
904
+
904
905
// There might be no media at this point if the user created a Track, deleted it,
905
906
// then called setLocalDescription().
906
907
if (description.mediaCount () == 0 )
0 commit comments