logo
On this page

Calculate call duration

This doc describes how to calculate the call duration through configuration.

To calculate call duration, do the following:

  1. Set the showCallDuration property of ZegoUIKitPrebuiltCallConfig to display the current call timer (It is displayed by default).

  2. Assuming that the call duration is 5 minutes, the call will automatically end when the time is up (refer to the following code). You will be notified of the end of the call duration through onCallTimeUpdate. To end the call, you can call the finish method of your ZegoUIKitPrebuiltCallVC (Basic call) or the endCall method of ZegoUIKitPrebuiltCallInvitationService(Call with invitation).

Basic call
With call invitation
let appID: UInt32 = yourAppID
let appSign: String = yourAppSign

var userID: String = yourUserID
var userName: String = yourUserName

let config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall()
config.showCallDuration = true

let callVC = ZegoUIKitPrebuiltCallVC.init(appID, appSign: appSign, userID: userID, userName: userName, callID: "100", config: config)
callVC.delegate = self

// call duration call back
func onCallTimeUpdate(_ duration: Int) {
    print("onCallTimeUpdate\(duration)")
}
1
Copied!

// ...
ZegoUIKitPrebuiltCallInvitationService.shared.delegate = self


// ...
extension CallInvitationVC: ZegoUIKitPrebuiltCallInvitationServiceDelegate {
    //MARK: -ZegoUIKitPrebuiltCallInvitationServiceDelegate
    func requireConfig(_ data: ZegoCallInvitationData) -> ZegoUIKitPrebuiltCallConfig {

        // ...
        config.showCallDuration = true
        return config
    }

    // call duration call back
    func onCallTimeUpdate(_ duration: Int) {
      print("onCallTimeUpdate\(duration)")
    }
}
1
Copied!

On this page

Back to top