aws / amazon-chime-sdk-js

A JavaScript client library for integrating multi-party communications powered by the Amazon Chime service.
Apache License 2.0
704 stars 475 forks source link

Uncaught TypeError: Cannot read property 'split' of null when using with react native while initializing default session #2674

Closed harryy2510 closed 1 year ago

harryy2510 commented 1 year ago

Hi! šŸ‘‹

Firstly, thanks for your work on this project! šŸ™‚

Today I used patch-package to patch amazon-chime-sdk-js@3.14.1 for the project I'm working on.

The project is based on react native and utilises amazon-chime-sdk-js and @aws-sdk/client-chime-sdk-messaging for chat. While initializing default session on react native,amazon-chime-sdk-js throws error Cannot read property 'split' of null when it tried to find major version of browser.

Here is the diff that solved my problem:

diff --git a/node_modules/amazon-chime-sdk-js/build/browserbehavior/DefaultBrowserBehavior.js b/node_modules/amazon-chime-sdk-js/build/browserbehavior/DefaultBrowserBehavior.js
index 43cc745..6691c21 100644
--- a/node_modules/amazon-chime-sdk-js/build/browserbehavior/DefaultBrowserBehavior.js
+++ b/node_modules/amazon-chime-sdk-js/build/browserbehavior/DefaultBrowserBehavior.js
@@ -61,7 +61,7 @@ class DefaultBrowserBehavior {
         this.webkitBrowsers = ['crios', 'fxios', 'safari', 'ios', 'ios-webview', 'edge-ios'];
     }
     version() {
-        return this.browser.version;
+        return this.browser.version || "";
     }
     majorVersion() {
         return parseInt(this.version().split('.')[0]);

This issue body was partially generated by patch-package.

xuesichao commented 1 year ago

Hi @harryy2510 , we are using detect() API of detect-browser library to retrieve the browser info in DefaultBrwoserBehavior.js. It seems for react native, the browser info from detect() does not contain a valid value for version, and in this cause your fix serves as a safe guard.

I just checked the implementation of detect-browser and confirm it returns null for version. https://github.com/DamonOehlman/detect-browser/pull/137/files

I'll add your fix to our library. Thanks for sharing this with us!

xuesichao commented 1 year ago

Duplicate of #1856 .