diff --git a/package-lock.json b/package-lock.json index 19d7c7875..76dbf9d62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@ably/msgpack-js": "^0.4.0", + "fastestsmallesttextencoderdecoder": "^1.0.22", "got": "^11.8.5", "ws": "^8.14.2" }, @@ -4645,6 +4646,11 @@ "node": ">= 4.9.1" } }, + "node_modules/fastestsmallesttextencoderdecoder": { + "version": "1.0.22", + "resolved": "https://registry.npmjs.org/fastestsmallesttextencoderdecoder/-/fastestsmallesttextencoderdecoder-1.0.22.tgz", + "integrity": "sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==" + }, "node_modules/fastq": { "version": "1.16.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", @@ -14062,6 +14068,11 @@ "integrity": "sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg==", "dev": true }, + "fastestsmallesttextencoderdecoder": { + "version": "1.0.22", + "resolved": "https://registry.npmjs.org/fastestsmallesttextencoderdecoder/-/fastestsmallesttextencoderdecoder-1.0.22.tgz", + "integrity": "sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==" + }, "fastq": { "version": "1.16.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.16.0.tgz", diff --git a/package.json b/package.json index b6430e582..dfc5cd50c 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "url": "https://github.com/ably/ably-js/issues", "email": "support@ably.com" }, + "react-native": "./build/ably-reactnative.js", "exports": { ".": { "types": "./ably.d.ts", @@ -34,6 +35,7 @@ ], "dependencies": { "@ably/msgpack-js": "^0.4.0", + "fastestsmallesttextencoderdecoder": "^1.0.22", "got": "^11.8.5", "ws": "^8.14.2" }, diff --git a/src/platform/react-native/index.ts b/src/platform/react-native/index.ts index 998c2dd19..4153714d3 100644 --- a/src/platform/react-native/index.ts +++ b/src/platform/react-native/index.ts @@ -20,6 +20,9 @@ import PlatformDefaults from '../web/lib/util/defaults'; import msgpack from '../web/lib/util/msgpack'; import { defaultBundledRequestImplementations } from '../web/lib/http/request'; +// lightweight polyfill for TextEncoder/TextDecoder +import 'fastestsmallesttextencoderdecoder'; + const Config = configFactory(BufferUtils); const Crypto = createCryptoClass(Config, BufferUtils); diff --git a/webpack.config.js b/webpack.config.js index e1a056a13..75a06278e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -91,6 +91,7 @@ const reactNativeConfig = { request: false, ws: false, 'react-native': true, + fastestsmallesttextencoderdecoder: 'fastestsmallesttextencoderdecoder', }, optimization: { minimize: false,