Skip to content

Commit 8702180

Browse files
committed
MSRP: lift leaveNow for talker complement to reduce code duplication
1 parent dae65aa commit 8702180

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Sources/MRP/Applications/MSRP/MSRPApplication.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,14 @@ extension MSRPApplication {
906906
accumulatedLatency += 500 // clause 35.2.2.8.6, 500ns default
907907
}
908908

909+
let complementToRemove: MSRPAttributeType =
910+
declarationType == .talkerAdvertise ? .talkerFailed : .talkerAdvertise
911+
try await participant.leaveNow { attributeType, _, attributeValue in
912+
attributeType == complementToRemove.rawValue &&
913+
(attributeValue as! MSRPStreamIDRepresentable).streamID == talkerValue.streamID
914+
}
915+
909916
if declarationType == .talkerAdvertise {
910-
// Leave any existing talkerFailed before joining talkerAdvertise
911-
try await participant.leaveNow { attributeType, _, attributeValue in
912-
attributeType == MSRPAttributeType.talkerFailed.rawValue &&
913-
(attributeValue as! MSRPStreamIDRepresentable).streamID == talkerValue.streamID
914-
}
915917
do {
916918
try await _canBridgeTalker(
917919
participant: participant,
@@ -970,11 +972,6 @@ extension MSRPApplication {
970972
}
971973
} else {
972974
precondition(declarationType == .talkerFailed)
973-
// Leave any existing talkerAdvertise before joining talkerFailed
974-
try await participant.leaveNow { attributeType, _, attributeValue in
975-
attributeType == MSRPAttributeType.talkerAdvertise.rawValue &&
976-
(attributeValue as! MSRPStreamIDRepresentable).streamID == talkerValue.streamID
977-
}
978975
let talkerFailed = MSRPTalkerFailedValue(
979976
streamID: talkerValue.streamID,
980977
dataFrameParameters: talkerValue.dataFrameParameters,

0 commit comments

Comments
 (0)