MrHertal / react-native-twilio-phone

Twilio Voice React Native module.
MIT License
154 stars 67 forks source link

Support for call quality stats #38

Closed JaonL closed 3 years ago

JaonL commented 3 years ago

Hi, we've been using your module to implement VoIP capabilities in our mobile app and it's been working great! I was just wondering about how we might add support for extracting the call quality stats from the native SDKs and exposing them in this module. Twilio supports this pretty easily in their web based javascript library already.

Is this an existing part of your roadmap for this project? If not, we would be happy to develop and contribute this feature from our end as well. Also, if you already have any thoughts on how to go about this, we will be sure to follow any and all guidance on implementing this within the module.

The native modules for Twilio unfortunately don't seem to be open source, but there does seem to be some simple documentation regarding how to fetch this data in their latest SDK for iOS.

In Voice iOS 3.0 SDK you can now access media stats in a Call using the [TVOCall getStatsWithBlock:] method.

call.getStatsWith { (statsReports) in
    for report: TVOStatsReport in statsReports {
        let localAudioTracks: Array<TVOLocalAudioTrackStats> = report.localAudioTrackStats
        let localAudioTrackStats = localAudioTracks[0]
        let remoteAudioTracks: Array<TVORemoteAudioTrackStats> = report.remoteAudioTrackStats
        let remoteAudioTrackStats = remoteAudioTracks[0]

        print("Local Audio Track - audio level: \(localAudioTrackStats.audioLevel), packets sent: \(localAudioTrackStats.packetsSent)")
        print("Remote Audio Track - audio level: \(remoteAudioTrackStats.audioLevel), packets received: \(remoteAudioTrackStats.packetsReceived)")
    }
}

with documentation on what the specific classes look like written here https://twilio.github.io/twilio-voice-ios/docs/latest/Classes/TVOStatsReport.html

Please let us know what your thoughts are, thanks!

MrHertal commented 3 years ago

Hi @JaonL, thanks for sharing this idea.

It would be nice to have this new feature added to the project. If you could submit a PR I would be glad to review it and help you out.

This does not seem difficult using TwilioVoice SDK as you suggested. Maybe a good way to do it would be to copy one of the method that is already using current call such as sendDigits, then call getStats to retrieve the information.

Let me know if you think of a better approach :)

Thanks.

thanhnvpk01168 commented 1 year ago

Hi @MrHertal @JaonL how much is max audioLevel?