OTSubscriberKitNetworkStatsDelegate and OTSubscriberKitRtcStatsReportDelegate Methods are not called unless the subscriber's delegate (OTSubscriberKitDelegate) conforms to the protocol and implements the method. This is fine if the fine if the subscriber's networkStatsDelegate and rtcStatsReportDelegate are the same object as the delegate, but can fail if they are different objects.
A crash can also occur if the delegate does conform to the stats delegate protocols and implements the methods, but the actual networkStatsDelegate and rtcStatsReportDelegate do not implement the methods.
Steps to Reproduce
Make sure the OTSubscriberKitDelegate doens't implement the OTSubscriberKitNetworkStatsDelegate and OTSubscriberKitRtcStatsReportDelegate methods.
Create a separate delegate object that implements the OTSubscriberKitNetworkStatsDelegate and OTSubscriberKitRtcStatsReportDelegate methods.
Observer the stats delegate methods not getting executed.
Notice that implementing the methods in the OTSubscriberKitDelegate will cause the methods in the stats delegate to get executed.
Notice that implementing the methods in the OTSubscriberKitDelegate, but not in the stats delegate will cause the app to crash.
class SubscriberDelegate: NSObject,
OTSubscriberKitDelegate,
OTSubscriberKitNetworkStatsDelegate,
OTSubscriberKitRtcStatsReportDelegate
{
...
// Uncomment theses lines to get the StatsDelegate to work.
// func subscriber(_ subscriber: OTSubscriberKit, videoNetworkStatsUpdated stats: OTSubscriberKitVideoNetworkStats) {}
// func subscriber(_ subscriber: OTSubscriberKit, audioNetworkStatsUpdated stats: OTSubscriberKitAudioNetworkStats) {}
// func subscriber(_ subscriber: OTSubscriberKit, rtcStatsReport jsonArrayOfReports: String) {}
...
}
class StatsDelegate: NSObject,
OTSubscriberKitNetworkStatsDelegate,
OTSubscriberKitRtcStatsReportDelegate
{
// Comment out these methods and uncomment the methods above to observe a crash.
func subscriber(_ subscriber: OTSubscriberKit, videoNetworkStatsUpdated stats: OTSubscriberKitVideoNetworkStats) {
print("subscriber video stats")
}
func subscriber(_ subscriber: OTSubscriberKit, audioNetworkStatsUpdated stats: OTSubscriberKitAudioNetworkStats) {
print("subscriber audio stats")
}
func subscriber(_ subscriber: OTSubscriberKit, rtcStatsReport jsonArrayOfReports: String) {
print("subscriber rtc stats")
}
}
I don't have access to the source code, but I am guessing that the reason this happens is because when deciding whether or not to call the stats delegate methods, there is a guard incorrectly checking to see if the subscriber's delegate conforms to the protocol and implements the method, this should be changed to check the networkStatsDelegate/rtcStatsReportDelegate as appropriate.
Issue
OTSubscriberKitNetworkStatsDelegate and OTSubscriberKitRtcStatsReportDelegate Methods are not called unless the subscriber's
delegate
(OTSubscriberKitDelegate) conforms to the protocol and implements the method. This is fine if the fine if the subscriber'snetworkStatsDelegate
andrtcStatsReportDelegate
are the same object as thedelegate
, but can fail if they are different objects.A crash can also occur if the
delegate
does conform to the stats delegate protocols and implements the methods, but the actualnetworkStatsDelegate
andrtcStatsReportDelegate
do not implement the methods.Steps to Reproduce
OTSubscriberKitDelegate
doens't implement theOTSubscriberKitNetworkStatsDelegate
andOTSubscriberKitRtcStatsReportDelegate
methods.OTSubscriberKitNetworkStatsDelegate
andOTSubscriberKitRtcStatsReportDelegate
methods.OTSubscriberKitDelegate
will cause the methods in the stats delegate to get executed.OTSubscriberKitDelegate
, but not in the stats delegate will cause the app to crash.Solution
I don't have access to the source code, but I am guessing that the reason this happens is because when deciding whether or not to call the stats delegate methods, there is a guard incorrectly checking to see if the subscriber's
delegate
conforms to the protocol and implements the method, this should be changed to check thenetworkStatsDelegate
/rtcStatsReportDelegate
as appropriate.