Starter Deal! First 3 month from only  $9.9 /month!
Starter Deal! First 3 month from only  $9.9 /month!
Grab It Now 
Tencent RTC Blog
Tencent RTC Blog
Tutorial

How to Add Call Status Observer in Your iOS App

Tencent RTC - Dev Team

How to Add Call Status Observer in Your iOS App.png

In your audio and video calling application on the iOS platform, you may need to use callback functions to obtain the user's call status and make timely responses. For example, when you know that the current call is a group call, you may need to allocate more resources to reduce latency and ensure a better calling experience for users. Tencent RTC Call (TUICallKit) provides developers with a rich set of callback functions to meet various business requirements.

For more information, please refer to our technical documentation, which includes the API documentation for TUICallObserver. It provides detailed information about the parameters and more. Feel free to explore it.

Now, let's take the callbacks "onCallReceived", "onCallBegin", and "onCallEnd" as examples to guide you on how to invoke callback functions in your iOS project.

Video Tutorial

How to Use TUICallObserver in Your iOS Calling App?

Note: If you haven't set up your own iOS audio and video calling application yet, please refer to this tutorial blog: "How to Build A Video Calling App on iOS" and follow the steps to enter the TRTC console for creating your Call application.

Step 1: Import the TUICallEngine component and add the TUICallObserver protocol.

To begin, navigate to your iOS project and import the TUICallEngine component. Then, add the TUICallObserver protocol at the appropriate location, as shown in the following image:

import the TUICallEngine component & add the TUICallObserver protocol.png

Next, register the callback events in the TUILogin function. Here, you will need to use TUICallEngine and add the callbacks:

import TUICallEngine

TUICallEngine.createInstance().add(self)

public func onCallBegin(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole) {
}
public func onCallEnd(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole, totalTime: Float) {
}
public func onUserNetworkQualityChanged(networkQualityList: [TUINetworkQualityInfo]) {
}

using TUICallEngine and adding the callbacks.png

  • onCallReceived: called when we receive an incoming call.
  • onCallBegin: called when we start a call.
  • onCallEnd: called when we end a call.

Step 2: Print callback information in the callback functions.

Now, let's print these callback information to the console.

When we receive an incoming call, we can obtain some parameters in "onCallReceived":

  • callerId: the user ID of the inviter.
  • calleeIdList: the invitee list.
  • groupId: the group ID.
  • callMediaType: the call type, which can be video or audio.
  • userData: user-added extended fields.

When a call starts, we also receive callback information in "onCallBegin":

  • roomId: the room ID.
  • callMediaType: the call type, which can be video or audio.
  • callRole: the role, which can be caller or callee.

Similarly, when a call is hung up, we can also receive callback information in "onCallEnd":

  • roomId: the room ID.
  • callMediaType: the call type, which can be video or audio.
  • callRole: the role, which can be caller or callee.
  • totalTime: the call duration.

print callback information to the console.png

Testing

At this point, we have successfully registered the callbacks. Now, we can run our demo and test:

  • Click on <Login>.
  • Once successful, initiate a call to it.
  • Check the console to view the printed information from the callback functions.

log in.png

You can see that the console has received the callback from "onCallReceived":

  • The callerId is 8558.
  • The calleeIdList concludes 1234.
  • The groupId is empty because there is only one called user.
  • The callMediaType is audio call.

call the "onCallReceived".png

Now, when we answer the call, we can also receive callback information from "onCallBegin" in the console:

call the "onCallBegin".png

When we hang up the call at this point, we receive callback information from "onCallEnd" in the console:

call the "onCallEnd".png

Conclusion

The usage of other callbacks is similar. Additionally, if you wish to invoke other callbacks, you can refer to the official documentation. In the API documentation, specifically the TUICallObserver documentation page, you can find information on which callbacks are supported. Use these callbacks to accomplish more complex and diverse business functionalities.

other callbacks of TUICallObserver.png

If you need more details or resources, please visit our official website: Tencent RTC or GitHub and explore freely.

If you have any questions or need help, our support team is always ready to help. Please feel free to contact us, or join us in Discord.

Set Up
Call
Build App
iOS development