DEV Community

Cover image for Fixing Common Issues in Zego Call Kit for React Native Developers πŸ’»πŸš€
Muhammad haris baig
Muhammad haris baig

Posted on

Fixing Common Issues in Zego Call Kit for React Native Developers πŸ’»πŸš€

Introduction πŸ› οΈ
If you're a React Native developer working with Zego Call Kit, you've likely encountered frustrating issues with no straightforward solutions available online. I faced two major problems while integrating @zegocloud/zego-uikit-prebuilt-call-rn and zego-callkit-react-native, and after much debugging, I found effective fixes that will save you a lot of time.

In this article, I'll walk you through these issues, their causes, and the solutions I implemented to resolve them using a patching technique. Hopefully, this will save you time and effort! ⏳

Issue #1: ZegoUIKit.kitLogInfo error apply of undefined ⚠️
Problem ❌
This issue originated from the @zegocloud/zego-uikit-prebuilt-call-rn library. When running my Android app, it would crash due to an undefined method kitLogInfo, while on iOS, it would just show a warning.

Root Cause πŸ§
The kitLogInfo function was expected to be present in ZegoUIKitLogger, but it was missing in some versions of the library, leading to runtime errors.

Solution βœ…
I resolved this by modifying the logging mechanism using a patch. The original problematic code looked like this:

import {ZegoUIKitLogger} from '@zegocloud/zego-uikit-rn';
const module = 'PrebuiltCall'
export const zloginfo = (...msg) => {
  ZegoUIKitLogger.logInfo(module, ...msg);
};
export const zlogwarning = (...msg) => {
  ZegoUIKitLogger.logWarning(module, ...msg);
};
export const zlogerror = (...msg) => {
  ZegoUIKitLogger.logError(module, ...msg);
};
Enter fullscreen mode Exit fullscreen mode

I changed it to:


"use strict";
import { Platform } from "react-native";
import _zegoUikitRn from "@zegocloud/zego-uikit-rn";
const zloginfo = (...msg) => {
  if (_zegoUikitRn.default.kitLogInfo) {
    _zegoUikitRn.default.kitLogInfo('PrebuiltCall', ...msg);
  } else {
    console.warn(`kitLogInfo is not defined in ZegoUIKit in ${Platform.OS}`);
  }
};
export { zloginfo };

Enter fullscreen mode Exit fullscreen mode

This ensures that if kitLogInfo is undefined, it falls back to a console warning instead of causing a crash. πŸ› οΈ

Issue #2: TypeError: Cannot read property 'prefix' of null, js engine: hermes πŸž
Problem ❌
This issue was coming from the zego-callkit-react-native library. On iOS, it threw a warning, but on Android, the app crashed abruptly.

Root Cause πŸ§
The problem was in the following line:

const Prefix = ZegoCallKitNativeModule.prefix;

Enter fullscreen mode Exit fullscreen mode

When using Hermes, ZegoCallKitNativeModule was sometimes null, causing an error when trying to access prefix.

Solution βœ…
I fixed it by modifying this line to:

import { Platform } from 'react-native';
const Prefix = Platform.OS == 'ios' ? ZegoCallKitNativeModule.prefix : '';
Enter fullscreen mode Exit fullscreen mode

This ensures that on Android, the app does not crash due to a null reference. πŸ› οΈ

Applying Patches for These Fixes πŸ©Ή
To ensure these changes persist across updates, I used the patch-package tool. Here's how I applied and committed these patches:

Step 1: Install patch-package πŸ“¦
yarn add patch-package postinstall-postinstall

Step 2: Make the Changes and Save the Patch πŸ“
npx patch-package @zegocloud/zego-uikit-prebuilt-call-rn
npx patch-package zego-callkit-react-native

Step 3: Ensure Patch is Applied Automatically πŸ”„
Add this script to package.json:
"scripts": {
"postinstall": "patch-package"
}

Now, whenever a developer runs yarn install, the patches will be applied automatically. πŸ› οΈ

Step 4: Push Patches to GitHub πŸš€
I committed the patches so that other developers on my team could use them:

git add patches/
git commit -m "Fix Zego issues with patch-package"
git push origin main

Contributing to Open Source πŸ€

I also created pull requests (PRs) to contribute these fixes upstream. If merged, we won't need the patches anymore. Here's my PR for @zegocloud/zego-uikit-prebuilt-call-rn:
πŸ”— PR #14β€Š-β€ŠFix kitLogInfo Issue
Unfortunately, I couldn't find zego-callkit-react-native on GitHub, so I had to rely on patching for that one. πŸ˜•

Conclusion 🎯
``
If you're working with Zego Call Kit and facing these frustrating issues, I hope this guide helps you save time. Let me know if you encounter any other problemsβ€Š-β€Šlet's work together to improve these libraries! πŸš€
Feel free to share your thoughts in the comments or contribute to the PR to get these fixes merged! πŸ”₯

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more