Using @livekit/react-native I have this error: Typ...
# ask-ai
a
Using @livekit/react-native I have this error: TypeError: window.addEventListener is not a function (it is undefined)
t
Thanks for reaching out, David. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error you're encountering, "TypeError: window.addEventListener is not a function," is likely due to not properly initializing the LiveKit SDK in your React Native application. To resolve this, you need to call the
registerGlobals()
function before using any LiveKit functionality. Here are the steps to fix this: 1. Import the
registerGlobals
function:
import { registerGlobals } from '@livekit/react-native';
2. Call it at the beginning of your application code, before using any LiveKit components:
registerGlobals();
This step is essential as it sets up the required WebRTC libraries for use in JavaScript, which are necessary for LiveKit to function properly in a React Native environment. Sources: LiveKit React Native Client SDK - v2.5.1
a
and what if i already added
t
If you have already added
registerGlobals()
and the error persists, it could be due to another issue in the setup or environment. Unfortunately, I couldn't find specific information about this scenario in the documentation. To assist further, could you provide additional details about your setup? For example: • The version of
@livekit/react-native
you are using. • Any other libraries or dependencies in your project that might interact with WebRTC. • The specific environment (e.g., iOS, Android, or both). With this information, I can investigate further or escalate the issue to a specialist if needed.
a
"@anhnch/react-native-pincode": "^1.3.0", "@eabdullazyanov/react-native-sms-user-consent": "1.2.0", "@ethersproject/shims": "^5.7.0", "@expo/react-native-action-sheet": "^4.0.1", "@flyerhq/react-native-link-preview": "https://github.com/kyunkakata/react-native-link-preview", "@giphy/react-native-sdk": "^3.2.6", "@livekit/react-native": "^2.7.4", "@livekit/react-native-webrtc": "^125.0.9", "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.13.tgz", "@notifee/react-native": "^7.8.2", "@react-native-async-storage/async-storage": "^1.23.1", "@react-native-clipboard/clipboard": "^1.14.1", "@react-native-community/blur": "^4.4.0", "@react-native-community/datetimepicker": "^8.1.1", "@react-native-community/netinfo": "^11.3.2", "@react-native-community/slider": "^4.5.2", "@react-native-firebase/analytics": "20.1.0", "@react-native-firebase/app": "20.1.0", "@react-native-firebase/crashlytics": "20.1.0", "@react-native-firebase/in-app-messaging": "20.1.0", "@react-native-firebase/messaging": "20.1.0", "@react-native-firebase/remote-config": "20.1.0", "@react-native-material/core": "^1.3.7", "@react-native-segmented-control/segmented-control": "^2.5.2", "@react-navigation/bottom-tabs": "^6.5.20", "@react-navigation/native": "^6.1.17", "@react-navigation/stack": "^6.3.29", "@realm/react": "^0.6.2", "@reduxjs/toolkit": "^2.2.1", "@shopify/react-native-skia": "1.3.6", "@solana/web3.js": "^1.95.3", "@tradle/react-native-http": "^2.0.1", "@types/promise.allsettled": "^1.0.6", "@types/react-native-incall-manager": "^4.0.3", "@types/react-native-video": "^5.0.19", "@uniswap/sdk-core": "^4.2.0", "@uniswap/smart-order-router": "^3.26.0", "@uniswap/v3-sdk": "^3.11.0", "assert": "^1.1.1", "axios": "^1.6.7", "base-64": "^1.0.0", "browserify-zlib": "~0.1.4", "buffer": "^6.0.3", "cheerio": "^1.0.0-rc.12", "console-browserify": "^1.1.0", "constants-browserify": "^1.0.0", "copyfiles": "^2.4.1", "dns.js": "^1.0.1", "domain-browser": "^1.1.1", "ethers": "^6.11.1", "ethersv5": "npm:ethers@^5.7.2", "events": "^3.3.0", "fbemitter": "^3.0.0", "google-libphonenumber": "^3.2.34", "hardhat": "^2.20.1", "https-browserify": "^1.0.0", "i18next": "^23.10.0", "jsbi": "^3.2.0", "jwt-decode": "^4.0.0", "linkifyjs": "^4.1.3", "livekit-client": "^2.12.0", "lodash": "^4.17.21", "matrix-js-sdk": "^31.4.0", "metro": "^0.80.6", "metro-hermes-compiler": "^0.73.10", "moment": "^2.30.1", "node-libs-browser": "^2.2.1", "olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz", "openai": "^4.28.4", "parse-open-graph": "^0.4.0", "patch-package": "^8.0.0", "path-browserify": "0.0.0", "postinstall-postinstall": "^2.1.0", "process": "^0.11.0", "promise.allsettled": "^1.0.7", "punycode": "^1.2.4", "querystring-es3": "~0.2.0", "quickswap-sdk": "^3.0.30", "react": "18.3.1", "react-i18next": "^14.1.0", "react-native": "0.74.3", "react-native-animated-progress": "^1.0.2", "react-native-app-auth": "7.2.0", "react-native-app-intro-slider": "^4.0.4", "react-native-audio-recorder-player": "3.6.8", "react-native-autolink": "^4.2.0", "react-native-bouncy-checkbox": "4.0.1", "react-native-bouncy-checkbox-group": "^0.1.1", "react-native-calendars": "1.1305.0", "react-native-camera": "4.2.1", "react-native-confirmation-code-field": "7.4.0", "react-native-contacts": "^7.0.8", "react-native-create-thumbnail": "^2.0.0", "react-native-crypto": "^2.2.0", "react-native-date-picker": "^5.0.4", "react-native-device-info": "^11.1.0", "react-native-document-picker": "9.3.0", "react-native-element-dropdown": "^2.12.0", "react-native-encrypted-storage": "^4.0.3", "react-native-fast-image": "^8.6.3", "react-native-fs": "^2.20.0", "react-native-gesture-handler": "^2.17.0", "react-native-get-random-values": "^1.11.0", "react-native-google-mobile-ads": "13.6.0", "react-native-gradle-plugin": "^0.71.19", "react-native-image-keyboard": "^2.2.1", "react-native-image-picker": "^7.1.2", "react-native-image-viewing": "^0.2.2", "react-native-inappbrowser-reborn": "^3.7.0", "react-native-incall-manager": "^4.2.0", "react-native-level-fs": "^3.0.0", "react-native-localize": "^3.2.0", "react-native-material-menu": "^2.0.0", "react-native-modal": "^13.0.1", "react-native-modal-datetime-picker": "^17.1.0", "react-native-permissions": "^3.10.1", "react-native-phone-number-input": "^2.1.0", "react-native-qrcode-scanner": "^1.5.5", "react-native-qrcode-svg": "^6.3.1", "react-native-randombytes": "^3.6.1", "react-native-rss-parser": "^1.5.1", "react-native-safe-area-context": "^4.10.5", "react-native-screens": "^3.32.0", "react-native-sha256": "^1.4.10", "react-native-share": "^10.2.1", "react-native-shared-preferences": "^1.0.2", "react-native-sound": "^0.11.2", "react-native-splash-screen": "^3.3.0", "react-native-svg": "^15.3.0", "react-native-swiper": "^1.6.0", "react-native-toast-notifications": "^3.3.1", "react-native-tracking-transparency": "^0.1.2", "react-native-typing-animation": "^0.1.7", "react-native-udp": "^4.1.7", "react-native-url-polyfill": "^1.3.0", "react-native-video": "^6.2.0", "react-native-volume-manager": "^1.2.1", "react-native-walkthrough-tooltip": "^1.6.0", "react-native-webview": "^13.10.3", "react-redux": "^8.0.4", "readable-stream": "1.0.33", "realm": "^12.11.1", "rn-fetch-blob": "^0.12.0", "stream-browserify": "^3.0.0", "string_decoder": "~0.10.25", "svg-path-properties": "^1.3.0", "timers-browserify": "^1.0.1", "tty-browserify": "0.0.0", "unorm": "^1.6.0", "url": "^0.11.0", "util": "~0.10.3", "vm-browserify": "0.0.4", "web3": "^1.8.1"
t
Thank you for providing the list of dependencies in your project. Based on the information, it seems there are several libraries that might interact with WebRTC or the global environment, such as
@livekit/react-native-webrtc
,
react-native-webrtc
, or other polyfills like
react-native-get-random-values
and
react-native-url-polyfill
. To further investigate the issue, could you confirm the following: • Have you ensured that
registerGlobals()
is called at the very start of your application, before any other imports or initializations? • Are there any custom configurations or overrides in your project that might affect the global
window
object? • Does the issue occur on both iOS and Android, or is it specific to one platform? With this additional information, I can assist you further or escalate the issue to a specialist if needed.
a
i have the same error on ios and android
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.