Enable Video Call (iOS)

Last updated: 2021-09-02 12:16:58

    TUIKit 4.8.50 and later versions provide audio/video call features and support interconnection between iOS and Android platforms. It should be noted that the integration method varies depending on the version:
    TUIKit versions 4.8.50 to 5.1.60 are integrated with the TRTC UI components and TRTC audio/video library by default. And therefore they support audio/video call related features by default.
    TUIKit versions 5.4.666 and later are not integrated with the TRTC UI components and TRTC audio/video library by default. The related audio/video logic is moved to the TUIKitLive component. If you need to use the audio/video call feature, integrate TUIKitLive by referring to Step 2.

    Step 1: Activate the TRTC Service

    1. Log in to the IM console and click the target app card to go to the basic configuration page of the app.
    2. Click Activate under Activate Tencent Real-Time Communication (TRTC).
    3. Click Confirm in the pop-up dialog box.
      A TRTC app with the same SDKAppID as the IM app will be created in the TRTC console. You can use the same account and authentication information for IM and TRTC.

    Step 2: Integrate TUIKitLive

    1. Add the following content to the podfile file.

      // You need to integrate TUIKit_live separately only for TUIKit 5.4.666 or later versions.
      pod 'TXIMSDK_TUIKit_live_iOS'                // By default, the audio and video library of the TXLiteAVSDK_TRTC version is integrated.
      // pod 'TXIMSDK_TUIKit_live_iOS_Professional' // By default, the audio and video library of the TXLiteAVSDK_Professional version is integrated.
      

      Do not integrate different Tencent Cloud audio and video libraries at the same time to avoid symbol conflicts. If you use a library not of the TRTC version, we recommend that you remove it and integrate the TXIMSDK_TUIKit_iOS_Professional version. The audio and video library of the LiteAV_Professional version contains all basic audio and video capabilities.

    2. Run the following command to download the third-party library to the current project:

      pod install
      

      If you cannot install the latest TUIKit version, run the following command to update the local CocoaPods repository list:

      pod repo update
      

    Step 3: Initialize TUIKit

    To initialize TUIKit, enter the SDKAppID generated in Step 1.

    [[TUIKit sharedInstance] setupWithAppId:SDKAppID];
    

    Step 4: Log In to TUIKit

    Call the login API provided by TUIKit to log in to IM. For more information on how to generate UserSig, see How to Generate Usersig.

    [[TUIKit sharedInstance] login:@"userID" userSig:@"userSig" succ:^{
        NSLog(@"-----> login succeeds");
    } fail:^(int code, NSString *msg) {
        NSLog(@"-----> login fails");
    }];
    

    Step 5: Enable/Disable Audio/Video Call

    In TUIKitLive, audio/video call is enabled by default. If you do not need audio/video call, use the enableVideoCall and enableAudioCall attributes in TUIKitLive.h to disable it. The code is as follows:

    // Values of `enableVideoCall`: YES (enable); NO (disabled). Default value: Yes
    [TUIKitLive shareInstance].enableVideoCall = YES;
    // Values of `enableAudioCall`: YES (enable); NO (disabled). Default value: Yes
    [TUIKitLive shareInstance].enableAudioCall = YES;
    

    Step 6: Initiate an Audio/Video call

    When you tap Video or Voice on the chat UI, TUIKit automatically displays the call invitation UI and sends a call request to the peer.

    Step 7: Answer an Audio/Video call

    • When an online user receives a call invitation, TUIKit automatically displays the call receiving UI, where the user can answer or reject the call.
    • When an offline user receives a call invitation, offline push is required if the app call UI needs to be woken up. For more information about offline push, see Step 8.

    Step 8: Offline Push

    To implement offline push for audio/video calls, follow these steps:

    1. Configure offline push for the app. For more information, see Offline Push Configuration.
    2. Upgrade TUIKit to 4.9.1 or later.
    3. Use TUIKit to initiate a call invitation. An offline push message will be generated by default. For more information about the message generation logic, see the sendAPNsForCall function in the TUICall+Signal.m class.
    4. After the peer receives the offline push message, the peer can call the didReceiveRemoteNotification callback in the AppDelegate source code to wake up the call UI.

    FAQs

    1. What should I be aware of if I have created the TRTC and IM SDKAppIDs and want to integrate the IM SDK and TRTC SDK at the same time?

    If you have created the TRTC and IM SDKAppIDs, you cannot use the same account or authentication information for these two apps. You need to generate a UserSig corresponding to the TRTC SDKAppID to perform authentication. For more information on how to generate UserSig, see How to Generate Usersig.

    After obtaining the TRTC SDKAppID and UserSig, modify the following code in the TUICall+TRTC.m source code:

    - (void)enterRoom {
     TRTCParams *param = [[TRTCParams alloc] init];
     // TRTC SDKAppID
     param.sdkAppId = 1000000000 
     // UserSig generated based on the TRTC SDKAppID
     param.userSig = "userSig"
    }
    

    2. How long is the default call invitation timeout duration? How can I modify the default timeout duration?

    The default call invitation timeout duration is 30s. You can modify the SIGNALING_EXTRA_KEY_TIME_OUT field in TUICallModel.m to customize the timeout duration.

    3. Will an invitee receive a call invitation if the invitee goes offline and then online within the call invitation timeout duration?

    • If the call invitation is initiated in a one-to-one chat, the invitee can receive the call invitation.
    • If the call invitation is initiated in a group chat, the invitee cannot receive the call invitation.

    4. What can I do if TUIkitLive conflicts with the integrated audio and video library?

    Do not integrate different Tencent Cloud audio and video libraries at the same time to avoid symbol conflicts. If you use a library not of the TRTC version, we recommend that you remove it and integrate the TXIMSDK_TUIKit_iOS_Professional version. The audio and video library of the LiteAV_Professional version contains all basic audio and video capabilities.
    The audio and video library of the LiteAV_Enterprise version cannot coexist with TUIkitLive.