diff --git a/README.md b/README.md
index 2055d94..e9d828b 100644
--- a/README.md
+++ b/README.md
@@ -9,9 +9,12 @@ Blazing fast WebSocket client for React Native built on top of [Nitro](https://m
### Getting started
```
-npm install react-native-fast-ws react-native-nitro-modules
+npm install react-native-fast-ws --save
```
+> [!NOTE]
+> This package requires React Native 0.76 and New Architecture. You must also install and configure [Nitro Modules](https://github.com/mrousavy/nitro) to use this package.
+
### TODOs
- Provide Android support
diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle
index efbd81a..4934ba2 100644
--- a/example/android/app/build.gradle
+++ b/example/android/app/build.gradle
@@ -11,11 +11,11 @@ react {
// The root of your project, i.e. where "package.json" lives. Default is '../..'
// root = file("../../")
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
- // reactNativeDir = file("../../node_modules/react-native")
+ reactNativeDir = file("../../../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
- // codegenDir = file("../../node_modules/@react-native/codegen")
+ codegenDir = file("../../../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
- // cliFile = file("../../node_modules/react-native/cli.js")
+ cliFile = file("../../../node_modules/react-native/cli.js")
/* Variants */
// The list of variants to that are debuggable. For those we're going to
diff --git a/example/android/app/src/main/java/com/nitroplayground/MainApplication.kt b/example/android/app/src/main/java/com/nitroplayground/MainApplication.kt
index 8da2516..4cb4586 100644
--- a/example/android/app/src/main/java/com/nitroplayground/MainApplication.kt
+++ b/example/android/app/src/main/java/com/nitroplayground/MainApplication.kt
@@ -8,6 +8,7 @@ import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
+import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
@@ -34,7 +35,7 @@ class MainApplication : Application(), ReactApplication {
override fun onCreate() {
super.onCreate()
- SoLoader.init(this, false)
+ SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
diff --git a/example/android/build.gradle b/example/android/build.gradle
index df1ce4d..a9ea023 100644
--- a/example/android/build.gradle
+++ b/example/android/build.gradle
@@ -1,8 +1,8 @@
buildscript {
ext {
- buildToolsVersion = "34.0.0"
- minSdkVersion = 23
- compileSdkVersion = 34
+ buildToolsVersion = "35.0.0"
+ minSdkVersion = 24
+ compileSdkVersion = 35
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.24"
diff --git a/example/android/gradle.properties b/example/android/gradle.properties
index 9fb1566..5e24e3a 100644
--- a/example/android/gradle.properties
+++ b/example/android/gradle.properties
@@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
-newArchEnabled=false
+newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties
index 6f7a6eb..79eb9d0 100644
--- a/example/android/gradle/wrapper/gradle-wrapper.properties
+++ b/example/android/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/example/android/gradlew b/example/android/gradlew
index b740cf1..f5feea6 100755
--- a/example/android/gradlew
+++ b/example/android/gradlew
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
#
@@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
-APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
diff --git a/example/android/gradlew.bat b/example/android/gradlew.bat
index 7101f8e..9b42019 100644
--- a/example/android/gradlew.bat
+++ b/example/android/gradlew.bat
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
diff --git a/example/android/settings.gradle b/example/android/settings.gradle
index 98ec6d3..09f8090 100644
--- a/example/android/settings.gradle
+++ b/example/android/settings.gradle
@@ -1,6 +1,8 @@
-pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
+pluginManagement { includeBuild("../../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
+
rootProject.name = 'NitroPlayground'
+
include ':app'
-includeBuild('../node_modules/@react-native/gradle-plugin')
+includeBuild('../../node_modules/@react-native/gradle-plugin')
\ No newline at end of file
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 5afcf85..127f3ee 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -1,6 +1,28 @@
PODS:
- boost (1.84.0)
- DoubleConversion (1.1.6)
+ - FastWebSocket (0.0.1):
+ - DoubleConversion
+ - glog
+ - hermes-engine
+ - NitroModules
+ - RCT-Folly (= 2024.01.01.00)
+ - RCTRequired
+ - RCTTypeSafety
+ - React-Core
+ - React-debug
+ - React-Fabric
+ - React-featureflags
+ - React-graphics
+ - React-ImageManager
+ - React-NativeModulesApple
+ - React-RCTFabric
+ - React-rendererdebug
+ - React-utils
+ - ReactCodegen
+ - ReactCommon/turbomodule/bridging
+ - ReactCommon/turbomodule/core
+ - Yoga
- FBLazyVector (0.76.0)
- fmt (9.1.0)
- glog (0.3.5)
@@ -1530,34 +1552,13 @@ PODS:
- React-logger (= 0.76.0)
- React-perflogger (= 0.76.0)
- React-utils (= 0.76.0)
- - ReactNativeFastWS (0.0.1):
- - DoubleConversion
- - glog
- - hermes-engine
- - NitroModules
- - RCT-Folly (= 2024.01.01.00)
- - RCTRequired
- - RCTTypeSafety
- - React-Core
- - React-debug
- - React-Fabric
- - React-featureflags
- - React-graphics
- - React-ImageManager
- - React-NativeModulesApple
- - React-RCTFabric
- - React-rendererdebug
- - React-utils
- - ReactCodegen
- - ReactCommon/turbomodule/bridging
- - ReactCommon/turbomodule/core
- - Yoga
- SocketRocket (0.7.1)
- Yoga (0.0.0)
DEPENDENCIES:
- boost (from `../../node_modules/react-native/third-party-podspecs/boost.podspec`)
- DoubleConversion (from `../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
+ - FastWebSocket (from `../../node_modules/react-native-fast-ws`)
- FBLazyVector (from `../../node_modules/react-native/Libraries/FBLazyVector`)
- fmt (from `../../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../../node_modules/react-native/third-party-podspecs/glog.podspec`)
@@ -1621,7 +1622,6 @@ DEPENDENCIES:
- React-utils (from `../../node_modules/react-native/ReactCommon/react/utils`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../../node_modules/react-native/ReactCommon`)
- - ReactNativeFastWS (from `../../node_modules/react-native-fast-ws`)
- Yoga (from `../../node_modules/react-native/ReactCommon/yoga`)
SPEC REPOS:
@@ -1633,6 +1633,8 @@ EXTERNAL SOURCES:
:podspec: "../../node_modules/react-native/third-party-podspecs/boost.podspec"
DoubleConversion:
:podspec: "../../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
+ FastWebSocket:
+ :path: "../../node_modules/react-native-fast-ws"
FBLazyVector:
:path: "../../node_modules/react-native/Libraries/FBLazyVector"
fmt:
@@ -1756,14 +1758,13 @@ EXTERNAL SOURCES:
:path: build/generated/ios
ReactCommon:
:path: "../../node_modules/react-native/ReactCommon"
- ReactNativeFastWS:
- :path: "../../node_modules/react-native-fast-ws"
Yoga:
:path: "../../node_modules/react-native/ReactCommon/yoga"
SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
+ FastWebSocket: f3a9f040b80d07f0d1f059651aa08b57a48323b9
FBLazyVector: aa59bef5c46e93168bffcf3dc37ee1e176de799a
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
@@ -1825,7 +1826,6 @@ SPEC CHECKSUMS:
React-utils: d9624101245ebaab39c9f1bd786132da0b4f27ff
ReactCodegen: 24a667adc5346207bc8029c9bf99710aa67d4371
ReactCommon: 429ca28cd813c31359c73ffac6dc24f93347d522
- ReactNativeFastWS: 632f4bfbcc6f6aa09c72db93927ad29d2b428228
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: f8ec45ce98bba1bc93dd28f2ee37215180e6d2b6
diff --git a/example/package.json b/example/package.json
index a2b9dd1..c060328 100644
--- a/example/package.json
+++ b/example/package.json
@@ -19,11 +19,12 @@
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/cli": "^15.0.1",
+ "@react-native-community/cli-platform-android": "^15.0.1",
+ "@react-native-community/cli-platform-ios": "^15.0.1",
"@react-native/babel-preset": "0.76.0",
"@react-native/metro-config": "0.76.0",
"@types/react": "^18.2.6",
- "eslint": "^8.19.0",
- "nitro-codegen": "^0.8.0"
+ "eslint": "^8.19.0"
},
"engines": {
"node": ">=18"
diff --git a/package-lock.json b/package-lock.json
index a93f41a..270cf7c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -40,11 +40,12 @@
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/cli": "^15.0.1",
+ "@react-native-community/cli-platform-android": "^15.0.1",
+ "@react-native-community/cli-platform-ios": "^15.0.1",
"@react-native/babel-preset": "0.76.0",
"@react-native/metro-config": "0.76.0",
"@types/react": "^18.2.6",
- "eslint": "^8.19.0",
- "nitro-codegen": "^0.8.0"
+ "eslint": "^8.19.0"
},
"engines": {
"node": ">=18"
@@ -3104,28 +3105,15 @@
}
},
"node_modules/@ts-morph/common": {
- "version": "0.24.0",
+ "version": "0.25.0",
+ "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.25.0.tgz",
+ "integrity": "sha512-kMnZz+vGGHi4GoHnLmMhGNjm44kGtKUXGnOvrKmMwAuvNjM/PgKVGfUnL7IDvK7Jb2QQ82jq3Zmp04Gy+r3Dkg==",
"dev": true,
"license": "MIT",
"dependencies": {
- "fast-glob": "^3.3.2",
"minimatch": "^9.0.4",
- "mkdirp": "^3.0.1",
- "path-browserify": "^1.0.1"
- }
- },
- "node_modules/@ts-morph/common/node_modules/mkdirp": {
- "version": "3.0.1",
- "dev": true,
- "license": "MIT",
- "bin": {
- "mkdirp": "dist/cjs/src/bin.js"
- },
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/isaacs"
+ "path-browserify": "^1.0.1",
+ "tinyglobby": "^0.2.9"
}
},
"node_modules/@types/babel__core": {
@@ -4421,7 +4409,9 @@
}
},
"node_modules/code-block-writer": {
- "version": "13.0.2",
+ "version": "13.0.3",
+ "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-13.0.3.tgz",
+ "integrity": "sha512-Oofo0pq3IKnsFtuHqSF7TqBfr71aeyZDVJ0HpmqB7FBM2qEigL0iPONSCZSO9pE9dZTAxANe5XHG9Uy0YMv8cg==",
"dev": true,
"license": "MIT"
},
@@ -7781,14 +7771,16 @@
"license": "MIT"
},
"node_modules/nitro-codegen": {
- "version": "0.8.0",
+ "version": "0.14.0",
+ "resolved": "https://registry.npmjs.org/nitro-codegen/-/nitro-codegen-0.14.0.tgz",
+ "integrity": "sha512-3qebf0vIkr5dsSVo00NO4RH9JUPaANOpSeK8wj5E5LNv3QpZ2Z7HKv1hi2Ksb2ex6uQrkYduZwWg4ogwZl7y7g==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"chalk": "^5.3.0",
- "react-native-nitro-modules": "^0.6.0",
- "ts-morph": "^23.0.0",
+ "react-native-nitro-modules": "^0.14.0",
+ "ts-morph": "^24.0.0",
"yargs": "^17.7.2",
"zod": "^3.23.8"
},
@@ -7807,16 +7799,6 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
- "node_modules/nitro-codegen/node_modules/react-native-nitro-modules": {
- "version": "0.6.0",
- "dev": true,
- "hasInstallScript": true,
- "license": "MIT",
- "peerDependencies": {
- "react": "*",
- "react-native": "*"
- }
- },
"node_modules/nocache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/nocache/-/nocache-3.0.4.tgz",
@@ -8214,6 +8196,8 @@
},
"node_modules/path-browserify": {
"version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz",
+ "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==",
"dev": true,
"license": "MIT"
},
@@ -9532,6 +9516,48 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/tinyglobby": {
+ "version": "0.2.10",
+ "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.10.tgz",
+ "integrity": "sha512-Zc+8eJlFMvgatPZTl6A9L/yht8QqdmUNtURHaKZLmKBE12hNPSrqNkUp2cs3M/UKmNVVAMFQYSjYIVHDjW5zew==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "fdir": "^6.4.2",
+ "picomatch": "^4.0.2"
+ },
+ "engines": {
+ "node": ">=12.0.0"
+ }
+ },
+ "node_modules/tinyglobby/node_modules/fdir": {
+ "version": "6.4.2",
+ "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.2.tgz",
+ "integrity": "sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==",
+ "dev": true,
+ "license": "MIT",
+ "peerDependencies": {
+ "picomatch": "^3 || ^4"
+ },
+ "peerDependenciesMeta": {
+ "picomatch": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/tinyglobby/node_modules/picomatch": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
+ "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/jonschlinkert"
+ }
+ },
"node_modules/tinypool": {
"version": "1.0.1",
"dev": true,
@@ -9597,12 +9623,14 @@
}
},
"node_modules/ts-morph": {
- "version": "23.0.0",
+ "version": "24.0.0",
+ "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-24.0.0.tgz",
+ "integrity": "sha512-2OAOg/Ob5yx9Et7ZX4CvTCc0UFoZHwLEJ+dpDPSUi5TgwwlTlX47w+iFRrEwzUZwYACjq83cgjS/Da50Ga37uw==",
"dev": true,
"license": "MIT",
"dependencies": {
- "@ts-morph/common": "~0.24.0",
- "code-block-writer": "^13.0.1"
+ "@ts-morph/common": "~0.25.0",
+ "code-block-writer": "^13.0.3"
}
},
"node_modules/tsconfig-paths": {
@@ -10262,6 +10290,7 @@
},
"devDependencies": {
"event-target-shim": "^6.0.2",
+ "nitro-codegen": "^0.14.0",
"web-streams-polyfill": "^4.0.0"
},
"peerDependencies": {
diff --git a/package.json b/package.json
index e72c9c4..0ea1361 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
"./example"
],
"scripts": {
- "codegen": "(cd ./packages/react-native-fast-ws && npm run codegen) && (cd ./example/ios && RCT_NEW_ARCH_ENABLED=1 pod install)",
+ "codegen": "(cd ./packages/react-native-fast-ws && npm run codegen) && (cd ./example/ios && pod install)",
"test": "vitest"
},
"devDependencies": {
diff --git a/packages/react-native-fast-ws/ReactNativeFastWS.podspec b/packages/react-native-fast-ws/FastWebSocket.podspec
similarity index 84%
rename from packages/react-native-fast-ws/ReactNativeFastWS.podspec
rename to packages/react-native-fast-ws/FastWebSocket.podspec
index 03a173e..c99a761 100644
--- a/packages/react-native-fast-ws/ReactNativeFastWS.podspec
+++ b/packages/react-native-fast-ws/FastWebSocket.podspec
@@ -3,7 +3,7 @@ require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
Pod::Spec.new do |s|
- s.name = "ReactNativeFastWS"
+ s.name = "FastWebSocket"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
"ios/**/*.{swift}"
]
- load 'nitrogen/generated/ios/ReactNativeFastWS+autolinking.rb'
+ load 'nitrogen/generated/ios/FastWebSocket+autolinking.rb'
add_nitrogen_files(s)
install_modules_dependencies(s)
diff --git a/packages/react-native-fast-ws/android/CMakeLists.txt b/packages/react-native-fast-ws/android/CMakeLists.txt
new file mode 100644
index 0000000..67a32e3
--- /dev/null
+++ b/packages/react-native-fast-ws/android/CMakeLists.txt
@@ -0,0 +1,29 @@
+project(FastWebSocket)
+cmake_minimum_required(VERSION 3.9.0)
+
+set (PACKAGE_NAME FastWebSocket)
+set (CMAKE_VERBOSE_MAKEFILE ON)
+set (CMAKE_CXX_STANDARD 20)
+
+# Define C++ library and add all sources
+add_library(${PACKAGE_NAME} SHARED
+ src/main/cpp/cpp-adapter.cpp
+)
+
+# Add Nitrogen specs :)
+include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/FastWebSocket+autolinking.cmake)
+
+# Set up local includes
+include_directories(
+ "src/main/cpp"
+ # "../cpp"
+)
+
+find_library(LOG_LIB log)
+
+# Link all libraries together
+target_link_libraries(
+ ${PACKAGE_NAME}
+ ${LOG_LIB}
+ android # <-- Android core
+)
diff --git a/packages/react-native-fast-ws/android/build.gradle b/packages/react-native-fast-ws/android/build.gradle
new file mode 100644
index 0000000..267de3e
--- /dev/null
+++ b/packages/react-native-fast-ws/android/build.gradle
@@ -0,0 +1,137 @@
+buildscript {
+ repositories {
+ google()
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath "com.android.tools.build:gradle:8.7.1"
+ }
+}
+
+def reactNativeArchitectures() {
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
+}
+
+def isNewArchitectureEnabled() {
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
+}
+
+apply plugin: "com.android.library"
+apply plugin: 'org.jetbrains.kotlin.android'
+apply from: '../nitrogen/generated/android/FastWebSocket+autolinking.gradle'
+
+if (isNewArchitectureEnabled()) {
+ apply plugin: "com.facebook.react"
+}
+
+def getExtOrDefault(name) {
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Nitro_" + name]
+}
+
+def getExtOrIntegerDefault(name) {
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Nitro_" + name]).toInteger()
+}
+
+android {
+ namespace "com.margelo.nitro.websocket"
+
+ ndkVersion getExtOrDefault("ndkVersion")
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
+
+ defaultConfig {
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
+
+ externalNativeBuild {
+ cmake {
+ cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
+ arguments "-DANDROID_STL=c++_shared"
+ abiFilters (*reactNativeArchitectures())
+ }
+ }
+ }
+
+ externalNativeBuild {
+ cmake {
+ path "CMakeLists.txt"
+ }
+ }
+
+ buildFeatures {
+ buildConfig true
+ prefab true
+ }
+
+ packagingOptions {
+ excludes = [
+ "META-INF",
+ "META-INF/**",
+ "**/libc++_shared.so",
+ "**/libfbjni.so",
+ "**/libjsi.so",
+ "**/libfolly_json.so",
+ "**/libfolly_runtime.so",
+ "**/libglog.so",
+ "**/libhermes.so",
+ "**/libhermes-executor-debug.so",
+ "**/libhermes_executor.so",
+ "**/libreactnativejni.so",
+ "**/libturbomodulejsijni.so",
+ "**/libreact_nativemodule_core.so",
+ "**/libjscexecutor.so"
+ ]
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ }
+ }
+
+ lintOptions {
+ disable "GradleCompatible"
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ sourceSets {
+ main {
+ if (isNewArchitectureEnabled()) {
+ java.srcDirs += [
+ // React Codegen files
+ "${project.buildDir}/generated/source/codegen/java"
+ ]
+ }
+ }
+ }
+}
+
+repositories {
+ mavenCentral()
+ google()
+}
+
+
+dependencies {
+ // For < 0.71, this will be from the local maven repo
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
+ //noinspection GradleDynamicVersion
+ implementation "com.facebook.react:react-native:+"
+
+ // Add a dependency on NitroModules
+ implementation project(":react-native-nitro-modules")
+}
+
+if (isNewArchitectureEnabled()) {
+ react {
+ jsRootDir = file("../src/")
+ libraryName = "FastWebSocket"
+ codegenJavaPackageName = "com.margelo.nitro.websocket"
+ }
+}
diff --git a/packages/react-native-fast-ws/android/src/main/AndroidManifest.xml b/packages/react-native-fast-ws/android/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..a2f47b6
--- /dev/null
+++ b/packages/react-native-fast-ws/android/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/packages/react-native-fast-ws/android/src/main/cpp/cpp-adapter.cpp b/packages/react-native-fast-ws/android/src/main/cpp/cpp-adapter.cpp
new file mode 100644
index 0000000..f3356c6
--- /dev/null
+++ b/packages/react-native-fast-ws/android/src/main/cpp/cpp-adapter.cpp
@@ -0,0 +1,8 @@
+#include
+#include
+
+#include "FastWebSocketOnLoad.hpp"
+
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
+ return facebook::jni::initialize(vm, [=] { margelo::nitro::websocket::initialize(vm); });
+}
diff --git a/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/FastWebSocketPackage.java b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/FastWebSocketPackage.java
new file mode 100644
index 0000000..df9f7df
--- /dev/null
+++ b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/FastWebSocketPackage.java
@@ -0,0 +1,30 @@
+package com.margelo.nitro.websocket;
+
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.facebook.react.bridge.NativeModule;
+import com.facebook.react.bridge.ReactApplicationContext;
+import com.facebook.react.module.model.ReactModuleInfoProvider;
+import com.facebook.react.TurboReactPackage;
+
+import java.util.HashMap;
+
+public class FastWebSocketPackage extends TurboReactPackage {
+ @Nullable
+ @Override
+ public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext) {
+ return null;
+ }
+
+ @Override
+ public ReactModuleInfoProvider getReactModuleInfoProvider() {
+ return HashMap::new;
+ }
+
+ static {
+ System.loadLibrary("FastWebSocket");
+ }
+}
diff --git a/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocket.kt b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocket.kt
new file mode 100644
index 0000000..3325697
--- /dev/null
+++ b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocket.kt
@@ -0,0 +1,49 @@
+package com.margelo.nitro.websocket
+
+import com.margelo.nitro.core.ArrayBuffer
+
+class HybridWebSocket(url: String, protocols: Array) : HybridWebSocketSpec() {
+ override fun send(message: String) {
+ TODO("Not implemented")
+ }
+
+ override fun sendArrayBuffer(buffer: ArrayBuffer) {
+ TODO("Not implemented")
+ }
+
+ override fun connect() {
+ TODO("Not implemented")
+ }
+
+ override fun close() {
+ TODO("Not implemented")
+ }
+
+ override fun ping() {
+ TODO("Not implemented")
+ }
+
+ override fun onOpen(callback: (selectedProtocol: String) -> Unit) {
+ TODO("Not implemented")
+ }
+
+ override fun onClose(callback: (code: Double, reason: String) -> Unit) {
+ TODO("Not implemented")
+ }
+
+ override fun onError(callback: (error: String) -> Unit) {
+ TODO("Not implemented")
+ }
+
+ override fun onMessage(callback: (message: String) -> Unit) {
+ TODO("Not implemented")
+ }
+
+ override fun onArrayBuffer(callback: (buffer: ArrayBuffer) -> Unit) {
+ TODO("Not implemented")
+ }
+
+ override val memorySize: Long
+ get() = 0L
+
+}
diff --git a/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocketManager.kt b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocketManager.kt
new file mode 100644
index 0000000..2d7ae55
--- /dev/null
+++ b/packages/react-native-fast-ws/android/src/main/java/com/margelo/nitro/websocket/HybridWebSocketManager.kt
@@ -0,0 +1,13 @@
+package com.margelo.nitro.websocket
+
+import com.facebook.proguard.annotations.DoNotStrip
+
+@DoNotStrip
+class HybridWebSocketManager : HybridWebSocketManagerSpec() {
+ override fun create(url: String, protocols: Array): HybridWebSocketSpec {
+ return HybridWebSocket(url, protocols)
+ }
+
+ override val memorySize: Long
+ get() = 0L
+}
\ No newline at end of file
diff --git a/packages/react-native-fast-ws/nitro.json b/packages/react-native-fast-ws/nitro.json
index 2e61769..2a0fa65 100644
--- a/packages/react-native-fast-ws/nitro.json
+++ b/packages/react-native-fast-ws/nitro.json
@@ -1,15 +1,16 @@
{
- "cxxNamespace": ["grabbou"],
+ "cxxNamespace": ["websocket"],
"ios": {
- "iosModulename": "ReactNativeFastWS"
+ "iosModuleName": "FastWebSocket"
},
"android": {
- "androidNamespace": ["grabbou"],
- "androidCxxLibName": "ReactNativeFastWS"
+ "androidNamespace": ["websocket"],
+ "androidCxxLibName": "FastWebSocket"
},
"autolinking": {
"WebSocketManager": {
- "swift": "HybridWebSocketManager"
+ "swift": "HybridWebSocketManager",
+ "kotlin": "HybridWebSocketManager"
}
}
}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.cmake b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.cmake
similarity index 69%
rename from packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.cmake
rename to packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.cmake
index e588401..ee43524 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.cmake
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.cmake
@@ -1,6 +1,5 @@
#
-# ReactNativeFastWS+autolinking.cmake
-# Fri Nov 01 2024
+# FastWebSocket+autolinking.cmake
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
# https://github.com/mrousavy/nitro
# Copyright © 2024 Marc Rousavy @ Margelo
@@ -11,7 +10,7 @@
#
# To use it, add this to your CMakeLists.txt:
# ```cmake
-# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeFastWS+autolinking.cmake)
+# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/FastWebSocket+autolinking.cmake)
# ```
# Add all headers that were generated by Nitrogen
@@ -24,14 +23,15 @@ include_directories(
# Add all .cpp sources that were generated by Nitrogen
target_sources(
# CMake project name (Android C++ library name)
- ReactNativeFastWS PRIVATE
+ FastWebSocket PRIVATE
# Autolinking Setup
- ../nitrogen/generated/android/ReactNativeFastWSOnLoad.cpp
+ ../nitrogen/generated/android/FastWebSocketOnLoad.cpp
# Shared Nitrogen C++ sources
../nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp
../nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp
# Android-specific Nitrogen C++ sources
-
+ ../nitrogen/generated/android/c++/JHybridWebSocketSpec.cpp
+ ../nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.cpp
)
# Add all libraries required by the generated specs
@@ -41,9 +41,21 @@ find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all Hybri
# Link all libraries together
target_link_libraries(
- ReactNativeFastWS
+ FastWebSocket
fbjni::fbjni # <-- Facebook C++ JNI helpers
ReactAndroid::jsi # <-- RN: JSI
- ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
)
+
+# Link react-native (different prefab between RN 0.75 and RN 0.76)
+if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
+ target_link_libraries(
+ FastWebSocket
+ ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
+ )
+else()
+ target_link_libraries(
+ FastWebSocket
+ ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
+ )
+endif()
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.gradle b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.gradle
similarity index 77%
rename from packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.gradle
rename to packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.gradle
index 143c83e..3c08dc8 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWS+autolinking.gradle
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocket+autolinking.gradle
@@ -1,6 +1,5 @@
///
-/// ReactNativeFastWS+autolinking.gradle
-/// Fri Nov 01 2024
+/// FastWebSocket+autolinking.gradle
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -11,7 +10,7 @@
///
/// To use it, add this to your build.gradle:
/// ```gradle
-/// apply from: '../nitrogen/generated/android/ReactNativeFastWS+autolinking.gradle'
+/// apply from: '../nitrogen/generated/android/FastWebSocket+autolinking.gradle'
/// ```
android {
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.cpp b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.cpp
new file mode 100644
index 0000000..41b87c4
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.cpp
@@ -0,0 +1,58 @@
+///
+/// FastWebSocketOnLoad.cpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#include "FastWebSocketOnLoad.hpp"
+
+#include
+#include
+#include
+
+#include "JHybridWebSocketSpec.hpp"
+#include "JFunc_void_std__string.hpp"
+#include "JFunc_void_double_std__string.hpp"
+#include "JFunc_void_std__shared_ptr_ArrayBuffer_.hpp"
+#include "JHybridWebSocketManagerSpec.hpp"
+#include
+
+namespace margelo::nitro::websocket {
+
+int initialize(JavaVM* vm) {
+ using namespace margelo::nitro;
+ using namespace margelo::nitro::websocket;
+ using namespace facebook;
+
+ return facebook::jni::initialize(vm, [] {
+ // Register native JNI methods
+ margelo::nitro::websocket::JHybridWebSocketSpec::registerNatives();
+ margelo::nitro::websocket::JFunc_void_std__string::registerNatives();
+ margelo::nitro::websocket::JFunc_void_double_std__string::registerNatives();
+ margelo::nitro::websocket::JFunc_void_std__string::registerNatives();
+ margelo::nitro::websocket::JFunc_void_std__string::registerNatives();
+ margelo::nitro::websocket::JFunc_void_std__shared_ptr_ArrayBuffer_::registerNatives();
+ margelo::nitro::websocket::JHybridWebSocketManagerSpec::registerNatives();
+
+ // Register Nitro Hybrid Objects
+ HybridObjectRegistry::registerHybridObjectConstructor(
+ "WebSocketManager",
+ []() -> std::shared_ptr {
+ static auto javaClass = jni::findClassStatic("com/margelo/nitro/websocket/HybridWebSocketManager");
+ static auto defaultConstructor = javaClass->getConstructor();
+
+ auto instance = javaClass->newObject(defaultConstructor);
+ #ifdef NITRO_DEBUG
+ if (instance == nullptr) [[unlikely]] {
+ throw std::runtime_error("Failed to create an instance of \"JHybridWebSocketManagerSpec\" - the constructor returned null!");
+ }
+ #endif
+ auto globalRef = jni::make_global(instance);
+ return JNISharedPtr::make_shared_from_jni(globalRef);
+ }
+ );
+ });
+}
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.hpp
similarity index 58%
rename from packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.hpp
rename to packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.hpp
index 75e0a1b..1935b46 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.hpp
@@ -1,25 +1,25 @@
///
-/// ReactNativeFastWSOnLoad.hpp
-/// Fri Nov 01 2024
+/// FastWebSocketOnLoad.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///
#include
+#include
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
/**
- * Initializes the native (C++) part of ReactNativeFastWS, and autolinks all Hybrid Objects.
+ * Initializes the native (C++) part of FastWebSocket, and autolinks all Hybrid Objects.
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
* Example:
* ```cpp (cpp-adapter.cpp)
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
- * return margelo::nitro::grabbou::initialize(vm);
+ * return margelo::nitro::websocket::initialize(vm);
* }
* ```
*/
int initialize(JavaVM* vm);
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.kt b/packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.kt
similarity index 100%
rename from packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.kt
rename to packages/react-native-fast-ws/nitrogen/generated/android/FastWebSocketOnLoad.kt
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.cpp b/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.cpp
deleted file mode 100644
index 2033807..0000000
--- a/packages/react-native-fast-ws/nitrogen/generated/android/ReactNativeFastWSOnLoad.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-///
-/// ReactNativeFastWSOnLoad.cpp
-/// Fri Nov 01 2024
-/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
-/// https://github.com/mrousavy/nitro
-/// Copyright © 2024 Marc Rousavy @ Margelo
-///
-
-#include "ReactNativeFastWSOnLoad.hpp"
-
-#include
-#include
-#include
-
-
-
-namespace margelo::nitro::grabbou {
-
-int initialize(JavaVM* vm) {
- using namespace margelo::nitro;
- using namespace margelo::nitro::grabbou;
- using namespace facebook;
-
- return facebook::jni::initialize(vm, [] {
- // Register native JNI methods
-
-
- // Register Nitro Hybrid Objects
-
- });
-}
-
-} // namespace margelo::nitro::grabbou
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp
new file mode 100644
index 0000000..043288c
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_double_std__string.hpp
@@ -0,0 +1,49 @@
+///
+/// JFunc_void_double_std__string.hpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#pragma once
+
+#include
+#include
+
+#include
+#include
+
+namespace margelo::nitro::websocket {
+
+ using namespace facebook;
+
+ /**
+ * C++ representation of the callback Func_void_double_std__string.
+ * This is a Kotlin `(code: Double, reason: String) -> Unit`, backed by a `std::function<...>`.
+ */
+ struct JFunc_void_double_std__string final: public jni::HybridClass {
+ public:
+ static jni::local_ref fromCpp(const std::function& func) {
+ return JFunc_void_double_std__string::newObjectCxxArgs(func);
+ }
+
+ public:
+ void call(double code, jni::alias_ref reason) {
+ return _func(code, reason->toStdString());
+ }
+
+ public:
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/websocket/Func_void_double_std__string;";
+ static void registerNatives() {
+ registerHybrid({makeNativeMethod("call", JFunc_void_double_std__string::call)});
+ }
+
+ private:
+ explicit JFunc_void_double_std__string(const std::function& func): _func(func) { }
+
+ private:
+ friend HybridBase;
+ std::function _func;
+ };
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__shared_ptr_ArrayBuffer_.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__shared_ptr_ArrayBuffer_.hpp
new file mode 100644
index 0000000..72a68df
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__shared_ptr_ArrayBuffer_.hpp
@@ -0,0 +1,50 @@
+///
+/// JFunc_void_std__shared_ptr_ArrayBuffer_.hpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#pragma once
+
+#include
+#include
+
+#include
+#include
+#include
+
+namespace margelo::nitro::websocket {
+
+ using namespace facebook;
+
+ /**
+ * C++ representation of the callback Func_void_std__shared_ptr_ArrayBuffer_.
+ * This is a Kotlin `(buffer: ArrayBuffer) -> Unit`, backed by a `std::function<...>`.
+ */
+ struct JFunc_void_std__shared_ptr_ArrayBuffer_ final: public jni::HybridClass {
+ public:
+ static jni::local_ref fromCpp(const std::function& /* buffer */)>& func) {
+ return JFunc_void_std__shared_ptr_ArrayBuffer_::newObjectCxxArgs(func);
+ }
+
+ public:
+ void call(jni::alias_ref buffer) {
+ return _func(buffer->cthis()->getArrayBuffer());
+ }
+
+ public:
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/websocket/Func_void_std__shared_ptr_ArrayBuffer_;";
+ static void registerNatives() {
+ registerHybrid({makeNativeMethod("call", JFunc_void_std__shared_ptr_ArrayBuffer_::call)});
+ }
+
+ private:
+ explicit JFunc_void_std__shared_ptr_ArrayBuffer_(const std::function& /* buffer */)>& func): _func(func) { }
+
+ private:
+ friend HybridBase;
+ std::function& /* buffer */)> _func;
+ };
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__string.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__string.hpp
new file mode 100644
index 0000000..c82e85a
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JFunc_void_std__string.hpp
@@ -0,0 +1,49 @@
+///
+/// JFunc_void_std__string.hpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#pragma once
+
+#include
+#include
+
+#include
+#include
+
+namespace margelo::nitro::websocket {
+
+ using namespace facebook;
+
+ /**
+ * C++ representation of the callback Func_void_std__string.
+ * This is a Kotlin `(message: String) -> Unit`, backed by a `std::function<...>`.
+ */
+ struct JFunc_void_std__string final: public jni::HybridClass {
+ public:
+ static jni::local_ref fromCpp(const std::function& func) {
+ return JFunc_void_std__string::newObjectCxxArgs(func);
+ }
+
+ public:
+ void call(jni::alias_ref message) {
+ return _func(message->toStdString());
+ }
+
+ public:
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/websocket/Func_void_std__string;";
+ static void registerNatives() {
+ registerHybrid({makeNativeMethod("call", JFunc_void_std__string::call)});
+ }
+
+ private:
+ explicit JFunc_void_std__string(const std::function& func): _func(func) { }
+
+ private:
+ friend HybridBase;
+ std::function _func;
+ };
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.cpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.cpp
new file mode 100644
index 0000000..33ebb52
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.cpp
@@ -0,0 +1,55 @@
+///
+/// JHybridWebSocketManagerSpec.cpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#include "JHybridWebSocketManagerSpec.hpp"
+
+// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
+namespace margelo::nitro::websocket { class HybridWebSocketSpec; }
+
+#include
+#include "HybridWebSocketSpec.hpp"
+#include "JHybridWebSocketSpec.hpp"
+#include
+#include
+#include
+
+namespace margelo::nitro::websocket {
+
+ jni::local_ref JHybridWebSocketManagerSpec::initHybrid(jni::alias_ref jThis) {
+ return makeCxxInstance(jThis);
+ }
+
+ void JHybridWebSocketManagerSpec::registerNatives() {
+ registerHybrid({
+ makeNativeMethod("initHybrid", JHybridWebSocketManagerSpec::initHybrid),
+ });
+ }
+
+ size_t JHybridWebSocketManagerSpec::getExternalMemorySize() noexcept {
+ static const auto method = _javaPart->getClass()->getMethod("getMemorySize");
+ return method(_javaPart);
+ }
+
+ // Properties
+
+
+ // Methods
+ std::shared_ptr JHybridWebSocketManagerSpec::create(const std::string& url, const std::vector& protocols) {
+ static const auto method = _javaPart->getClass()->getMethod(jni::alias_ref /* url */, jni::alias_ref> /* protocols */)>("create");
+ auto __result = method(_javaPart, jni::make_jstring(url), [&]() {
+ size_t __size = protocols.size();
+ jni::local_ref> __array = jni::JArrayClass::newArray(__size);
+ for (size_t __i = 0; __i < __size; __i++) {
+ const auto& __element = protocols[__i];
+ __array->setElement(__i, *jni::make_jstring(__element));
+ }
+ return __array;
+ }());
+ return JNISharedPtr::make_shared_from_jni(jni::make_global(__result));
+ }
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.hpp
new file mode 100644
index 0000000..cc47175
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketManagerSpec.hpp
@@ -0,0 +1,56 @@
+///
+/// HybridWebSocketManagerSpec.hpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#pragma once
+
+#include
+#include
+#include "HybridWebSocketManagerSpec.hpp"
+
+
+
+
+namespace margelo::nitro::websocket {
+
+ using namespace facebook;
+
+ class JHybridWebSocketManagerSpec: public jni::HybridClass,
+ public virtual HybridWebSocketManagerSpec {
+ public:
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/websocket/HybridWebSocketManagerSpec;";
+ static jni::local_ref initHybrid(jni::alias_ref jThis);
+ static void registerNatives();
+
+ protected:
+ // C++ constructor (called from Java via `initHybrid()`)
+ explicit JHybridWebSocketManagerSpec(jni::alias_ref jThis) :
+ HybridObject(HybridWebSocketManagerSpec::TAG),
+ _javaPart(jni::make_global(jThis)) {}
+
+ public:
+ size_t getExternalMemorySize() noexcept override;
+
+ public:
+ inline const jni::global_ref& getJavaPart() const noexcept {
+ return _javaPart;
+ }
+
+ public:
+ // Properties
+
+
+ public:
+ // Methods
+ std::shared_ptr create(const std::string& url, const std::vector& protocols) override;
+
+ private:
+ friend HybridBase;
+ using HybridBase::HybridBase;
+ jni::global_ref _javaPart;
+ };
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.cpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.cpp
new file mode 100644
index 0000000..2b7c79e
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.cpp
@@ -0,0 +1,83 @@
+///
+/// JHybridWebSocketSpec.cpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#include "JHybridWebSocketSpec.hpp"
+
+// Forward declaration of `ArrayBuffer` to properly resolve imports.
+namespace NitroModules { class ArrayBuffer; }
+
+#include
+#include
+#include
+#include
+#include "JFunc_void_std__string.hpp"
+#include "JFunc_void_double_std__string.hpp"
+#include "JFunc_void_std__shared_ptr_ArrayBuffer_.hpp"
+
+namespace margelo::nitro::websocket {
+
+ jni::local_ref JHybridWebSocketSpec::initHybrid(jni::alias_ref jThis) {
+ return makeCxxInstance(jThis);
+ }
+
+ void JHybridWebSocketSpec::registerNatives() {
+ registerHybrid({
+ makeNativeMethod("initHybrid", JHybridWebSocketSpec::initHybrid),
+ });
+ }
+
+ size_t JHybridWebSocketSpec::getExternalMemorySize() noexcept {
+ static const auto method = _javaPart->getClass()->getMethod("getMemorySize");
+ return method(_javaPart);
+ }
+
+ // Properties
+
+
+ // Methods
+ void JHybridWebSocketSpec::send(const std::string& message) {
+ static const auto method = _javaPart->getClass()->getMethod /* message */)>("send");
+ method(_javaPart, jni::make_jstring(message));
+ }
+ void JHybridWebSocketSpec::sendArrayBuffer(const std::shared_ptr& buffer) {
+ static const auto method = _javaPart->getClass()->getMethod /* buffer */)>("sendArrayBuffer");
+ method(_javaPart, JArrayBuffer::wrap(buffer));
+ }
+ void JHybridWebSocketSpec::connect() {
+ static const auto method = _javaPart->getClass()->getMethod("connect");
+ method(_javaPart);
+ }
+ void JHybridWebSocketSpec::close() {
+ static const auto method = _javaPart->getClass()->getMethod("close");
+ method(_javaPart);
+ }
+ void JHybridWebSocketSpec::ping() {
+ static const auto method = _javaPart->getClass()->getMethod("ping");
+ method(_javaPart);
+ }
+ void JHybridWebSocketSpec::onOpen(const std::function& callback) {
+ static const auto method = _javaPart->getClass()->getMethod /* callback */)>("onOpen");
+ method(_javaPart, JFunc_void_std__string::fromCpp(callback));
+ }
+ void JHybridWebSocketSpec::onClose(const std::function& callback) {
+ static const auto method = _javaPart->getClass()->getMethod /* callback */)>("onClose");
+ method(_javaPart, JFunc_void_double_std__string::fromCpp(callback));
+ }
+ void JHybridWebSocketSpec::onError(const std::function& callback) {
+ static const auto method = _javaPart->getClass()->getMethod /* callback */)>("onError");
+ method(_javaPart, JFunc_void_std__string::fromCpp(callback));
+ }
+ void JHybridWebSocketSpec::onMessage(const std::function& callback) {
+ static const auto method = _javaPart->getClass()->getMethod /* callback */)>("onMessage");
+ method(_javaPart, JFunc_void_std__string::fromCpp(callback));
+ }
+ void JHybridWebSocketSpec::onArrayBuffer(const std::function& /* buffer */)>& callback) {
+ static const auto method = _javaPart->getClass()->getMethod /* callback */)>("onArrayBuffer");
+ method(_javaPart, JFunc_void_std__shared_ptr_ArrayBuffer_::fromCpp(callback));
+ }
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.hpp b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.hpp
new file mode 100644
index 0000000..966203d
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/c++/JHybridWebSocketSpec.hpp
@@ -0,0 +1,65 @@
+///
+/// HybridWebSocketSpec.hpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#pragma once
+
+#include
+#include
+#include "HybridWebSocketSpec.hpp"
+
+
+
+
+namespace margelo::nitro::websocket {
+
+ using namespace facebook;
+
+ class JHybridWebSocketSpec: public jni::HybridClass,
+ public virtual HybridWebSocketSpec {
+ public:
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/websocket/HybridWebSocketSpec;";
+ static jni::local_ref initHybrid(jni::alias_ref jThis);
+ static void registerNatives();
+
+ protected:
+ // C++ constructor (called from Java via `initHybrid()`)
+ explicit JHybridWebSocketSpec(jni::alias_ref jThis) :
+ HybridObject(HybridWebSocketSpec::TAG),
+ _javaPart(jni::make_global(jThis)) {}
+
+ public:
+ size_t getExternalMemorySize() noexcept override;
+
+ public:
+ inline const jni::global_ref& getJavaPart() const noexcept {
+ return _javaPart;
+ }
+
+ public:
+ // Properties
+
+
+ public:
+ // Methods
+ void send(const std::string& message) override;
+ void sendArrayBuffer(const std::shared_ptr& buffer) override;
+ void connect() override;
+ void close() override;
+ void ping() override;
+ void onOpen(const std::function& callback) override;
+ void onClose(const std::function& callback) override;
+ void onError(const std::function& callback) override;
+ void onMessage(const std::function& callback) override;
+ void onArrayBuffer(const std::function& /* buffer */)>& callback) override;
+
+ private:
+ friend HybridBase;
+ using HybridBase::HybridBase;
+ jni::global_ref _javaPart;
+ };
+
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_double_std__string.kt b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_double_std__string.kt
new file mode 100644
index 0000000..53c9b02
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_double_std__string.kt
@@ -0,0 +1,45 @@
+///
+/// Func_void_double_std__string.kt
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+package com.margelo.nitro.websocket
+
+import androidx.annotation.Keep
+import com.facebook.jni.HybridData
+import com.facebook.proguard.annotations.DoNotStrip
+import dalvik.annotation.optimization.FastNative
+
+/**
+ * Represents the JavaScript callback `(code: number, reason: string) => void`.
+ * This is implemented in C++, via a `std::function<...>`.
+ */
+@DoNotStrip
+@Keep
+@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused")
+class Func_void_double_std__string {
+ @DoNotStrip
+ @Keep
+ private val mHybridData: HybridData
+
+ @DoNotStrip
+ @Keep
+ private constructor(hybridData: HybridData) {
+ mHybridData = hybridData
+ }
+
+ /**
+ * Converts this function to a Kotlin Lambda.
+ * This exists purely as syntactic sugar, and has minimal runtime overhead.
+ */
+ fun toLambda(): (code: Double, reason: String) -> Unit = this::call
+
+ /**
+ * Call the given JS callback.
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
+ */
+ @FastNative
+ external fun call(code: Double, reason: String): Unit
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__shared_ptr_ArrayBuffer_.kt b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__shared_ptr_ArrayBuffer_.kt
new file mode 100644
index 0000000..72b6395
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__shared_ptr_ArrayBuffer_.kt
@@ -0,0 +1,46 @@
+///
+/// Func_void_std__shared_ptr_ArrayBuffer_.kt
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+package com.margelo.nitro.websocket
+
+import androidx.annotation.Keep
+import com.facebook.jni.HybridData
+import com.facebook.proguard.annotations.DoNotStrip
+import com.margelo.nitro.core.ArrayBuffer
+import dalvik.annotation.optimization.FastNative
+
+/**
+ * Represents the JavaScript callback `(buffer: array-buffer) => void`.
+ * This is implemented in C++, via a `std::function<...>`.
+ */
+@DoNotStrip
+@Keep
+@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused")
+class Func_void_std__shared_ptr_ArrayBuffer_ {
+ @DoNotStrip
+ @Keep
+ private val mHybridData: HybridData
+
+ @DoNotStrip
+ @Keep
+ private constructor(hybridData: HybridData) {
+ mHybridData = hybridData
+ }
+
+ /**
+ * Converts this function to a Kotlin Lambda.
+ * This exists purely as syntactic sugar, and has minimal runtime overhead.
+ */
+ fun toLambda(): (buffer: ArrayBuffer) -> Unit = this::call
+
+ /**
+ * Call the given JS callback.
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
+ */
+ @FastNative
+ external fun call(buffer: ArrayBuffer): Unit
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__string.kt b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__string.kt
new file mode 100644
index 0000000..3e53d98
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/Func_void_std__string.kt
@@ -0,0 +1,45 @@
+///
+/// Func_void_std__string.kt
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+package com.margelo.nitro.websocket
+
+import androidx.annotation.Keep
+import com.facebook.jni.HybridData
+import com.facebook.proguard.annotations.DoNotStrip
+import dalvik.annotation.optimization.FastNative
+
+/**
+ * Represents the JavaScript callback `(message: string) => void`.
+ * This is implemented in C++, via a `std::function<...>`.
+ */
+@DoNotStrip
+@Keep
+@Suppress("RedundantSuppression", "ConvertSecondaryConstructorToPrimary", "RedundantUnitReturnType", "KotlinJniMissingFunction", "ClassName", "unused")
+class Func_void_std__string {
+ @DoNotStrip
+ @Keep
+ private val mHybridData: HybridData
+
+ @DoNotStrip
+ @Keep
+ private constructor(hybridData: HybridData) {
+ mHybridData = hybridData
+ }
+
+ /**
+ * Converts this function to a Kotlin Lambda.
+ * This exists purely as syntactic sugar, and has minimal runtime overhead.
+ */
+ fun toLambda(): (message: String) -> Unit = this::call
+
+ /**
+ * Call the given JS callback.
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
+ */
+ @FastNative
+ external fun call(message: String): Unit
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketManagerSpec.kt b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketManagerSpec.kt
new file mode 100644
index 0000000..3f93c18
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketManagerSpec.kt
@@ -0,0 +1,64 @@
+///
+/// HybridWebSocketManagerSpec.kt
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+package com.margelo.nitro.websocket
+
+import android.util.Log
+import androidx.annotation.Keep
+import com.facebook.jni.HybridData
+import com.facebook.proguard.annotations.DoNotStrip
+import com.margelo.nitro.core.*
+
+/**
+ * A Kotlin class representing the WebSocketManager HybridObject.
+ * Implement this abstract class to create Kotlin-based instances of WebSocketManager.
+ */
+@DoNotStrip
+@Keep
+@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused")
+abstract class HybridWebSocketManagerSpec: HybridObject() {
+ @DoNotStrip
+ private var mHybridData: HybridData = initHybrid()
+
+ init {
+ // Pass this `HybridData` through to it's base class,
+ // to represent inheritance to JHybridObject on C++ side
+ super.updateNative(mHybridData)
+ }
+
+ /**
+ * Call from a child class to initialize HybridData with a child.
+ */
+ override fun updateNative(hybridData: HybridData) {
+ mHybridData = hybridData
+ }
+
+ // Properties
+
+
+ // Methods
+ @DoNotStrip
+ @Keep
+ abstract fun create(url: String, protocols: Array): HybridWebSocketSpec
+
+ private external fun initHybrid(): HybridData
+
+ companion object {
+ private const val TAG = "HybridWebSocketManagerSpec"
+ init {
+ try {
+ Log.i(TAG, "Loading FastWebSocket C++ library...")
+ System.loadLibrary("FastWebSocket")
+ Log.i(TAG, "Successfully loaded FastWebSocket C++ library!")
+ } catch (e: Error) {
+ Log.e(TAG, "Failed to load FastWebSocket C++ library! Is it properly installed and linked? " +
+ "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
+ throw e
+ }
+ }
+ }
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketSpec.kt b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketSpec.kt
new file mode 100644
index 0000000..4367a7c
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/android/kotlin/com/margelo/nitro/websocket/HybridWebSocketSpec.kt
@@ -0,0 +1,135 @@
+///
+/// HybridWebSocketSpec.kt
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+package com.margelo.nitro.websocket
+
+import android.util.Log
+import androidx.annotation.Keep
+import com.facebook.jni.HybridData
+import com.facebook.proguard.annotations.DoNotStrip
+import com.margelo.nitro.core.*
+
+/**
+ * A Kotlin class representing the WebSocket HybridObject.
+ * Implement this abstract class to create Kotlin-based instances of WebSocket.
+ */
+@DoNotStrip
+@Keep
+@Suppress("RedundantSuppression", "KotlinJniMissingFunction", "PropertyName", "RedundantUnitReturnType", "unused")
+abstract class HybridWebSocketSpec: HybridObject() {
+ @DoNotStrip
+ private var mHybridData: HybridData = initHybrid()
+
+ init {
+ // Pass this `HybridData` through to it's base class,
+ // to represent inheritance to JHybridObject on C++ side
+ super.updateNative(mHybridData)
+ }
+
+ /**
+ * Call from a child class to initialize HybridData with a child.
+ */
+ override fun updateNative(hybridData: HybridData) {
+ mHybridData = hybridData
+ }
+
+ // Properties
+
+
+ // Methods
+ @DoNotStrip
+ @Keep
+ abstract fun send(message: String): Unit
+
+ @DoNotStrip
+ @Keep
+ abstract fun sendArrayBuffer(buffer: ArrayBuffer): Unit
+
+ @DoNotStrip
+ @Keep
+ abstract fun connect(): Unit
+
+ @DoNotStrip
+ @Keep
+ abstract fun close(): Unit
+
+ @DoNotStrip
+ @Keep
+ abstract fun ping(): Unit
+
+ @DoNotStrip
+ @Keep
+ abstract fun onOpen(callback: (selectedProtocol: String) -> Unit): Unit
+
+ @DoNotStrip
+ @Keep
+ private fun onOpen(callback: Func_void_std__string): Unit {
+ val __result = onOpen(callback.toLambda())
+ return __result
+ }
+
+ @DoNotStrip
+ @Keep
+ abstract fun onClose(callback: (code: Double, reason: String) -> Unit): Unit
+
+ @DoNotStrip
+ @Keep
+ private fun onClose(callback: Func_void_double_std__string): Unit {
+ val __result = onClose(callback.toLambda())
+ return __result
+ }
+
+ @DoNotStrip
+ @Keep
+ abstract fun onError(callback: (error: String) -> Unit): Unit
+
+ @DoNotStrip
+ @Keep
+ private fun onError(callback: Func_void_std__string): Unit {
+ val __result = onError(callback.toLambda())
+ return __result
+ }
+
+ @DoNotStrip
+ @Keep
+ abstract fun onMessage(callback: (message: String) -> Unit): Unit
+
+ @DoNotStrip
+ @Keep
+ private fun onMessage(callback: Func_void_std__string): Unit {
+ val __result = onMessage(callback.toLambda())
+ return __result
+ }
+
+ @DoNotStrip
+ @Keep
+ abstract fun onArrayBuffer(callback: (buffer: ArrayBuffer) -> Unit): Unit
+
+ @DoNotStrip
+ @Keep
+ private fun onArrayBuffer(callback: Func_void_std__shared_ptr_ArrayBuffer_): Unit {
+ val __result = onArrayBuffer(callback.toLambda())
+ return __result
+ }
+
+ private external fun initHybrid(): HybridData
+
+ companion object {
+ private const val TAG = "HybridWebSocketSpec"
+ init {
+ try {
+ Log.i(TAG, "Loading FastWebSocket C++ library...")
+ System.loadLibrary("FastWebSocket")
+ Log.i(TAG, "Successfully loaded FastWebSocket C++ library!")
+ } catch (e: Error) {
+ Log.e(TAG, "Failed to load FastWebSocket C++ library! Is it properly installed and linked? " +
+ "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
+ throw e
+ }
+ }
+ }
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS+autolinking.rb b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket+autolinking.rb
similarity index 72%
rename from packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS+autolinking.rb
rename to packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket+autolinking.rb
index 4b50f28..34d9645 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS+autolinking.rb
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket+autolinking.rb
@@ -1,6 +1,5 @@
#
-# ReactNativeFastWS+autolinking.rb
-# Fri Nov 01 2024
+# FastWebSocket+autolinking.rb
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
# https://github.com/mrousavy/nitro
# Copyright © 2024 Marc Rousavy @ Margelo
@@ -15,17 +14,17 @@
# # ...
#
# # Add all files generated by Nitrogen
-# load 'nitrogen/generated/ios/ReactNativeFastWS+autolinking.rb'
+# load 'nitrogen/generated/ios/FastWebSocket+autolinking.rb'
# add_nitrogen_files(spec)
# end
# ```
def add_nitrogen_files(spec)
- Pod::UI.puts "[NitroModules] Adding ReactNativeFastWS specs..."
+ Pod::UI.puts "[NitroModules] Adding FastWebSocket specs..."
spec.dependency "NitroModules"
- current_source_files = spec.attributes_hash['source_files'] || []
+ current_source_files = Array(spec.attributes_hash['source_files'])
spec.source_files = current_source_files + [
# Generated cross-platform specs
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
@@ -33,15 +32,15 @@ def add_nitrogen_files(spec)
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
]
- current_public_header_files = spec.attributes_hash['public_header_files'] || []
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
spec.public_header_files = current_public_header_files + [
# Generated specs
"nitrogen/generated/shared/**/*.{h,hpp}",
# Swift to C++ bridging helpers
- "nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.hpp"
+ "nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.hpp"
]
- current_private_header_files = spec.attributes_hash['private_header_files'] || []
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
spec.private_header_files = current_private_header_files + [
# iOS specific specs
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
@@ -53,5 +52,7 @@ def add_nitrogen_files(spec)
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
# Enables C++ <-> Swift interop (by default it's only C)
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
+ # Enables stricter modular headers
+ "DEFINES_MODULE" => "YES",
})
end
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.cpp b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.cpp
new file mode 100644
index 0000000..3e3be1d
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.cpp
@@ -0,0 +1,50 @@
+///
+/// FastWebSocket-Swift-Cxx-Bridge.cpp
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+#include "FastWebSocket-Swift-Cxx-Bridge.hpp"
+
+// Include C++ implementation defined types
+#include "FastWebSocket-Swift-Cxx-Umbrella.hpp"
+#include "HybridWebSocketManagerSpecSwift.hpp"
+#include "HybridWebSocketSpecSwift.hpp"
+#include
+
+namespace margelo::nitro::websocket::bridge::swift {
+
+ // pragma MARK: std::shared_ptr
+ std::shared_ptr create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_(void* _Nonnull swiftUnsafePointer) {
+ FastWebSocket::HybridWebSocketSpecCxx swiftPart = FastWebSocket::HybridWebSocketSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer);
+ return HybridContext::getOrCreate(swiftPart);
+ }
+ void* _Nonnull get_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_(std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_ cppType) {
+ std::shared_ptr swiftWrapper = std::dynamic_pointer_cast(cppType);
+ #ifdef NITRO_DEBUG
+ if (swiftWrapper == nullptr) [[unlikely]] {
+ throw std::runtime_error("Class \"HybridWebSocketSpec\" is not implemented in Swift!");
+ }
+ #endif
+ FastWebSocket::HybridWebSocketSpecCxx swiftPart = swiftWrapper->getSwiftPart();
+ return FastWebSocket::HybridWebSocketSpecCxxUnsafe::toUnsafe(swiftPart);
+ }
+
+ // pragma MARK: std::shared_ptr
+ std::shared_ptr create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_(void* _Nonnull swiftUnsafePointer) {
+ FastWebSocket::HybridWebSocketManagerSpecCxx swiftPart = FastWebSocket::HybridWebSocketManagerSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer);
+ return HybridContext::getOrCreate(swiftPart);
+ }
+ void* _Nonnull get_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_(std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_ cppType) {
+ std::shared_ptr swiftWrapper = std::dynamic_pointer_cast(cppType);
+ #ifdef NITRO_DEBUG
+ if (swiftWrapper == nullptr) [[unlikely]] {
+ throw std::runtime_error("Class \"HybridWebSocketManagerSpec\" is not implemented in Swift!");
+ }
+ #endif
+ FastWebSocket::HybridWebSocketManagerSpecCxx swiftPart = swiftWrapper->getSwiftPart();
+ return FastWebSocket::HybridWebSocketManagerSpecCxxUnsafe::toUnsafe(swiftPart);
+ }
+
+} // namespace margelo::nitro::websocket::bridge::swift
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.hpp b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.hpp
similarity index 53%
rename from packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.hpp
rename to packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.hpp
index fd2803b..78760a5 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Bridge.hpp
@@ -1,6 +1,5 @@
///
-/// ReactNativeFastWS-Swift-Cxx-Bridge.hpp
-/// Fri Nov 01 2024
+/// FastWebSocket-Swift-Cxx-Bridge.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -13,33 +12,34 @@
namespace NitroModules { class ArrayBufferHolder; }
// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
+// Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports.
+namespace margelo::nitro::websocket { class HybridWebSocketManagerSpec; }
+// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
+namespace margelo::nitro::websocket { class HybridWebSocketSpec; }
+
+// Forward declarations of Swift defined types
+// Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports.
+namespace FastWebSocket { class HybridWebSocketManagerSpecCxx; }
+// Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports.
+namespace FastWebSocket { class HybridWebSocketSpecCxx; }
// Include C++ defined types
-#if __has_include()
- #include
-#endif
-#if __has_include()
- #include
-#endif
-#if __has_include()
- #include
-#endif
-#if __has_include()
- #include
-#endif
-#if __has_include()
- #include
-#endif
-#if __has_include()
- #include
-#endif
+#include "HybridWebSocketManagerSpec.hpp"
+#include "HybridWebSocketSpec.hpp"
+#include
+#include
+#include
+#include
+#include
+#include
/**
* Contains specialized versions of C++ templated types so they can be accessed from Swift,
* as well as helper functions to interact with those C++ types from Swift.
*/
-namespace margelo::nitro::grabbou::bridge::swift {
+namespace margelo::nitro::websocket::bridge::swift {
+ // pragma MARK: std::function
/**
* Specialized version of `std::function`.
*/
@@ -47,18 +47,17 @@ namespace margelo::nitro::grabbou::bridge::swift {
/**
* Wrapper class for a `std::function`, this can be used from Swift.
*/
- class Func_void_std__string_Wrapper {
+ class Func_void_std__string_Wrapper final {
public:
- explicit Func_void_std__string_Wrapper(const std::function& func): function(func) {}
- explicit Func_void_std__string_Wrapper(std::function&& func): function(std::move(func)) {}
-
- void call(std::string selectedProtocol) const {
- function(selectedProtocol);
+ explicit Func_void_std__string_Wrapper(const std::function& func): _function(func) {}
+ explicit Func_void_std__string_Wrapper(std::function&& func): _function(std::move(func)) {}
+ inline void call(std::string selectedProtocol) const {
+ _function(selectedProtocol);
}
-
- std::function function;
+ private:
+ std::function _function;
};
- inline Func_void_std__string create_Func_void_std__string(void* closureHolder, void(*call)(void* /* closureHolder */, std::string), void(*destroy)(void*)) {
+ inline Func_void_std__string create_Func_void_std__string(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, std::string), void(* _Nonnull destroy)(void* _Nonnull)) {
std::shared_ptr sharedClosureHolder(closureHolder, destroy);
return Func_void_std__string([sharedClosureHolder, call](const std::string& selectedProtocol) -> void {
call(sharedClosureHolder.get(), selectedProtocol);
@@ -68,6 +67,7 @@ namespace margelo::nitro::grabbou::bridge::swift {
return std::make_shared(value);
}
+ // pragma MARK: std::function
/**
* Specialized version of `std::function`.
*/
@@ -75,18 +75,17 @@ namespace margelo::nitro::grabbou::bridge::swift {
/**
* Wrapper class for a `std::function`, this can be used from Swift.
*/
- class Func_void_double_std__string_Wrapper {
+ class Func_void_double_std__string_Wrapper final {
public:
- explicit Func_void_double_std__string_Wrapper(const std::function& func): function(func) {}
- explicit Func_void_double_std__string_Wrapper(std::function&& func): function(std::move(func)) {}
-
- void call(double code, std::string reason) const {
- function(code, reason);
+ explicit Func_void_double_std__string_Wrapper(const std::function& func): _function(func) {}
+ explicit Func_void_double_std__string_Wrapper(std::function&& func): _function(std::move(func)) {}
+ inline void call(double code, std::string reason) const {
+ _function(code, reason);
}
-
- std::function function;
+ private:
+ std::function _function;
};
- inline Func_void_double_std__string create_Func_void_double_std__string(void* closureHolder, void(*call)(void* /* closureHolder */, double, std::string), void(*destroy)(void*)) {
+ inline Func_void_double_std__string create_Func_void_double_std__string(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, double, std::string), void(* _Nonnull destroy)(void* _Nonnull)) {
std::shared_ptr sharedClosureHolder(closureHolder, destroy);
return Func_void_double_std__string([sharedClosureHolder, call](double code, const std::string& reason) -> void {
call(sharedClosureHolder.get(), code, reason);
@@ -96,6 +95,7 @@ namespace margelo::nitro::grabbou::bridge::swift {
return std::make_shared(value);
}
+ // pragma MARK: std::function& /* buffer */)>
/**
* Specialized version of `std::function&)>`.
*/
@@ -103,18 +103,17 @@ namespace margelo::nitro::grabbou::bridge::swift {
/**
* Wrapper class for a `std::function& / * buffer * /)>`, this can be used from Swift.
*/
- class Func_void_std__shared_ptr_ArrayBuffer__Wrapper {
+ class Func_void_std__shared_ptr_ArrayBuffer__Wrapper final {
public:
- explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(const std::function& /* buffer */)>& func): function(func) {}
- explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(std::function& /* buffer */)>&& func): function(std::move(func)) {}
-
- void call(ArrayBufferHolder buffer) const {
- function(buffer.getArrayBuffer());
+ explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(const std::function& /* buffer */)>& func): _function(func) {}
+ explicit Func_void_std__shared_ptr_ArrayBuffer__Wrapper(std::function& /* buffer */)>&& func): _function(std::move(func)) {}
+ inline void call(ArrayBufferHolder buffer) const {
+ _function(buffer.getArrayBuffer());
}
-
- std::function& /* buffer */)> function;
+ private:
+ std::function& /* buffer */)> _function;
};
- inline Func_void_std__shared_ptr_ArrayBuffer_ create_Func_void_std__shared_ptr_ArrayBuffer_(void* closureHolder, void(*call)(void* /* closureHolder */, ArrayBufferHolder), void(*destroy)(void*)) {
+ inline Func_void_std__shared_ptr_ArrayBuffer_ create_Func_void_std__shared_ptr_ArrayBuffer_(void* _Nonnull closureHolder, void(* _Nonnull call)(void* _Nonnull /* closureHolder */, ArrayBufferHolder), void(* _Nonnull destroy)(void* _Nonnull)) {
std::shared_ptr sharedClosureHolder(closureHolder, destroy);
return Func_void_std__shared_ptr_ArrayBuffer_([sharedClosureHolder, call](const std::shared_ptr& buffer) -> void {
call(sharedClosureHolder.get(), ArrayBufferHolder(buffer));
@@ -124,6 +123,15 @@ namespace margelo::nitro::grabbou::bridge::swift {
return std::make_shared(value);
}
+ // pragma MARK: std::shared_ptr
+ /**
+ * Specialized version of `std::shared_ptr`.
+ */
+ using std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_ = std::shared_ptr;
+ std::shared_ptr create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_(void* _Nonnull swiftUnsafePointer);
+ void* _Nonnull get_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_(std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_ cppType);
+
+ // pragma MARK: std::vector
/**
* Specialized version of `std::vector`.
*/
@@ -133,5 +141,13 @@ namespace margelo::nitro::grabbou::bridge::swift {
vector.reserve(size);
return vector;
}
+
+ // pragma MARK: std::shared_ptr
+ /**
+ * Specialized version of `std::shared_ptr`.
+ */
+ using std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_ = std::shared_ptr;
+ std::shared_ptr create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_(void* _Nonnull swiftUnsafePointer);
+ void* _Nonnull get_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_(std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_ cppType);
-} // namespace margelo::nitro::grabbou::bridge::swift
+} // namespace margelo::nitro::websocket::bridge::swift
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Umbrella.hpp b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Umbrella.hpp
similarity index 56%
rename from packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Umbrella.hpp
rename to packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Umbrella.hpp
index 47fb243..f3b2d66 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Umbrella.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocket-Swift-Cxx-Umbrella.hpp
@@ -1,6 +1,5 @@
///
-/// ReactNativeFastWS-Swift-Cxx-Umbrella.hpp
-/// Fri Nov 01 2024
+/// FastWebSocket-Swift-Cxx-Umbrella.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -11,10 +10,13 @@
// Forward declarations of C++ defined types
// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
+// Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports.
+namespace margelo::nitro::websocket { class HybridWebSocketManagerSpec; }
// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
-namespace margelo::nitro::grabbou { class HybridWebSocketSpec; }
+namespace margelo::nitro::websocket { class HybridWebSocketSpec; }
// Include C++ defined types
+#include "HybridWebSocketManagerSpec.hpp"
#include "HybridWebSocketSpec.hpp"
#include
#include
@@ -23,7 +25,7 @@ namespace margelo::nitro::grabbou { class HybridWebSocketSpec; }
#include
// C++ helpers for Swift
-#include "ReactNativeFastWS-Swift-Cxx-Bridge.hpp"
+#include "FastWebSocket-Swift-Cxx-Bridge.hpp"
// Common C++ types used in Swift
#include
@@ -32,14 +34,16 @@ namespace margelo::nitro::grabbou { class HybridWebSocketSpec; }
#include
// Forward declarations of Swift defined types
+// Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports.
+namespace FastWebSocket { class HybridWebSocketManagerSpecCxx; }
// Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports.
-namespace ReactNativeFastWS { class HybridWebSocketSpecCxx; }
+namespace FastWebSocket { class HybridWebSocketSpecCxx; }
// Include Swift defined types
-#if __has_include("ReactNativeFastWS-Swift.h")
+#if __has_include("FastWebSocket-Swift.h")
// This header is generated by Xcode/Swift on every app build.
-// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "ReactNativeFastWS".
-#include "ReactNativeFastWS-Swift.h"
+// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "FastWebSocket".
+#include "FastWebSocket-Swift.h"
#else
-#error ReactNativeFastWS's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "ReactNativeFastWS", and try building the app first.
+#error FastWebSocket's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "FastWebSocket", and try building the app first.
#endif
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.mm b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.mm
similarity index 55%
rename from packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.mm
rename to packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.mm
index 637bfb1..e29f4d7 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.mm
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.mm
@@ -1,6 +1,5 @@
///
-/// ReactNativeFastWSAutolinking.mm
-/// Fri Nov 01 2024
+/// FastWebSocketAutolinking.mm
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -8,25 +7,25 @@
#import
#import
-#import "ReactNativeFastWS-Swift-Cxx-Umbrella.hpp"
+#import "FastWebSocket-Swift-Cxx-Umbrella.hpp"
#import
#include "HybridWebSocketManagerSpecSwift.hpp"
-@interface ReactNativeFastWSAutolinking : NSObject
+@interface FastWebSocketAutolinking : NSObject
@end
-@implementation ReactNativeFastWSAutolinking
+@implementation FastWebSocketAutolinking
+ (void) load {
using namespace margelo::nitro;
- using namespace margelo::nitro::grabbou;
+ using namespace margelo::nitro::websocket;
HybridObjectRegistry::registerHybridObjectConstructor(
"WebSocketManager",
[]() -> std::shared_ptr {
- auto swiftPart = ReactNativeFastWS::ReactNativeFastWSAutolinking::createWebSocketManager();
- return std::make_shared(swiftPart);
+ std::shared_ptr hybridObject = FastWebSocket::FastWebSocketAutolinking::createWebSocketManager();
+ return hybridObject;
}
);
}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.swift
new file mode 100644
index 0000000..bd74d38
--- /dev/null
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/FastWebSocketAutolinking.swift
@@ -0,0 +1,26 @@
+///
+/// FastWebSocketAutolinking.swift
+/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
+/// https://github.com/mrousavy/nitro
+/// Copyright © 2024 Marc Rousavy @ Margelo
+///
+
+public final class FastWebSocketAutolinking {
+ public typealias bridge = margelo.nitro.websocket.bridge.swift
+
+ /**
+ * Creates an instance of a Swift class that implements `HybridWebSocketManagerSpec`,
+ * and wraps it in a Swift class that can directly interop with C++ (`HybridWebSocketManagerSpecCxx`)
+ *
+ * This is generated by Nitrogen and will initialize the class specified
+ * in the `"autolinking"` property of `nitro.json` (in this case, `HybridWebSocketManager`).
+ */
+ public static func createWebSocketManager() -> bridge.std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_ {
+ let hybridObject = HybridWebSocketManager()
+ return { () -> bridge.std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_ in
+ let __cxxWrapped = HybridWebSocketManagerSpecCxx(hybridObject)
+ let __pointer = HybridWebSocketManagerSpecCxxUnsafe.toUnsafe(__cxxWrapped)
+ return bridge.create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketManagerSpec_(__pointer)
+ }()
+ }
+}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.cpp b/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.cpp
deleted file mode 100644
index 7e9b366..0000000
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWS-Swift-Cxx-Bridge.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-///
-/// ReactNativeFastWS-Swift-Cxx-Bridge.cpp
-/// Fri Nov 01 2024
-/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
-/// https://github.com/mrousavy/nitro
-/// Copyright © 2024 Marc Rousavy @ Margelo
-///
-
-#include "ReactNativeFastWS-Swift-Cxx-Bridge.hpp"
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.swift
deleted file mode 100644
index 26426ab..0000000
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/ReactNativeFastWSAutolinking.swift
+++ /dev/null
@@ -1,21 +0,0 @@
-///
-/// ReactNativeFastWSAutolinking.swift
-/// Fri Nov 01 2024
-/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
-/// https://github.com/mrousavy/nitro
-/// Copyright © 2024 Marc Rousavy @ Margelo
-///
-
-public final class ReactNativeFastWSAutolinking {
- /**
- * Creates an instance of a Swift class that implements `HybridWebSocketManagerSpec`,
- * and wraps it in a Swift class that can directly interop with C++ (`HybridWebSocketManagerSpecCxx`)
- *
- * This is generated by Nitrogen and will initialize the class specified
- * in the `"autolinking"` property of `nitro.json` (in this case, `HybridWebSocketManager`).
- */
- public static func createWebSocketManager() -> HybridWebSocketManagerSpecCxx {
- let hybridObject = HybridWebSocketManager()
- return hybridObject.createCxxBridge()
- }
-}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.cpp b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.cpp
index bf9d554..c654ee0 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.cpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.cpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpecSwift.cpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -8,5 +7,5 @@
#include "HybridWebSocketManagerSpecSwift.hpp"
-namespace margelo::nitro::grabbou {
-} // namespace margelo::nitro::grabbou
+namespace margelo::nitro::websocket {
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.hpp b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.hpp
index e0f4be4..afa33ee 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketManagerSpecSwift.hpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpecSwift.hpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -11,16 +10,13 @@
#include "HybridWebSocketManagerSpec.hpp"
// Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports.
-namespace ReactNativeFastWS { class HybridWebSocketManagerSpecCxx; }
+namespace FastWebSocket { class HybridWebSocketManagerSpecCxx; }
// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
-namespace margelo::nitro::grabbou { class HybridWebSocketSpec; }
-// Forward declaration of `HybridWebSocketSpecSwift` to properly resolve imports.
-namespace margelo::nitro::grabbou { class HybridWebSocketSpecSwift; }
+namespace margelo::nitro::websocket { class HybridWebSocketSpec; }
#include
#include "HybridWebSocketSpec.hpp"
-#include "HybridWebSocketSpecSwift.hpp"
#include
#include
@@ -30,9 +26,9 @@ namespace margelo::nitro::grabbou { class HybridWebSocketSpecSwift; }
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
-#include "ReactNativeFastWS-Swift-Cxx-Umbrella.hpp"
+#include "FastWebSocket-Swift-Cxx-Umbrella.hpp"
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
/**
* The C++ part of HybridWebSocketManagerSpecCxx.swift.
@@ -44,16 +40,16 @@ namespace margelo::nitro::grabbou {
* the future, HybridWebSocketManagerSpecCxx can directly inherit from the C++ class HybridWebSocketManagerSpec
* to simplify the whole structure and memory management.
*/
- class HybridWebSocketManagerSpecSwift final: public HybridWebSocketManagerSpec {
+ class HybridWebSocketManagerSpecSwift: public virtual HybridWebSocketManagerSpec {
public:
// Constructor from a Swift instance
- explicit HybridWebSocketManagerSpecSwift(const ReactNativeFastWS::HybridWebSocketManagerSpecCxx& swiftPart):
+ explicit HybridWebSocketManagerSpecSwift(const FastWebSocket::HybridWebSocketManagerSpecCxx& swiftPart):
HybridObject(HybridWebSocketManagerSpec::TAG),
_swiftPart(swiftPart) { }
public:
// Get the Swift part
- inline ReactNativeFastWS::HybridWebSocketManagerSpecCxx getSwiftPart() noexcept { return _swiftPart; }
+ inline FastWebSocket::HybridWebSocketManagerSpecCxx getSwiftPart() noexcept { return _swiftPart; }
public:
// Get memory pressure
@@ -67,13 +63,13 @@ namespace margelo::nitro::grabbou {
public:
// Methods
- inline std::shared_ptr create(const std::string& url, const std::vector& protocols) override {
+ inline std::shared_ptr create(const std::string& url, const std::vector& protocols) override {
auto __result = _swiftPart.create(url, protocols);
- return HybridContext::getOrCreate(__result);
+ return __result;
}
private:
- ReactNativeFastWS::HybridWebSocketManagerSpecCxx _swiftPart;
+ FastWebSocket::HybridWebSocketManagerSpecCxx _swiftPart;
};
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.cpp b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.cpp
index 1ce6f6c..e092a18 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.cpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.cpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpecSwift.cpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -8,5 +7,5 @@
#include "HybridWebSocketSpecSwift.hpp"
-namespace margelo::nitro::grabbou {
-} // namespace margelo::nitro::grabbou
+namespace margelo::nitro::websocket {
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.hpp b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.hpp
index 7f73322..cbd2383 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/c++/HybridWebSocketSpecSwift.hpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpecSwift.hpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -11,7 +10,7 @@
#include "HybridWebSocketSpec.hpp"
// Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports.
-namespace ReactNativeFastWS { class HybridWebSocketSpecCxx; }
+namespace FastWebSocket { class HybridWebSocketSpecCxx; }
// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
@@ -29,9 +28,9 @@ namespace NitroModules { class ArrayBufferHolder; }
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
-#include "ReactNativeFastWS-Swift-Cxx-Umbrella.hpp"
+#include "FastWebSocket-Swift-Cxx-Umbrella.hpp"
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
/**
* The C++ part of HybridWebSocketSpecCxx.swift.
@@ -43,16 +42,16 @@ namespace margelo::nitro::grabbou {
* the future, HybridWebSocketSpecCxx can directly inherit from the C++ class HybridWebSocketSpec
* to simplify the whole structure and memory management.
*/
- class HybridWebSocketSpecSwift final: public HybridWebSocketSpec {
+ class HybridWebSocketSpecSwift: public virtual HybridWebSocketSpec {
public:
// Constructor from a Swift instance
- explicit HybridWebSocketSpecSwift(const ReactNativeFastWS::HybridWebSocketSpecCxx& swiftPart):
+ explicit HybridWebSocketSpecSwift(const FastWebSocket::HybridWebSocketSpecCxx& swiftPart):
HybridObject(HybridWebSocketSpec::TAG),
_swiftPart(swiftPart) { }
public:
// Get the Swift part
- inline ReactNativeFastWS::HybridWebSocketSpecCxx getSwiftPart() noexcept { return _swiftPart; }
+ inline FastWebSocket::HybridWebSocketSpecCxx getSwiftPart() noexcept { return _swiftPart; }
public:
// Get memory pressure
@@ -98,7 +97,7 @@ namespace margelo::nitro::grabbou {
}
private:
- ReactNativeFastWS::HybridWebSocketSpecCxx _swiftPart;
+ FastWebSocket::HybridWebSocketSpecCxx _swiftPart;
};
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpec.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpec.swift
index 02c40c4..7ec47c6 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpec.swift
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpec.swift
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpec.swift
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -28,22 +27,10 @@ import NitroModules
* }
* ```
*/
-public protocol HybridWebSocketManagerSpec: HybridObjectSpec {
+public protocol HybridWebSocketManagerSpec: AnyObject, HybridObjectSpec {
// Properties
// Methods
- func create(url: String, protocols: [String]) throws -> HybridWebSocketSpec
-}
-
-public extension HybridWebSocketManagerSpec {
- /**
- * Create a new instance of HybridWebSocketManagerSpecCxx for the given HybridWebSocketManagerSpec.
- *
- * Instances of HybridWebSocketManagerSpecCxx can be accessed from C++, and contain
- * additional required bridging code for C++ <> Swift interop.
- */
- func createCxxBridge() -> HybridWebSocketManagerSpecCxx {
- return HybridWebSocketManagerSpecCxx(self)
- }
+ func create(url: String, protocols: [String]) throws -> (any HybridWebSocketSpec)
}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpecCxx.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpecCxx.swift
index 4d729f5..4127c24 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpecCxx.swift
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketManagerSpecCxx.swift
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpecCxx.swift
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -9,6 +8,30 @@
import Foundation
import NitroModules
+/**
+ * Helper class for converting instances of `HybridWebSocketManagerSpecCxx` from- and to unsafe pointers.
+ * This is useful to pass Swift classes to C++, without having to strongly type the C++ function signature.
+ * The actual Swift type can be included in the .cpp file, without having to forward-declare anything in .hpp.
+ */
+public final class HybridWebSocketManagerSpecCxxUnsafe {
+ /**
+ * Casts a `HybridWebSocketManagerSpecCxx` instance to a retained unsafe raw pointer.
+ * This acquires one additional strong reference on the object!
+ */
+ public static func toUnsafe(_ instance: HybridWebSocketManagerSpecCxx) -> UnsafeMutableRawPointer {
+ return Unmanaged.passRetained(instance).toOpaque()
+ }
+
+ /**
+ * Casts an unsafe pointer to a `HybridWebSocketManagerSpecCxx`.
+ * The pointer has to be a retained opaque `Unmanaged`.
+ * This removes one strong reference from the object!
+ */
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridWebSocketManagerSpecCxx {
+ return Unmanaged.fromOpaque(pointer).takeRetainedValue()
+ }
+}
+
/**
* A class implementation that bridges HybridWebSocketManagerSpec over to C++.
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
@@ -18,36 +41,47 @@ import NitroModules
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
* - Throwing methods need to be wrapped with a Result type, as exceptions cannot be propagated to C++
*/
-public final class HybridWebSocketManagerSpecCxx {
+public class HybridWebSocketManagerSpecCxx {
/**
- * The Swift <> C++ bridge's namespace (`margelo::nitro::grabbou::bridge::swift`)
- * from `ReactNativeFastWS-Swift-Cxx-Bridge.hpp`.
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::websocket::bridge::swift`)
+ * from `FastWebSocket-Swift-Cxx-Bridge.hpp`.
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
*/
- public typealias bridge = margelo.nitro.grabbou.bridge.swift
+ public typealias bridge = margelo.nitro.websocket.bridge.swift
/**
* Holds an instance of the `HybridWebSocketManagerSpec` Swift protocol.
*/
- private(set) var implementation: HybridWebSocketManagerSpec
+ private var __implementation: any HybridWebSocketManagerSpec
/**
* Create a new `HybridWebSocketManagerSpecCxx` that wraps the given `HybridWebSocketManagerSpec`.
* All properties and methods bridge to C++ types.
*/
- public init(_ implementation: HybridWebSocketManagerSpec) {
- self.implementation = implementation
+ public init(_ implementation: some HybridWebSocketManagerSpec) {
+ self.__implementation = implementation
+ /* no base class */
+ }
+
+ /**
+ * Get the actual `HybridWebSocketManagerSpec` instance this class wraps.
+ */
+ @inline(__always)
+ public func getHybridWebSocketManagerSpec() -> any HybridWebSocketManagerSpec {
+ return __implementation
}
/**
* Contains a (weak) reference to the C++ HybridObject to cache it.
*/
public var hybridContext: margelo.nitro.HybridContext {
+ @inline(__always)
get {
- return self.implementation.hybridContext
+ return self.__implementation.hybridContext
}
+ @inline(__always)
set {
- self.implementation.hybridContext = newValue
+ self.__implementation.hybridContext = newValue
}
}
@@ -55,8 +89,9 @@ public final class HybridWebSocketManagerSpecCxx {
* Get the memory size of the Swift class (plus size of any other allocations)
* so the JS VM can properly track it and garbage-collect the JS object if needed.
*/
+ @inline(__always)
public var memorySize: Int {
- return self.implementation.memorySize
+ return self.__implementation.memorySize
}
// Properties
@@ -64,13 +99,17 @@ public final class HybridWebSocketManagerSpecCxx {
// Methods
@inline(__always)
- public func create(url: std.string, protocols: bridge.std__vector_std__string_) -> HybridWebSocketSpecCxx {
+ public func create(url: std.string, protocols: bridge.std__vector_std__string_) -> bridge.std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_ {
do {
- let result = try self.implementation.create(url: String(url), protocols: protocols.map({ val in String(val) }))
- return result.createCxxBridge()
+ let __result = try self.__implementation.create(url: String(url), protocols: protocols.map({ __item in String(__item) }))
+ return { () -> bridge.std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_ in
+ let __cxxWrapped = HybridWebSocketSpecCxx(__result)
+ let __pointer = HybridWebSocketSpecCxxUnsafe.toUnsafe(__cxxWrapped)
+ return bridge.create_std__shared_ptr_margelo__nitro__websocket__HybridWebSocketSpec_(__pointer)
+ }()
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpec.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpec.swift
index 3feced4..6171179 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpec.swift
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpec.swift
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpec.swift
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -28,7 +27,7 @@ import NitroModules
* }
* ```
*/
-public protocol HybridWebSocketSpec: HybridObjectSpec {
+public protocol HybridWebSocketSpec: AnyObject, HybridObjectSpec {
// Properties
@@ -44,15 +43,3 @@ public protocol HybridWebSocketSpec: HybridObjectSpec {
func onMessage(callback: @escaping ((_ message: String) -> Void)) throws -> Void
func onArrayBuffer(callback: @escaping ((_ buffer: ArrayBufferHolder) -> Void)) throws -> Void
}
-
-public extension HybridWebSocketSpec {
- /**
- * Create a new instance of HybridWebSocketSpecCxx for the given HybridWebSocketSpec.
- *
- * Instances of HybridWebSocketSpecCxx can be accessed from C++, and contain
- * additional required bridging code for C++ <> Swift interop.
- */
- func createCxxBridge() -> HybridWebSocketSpecCxx {
- return HybridWebSocketSpecCxx(self)
- }
-}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpecCxx.swift b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpecCxx.swift
index d707cd3..19b1a3f 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpecCxx.swift
+++ b/packages/react-native-fast-ws/nitrogen/generated/ios/swift/HybridWebSocketSpecCxx.swift
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpecCxx.swift
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -9,6 +8,30 @@
import Foundation
import NitroModules
+/**
+ * Helper class for converting instances of `HybridWebSocketSpecCxx` from- and to unsafe pointers.
+ * This is useful to pass Swift classes to C++, without having to strongly type the C++ function signature.
+ * The actual Swift type can be included in the .cpp file, without having to forward-declare anything in .hpp.
+ */
+public final class HybridWebSocketSpecCxxUnsafe {
+ /**
+ * Casts a `HybridWebSocketSpecCxx` instance to a retained unsafe raw pointer.
+ * This acquires one additional strong reference on the object!
+ */
+ public static func toUnsafe(_ instance: HybridWebSocketSpecCxx) -> UnsafeMutableRawPointer {
+ return Unmanaged.passRetained(instance).toOpaque()
+ }
+
+ /**
+ * Casts an unsafe pointer to a `HybridWebSocketSpecCxx`.
+ * The pointer has to be a retained opaque `Unmanaged`.
+ * This removes one strong reference from the object!
+ */
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridWebSocketSpecCxx {
+ return Unmanaged.fromOpaque(pointer).takeRetainedValue()
+ }
+}
+
/**
* A class implementation that bridges HybridWebSocketSpec over to C++.
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
@@ -18,36 +41,47 @@ import NitroModules
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
* - Throwing methods need to be wrapped with a Result type, as exceptions cannot be propagated to C++
*/
-public final class HybridWebSocketSpecCxx {
+public class HybridWebSocketSpecCxx {
/**
- * The Swift <> C++ bridge's namespace (`margelo::nitro::grabbou::bridge::swift`)
- * from `ReactNativeFastWS-Swift-Cxx-Bridge.hpp`.
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::websocket::bridge::swift`)
+ * from `FastWebSocket-Swift-Cxx-Bridge.hpp`.
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
*/
- public typealias bridge = margelo.nitro.grabbou.bridge.swift
+ public typealias bridge = margelo.nitro.websocket.bridge.swift
/**
* Holds an instance of the `HybridWebSocketSpec` Swift protocol.
*/
- private(set) var implementation: HybridWebSocketSpec
+ private var __implementation: any HybridWebSocketSpec
/**
* Create a new `HybridWebSocketSpecCxx` that wraps the given `HybridWebSocketSpec`.
* All properties and methods bridge to C++ types.
*/
- public init(_ implementation: HybridWebSocketSpec) {
- self.implementation = implementation
+ public init(_ implementation: some HybridWebSocketSpec) {
+ self.__implementation = implementation
+ /* no base class */
+ }
+
+ /**
+ * Get the actual `HybridWebSocketSpec` instance this class wraps.
+ */
+ @inline(__always)
+ public func getHybridWebSocketSpec() -> any HybridWebSocketSpec {
+ return __implementation
}
/**
* Contains a (weak) reference to the C++ HybridObject to cache it.
*/
public var hybridContext: margelo.nitro.HybridContext {
+ @inline(__always)
get {
- return self.implementation.hybridContext
+ return self.__implementation.hybridContext
}
+ @inline(__always)
set {
- self.implementation.hybridContext = newValue
+ self.__implementation.hybridContext = newValue
}
}
@@ -55,8 +89,9 @@ public final class HybridWebSocketSpecCxx {
* Get the memory size of the Swift class (plus size of any other allocations)
* so the JS VM can properly track it and garbage-collect the JS object if needed.
*/
+ @inline(__always)
public var memorySize: Int {
- return self.implementation.memorySize
+ return self.__implementation.memorySize
}
// Properties
@@ -66,135 +101,135 @@ public final class HybridWebSocketSpecCxx {
@inline(__always)
public func send(message: std.string) -> Void {
do {
- try self.implementation.send(message: String(message))
+ try self.__implementation.send(message: String(message))
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func sendArrayBuffer(buffer: ArrayBufferHolder) -> Void {
do {
- try self.implementation.sendArrayBuffer(buffer: buffer)
+ try self.__implementation.sendArrayBuffer(buffer: buffer)
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func connect() -> Void {
do {
- try self.implementation.connect()
+ try self.__implementation.connect()
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func close() -> Void {
do {
- try self.implementation.close()
+ try self.__implementation.close()
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func ping() -> Void {
do {
- try self.implementation.ping()
+ try self.__implementation.ping()
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func onOpen(callback: bridge.Func_void_std__string) -> Void {
do {
- try self.implementation.onOpen(callback: { () -> ((String) -> Void) in
- let shared = bridge.share_Func_void_std__string(callback)
- return { (selectedProtocol: String) -> Void in
- shared.pointee.call(std.string(selectedProtocol))
+ try self.__implementation.onOpen(callback: { () -> ((String) -> Void) in
+ let __sharedClosure = bridge.share_Func_void_std__string(callback)
+ return { (__selectedProtocol: String) -> Void in
+ __sharedClosure.pointee.call(std.string(__selectedProtocol))
}
}())
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func onClose(callback: bridge.Func_void_double_std__string) -> Void {
do {
- try self.implementation.onClose(callback: { () -> ((Double, String) -> Void) in
- let shared = bridge.share_Func_void_double_std__string(callback)
- return { (code: Double, reason: String) -> Void in
- shared.pointee.call(code, std.string(reason))
+ try self.__implementation.onClose(callback: { () -> ((Double, String) -> Void) in
+ let __sharedClosure = bridge.share_Func_void_double_std__string(callback)
+ return { (__code: Double, __reason: String) -> Void in
+ __sharedClosure.pointee.call(__code, std.string(__reason))
}
}())
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func onError(callback: bridge.Func_void_std__string) -> Void {
do {
- try self.implementation.onError(callback: { () -> ((String) -> Void) in
- let shared = bridge.share_Func_void_std__string(callback)
- return { (error: String) -> Void in
- shared.pointee.call(std.string(error))
+ try self.__implementation.onError(callback: { () -> ((String) -> Void) in
+ let __sharedClosure = bridge.share_Func_void_std__string(callback)
+ return { (__error: String) -> Void in
+ __sharedClosure.pointee.call(std.string(__error))
}
}())
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func onMessage(callback: bridge.Func_void_std__string) -> Void {
do {
- try self.implementation.onMessage(callback: { () -> ((String) -> Void) in
- let shared = bridge.share_Func_void_std__string(callback)
- return { (message: String) -> Void in
- shared.pointee.call(std.string(message))
+ try self.__implementation.onMessage(callback: { () -> ((String) -> Void) in
+ let __sharedClosure = bridge.share_Func_void_std__string(callback)
+ return { (__message: String) -> Void in
+ __sharedClosure.pointee.call(std.string(__message))
}
}())
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
@inline(__always)
public func onArrayBuffer(callback: bridge.Func_void_std__shared_ptr_ArrayBuffer_) -> Void {
do {
- try self.implementation.onArrayBuffer(callback: { () -> ((ArrayBufferHolder) -> Void) in
- let shared = bridge.share_Func_void_std__shared_ptr_ArrayBuffer_(callback)
- return { (buffer: ArrayBufferHolder) -> Void in
- shared.pointee.call(buffer)
+ try self.__implementation.onArrayBuffer(callback: { () -> ((ArrayBufferHolder) -> Void) in
+ let __sharedClosure = bridge.share_Func_void_std__shared_ptr_ArrayBuffer_(callback)
+ return { (__buffer: ArrayBufferHolder) -> Void in
+ __sharedClosure.pointee.call(__buffer)
}
}())
return
} catch {
- let message = "\(error.localizedDescription)"
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(message))")
+ let __message = "\(error.localizedDescription)"
+ fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
}
}
}
diff --git a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp
index 1645e2e..6dc10bc 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpec.cpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -8,7 +7,7 @@
#include "HybridWebSocketManagerSpec.hpp"
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
void HybridWebSocketManagerSpec::loadHybridMethods() {
// load base methods/properties
@@ -19,4 +18,4 @@ namespace margelo::nitro::grabbou {
});
}
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.hpp b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.hpp
index cd7641e..9c9358c 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.hpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketManagerSpec.hpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -15,23 +14,26 @@
#endif
// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
-namespace margelo::nitro::grabbou { class HybridWebSocketSpec; }
+namespace margelo::nitro::websocket { class HybridWebSocketSpec; }
#include
#include "HybridWebSocketSpec.hpp"
#include
#include
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
using namespace margelo::nitro;
/**
* An abstract base class for `WebSocketManager`
* Inherit this class to create instances of `HybridWebSocketManagerSpec` in C++.
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
* @example
* ```cpp
* class HybridWebSocketManager: public HybridWebSocketManagerSpec {
+ * public:
+ * HybridWebSocketManager(...): HybridObject(TAG) { ... }
* // ...
* };
* ```
@@ -50,7 +52,7 @@ namespace margelo::nitro::grabbou {
public:
// Methods
- virtual std::shared_ptr create(const std::string& url, const std::vector& protocols) = 0;
+ virtual std::shared_ptr create(const std::string& url, const std::vector& protocols) = 0;
protected:
// Hybrid Setup
@@ -61,4 +63,4 @@ namespace margelo::nitro::grabbou {
static constexpr auto TAG = "WebSocketManager";
};
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp
index c21bb24..a363c0b 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpec.cpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -8,7 +7,7 @@
#include "HybridWebSocketSpec.hpp"
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
void HybridWebSocketSpec::loadHybridMethods() {
// load base methods/properties
@@ -28,4 +27,4 @@ namespace margelo::nitro::grabbou {
});
}
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.hpp b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.hpp
index 4e80cff..1c967c9 100644
--- a/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.hpp
+++ b/packages/react-native-fast-ws/nitrogen/generated/shared/c++/HybridWebSocketSpec.hpp
@@ -1,6 +1,5 @@
///
/// HybridWebSocketSpec.hpp
-/// Fri Nov 01 2024
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
@@ -21,16 +20,19 @@ namespace NitroModules { class ArrayBuffer; }
#include
#include
-namespace margelo::nitro::grabbou {
+namespace margelo::nitro::websocket {
using namespace margelo::nitro;
/**
* An abstract base class for `WebSocket`
* Inherit this class to create instances of `HybridWebSocketSpec` in C++.
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
* @example
* ```cpp
* class HybridWebSocket: public HybridWebSocketSpec {
+ * public:
+ * HybridWebSocket(...): HybridObject(TAG) { ... }
* // ...
* };
* ```
@@ -69,4 +71,4 @@ namespace margelo::nitro::grabbou {
static constexpr auto TAG = "WebSocket";
};
-} // namespace margelo::nitro::grabbou
+} // namespace margelo::nitro::websocket
diff --git a/packages/react-native-fast-ws/package.json b/packages/react-native-fast-ws/package.json
index d6613f3..554acd4 100644
--- a/packages/react-native-fast-ws/package.json
+++ b/packages/react-native-fast-ws/package.json
@@ -16,13 +16,13 @@
"author": "Mike Grabowski ",
"peerDependencies": {
"react-native-nitro-modules": "^0.14.0",
- "web-streams-polyfill": "^4.0.0"
+ "react-native": "^0.76.0"
},
"dependencies": {
- "event-target-shim": "^6.0.2"
- },
- "devDependencies": {
"event-target-shim": "^6.0.2",
"web-streams-polyfill": "^4.0.0"
+ },
+ "devDependencies": {
+ "nitro-codegen": "^0.14.0"
}
}
diff --git a/packages/react-native-fast-ws/src/index.ts b/packages/react-native-fast-ws/src/index.ts
index 416cd60..7ac67ea 100644
--- a/packages/react-native-fast-ws/src/index.ts
+++ b/packages/react-native-fast-ws/src/index.ts
@@ -7,7 +7,7 @@ import {
import { NitroModules } from 'react-native-nitro-modules'
import { Blob } from './blob'
-import { WebSocket as HybridWebSocket, WebSocketManager } from './spec.nitro'
+import { WebSocket as HybridWebSocket, WebSocketManager } from './WebSocket.nitro'
const manager = NitroModules.createHybridObject('WebSocketManager')
diff --git a/packages/react-native-fast-ws/src/spec.nitro.ts b/packages/react-native-fast-ws/src/spec.nitro.ts
index 4ad791e..097b14a 100644
--- a/packages/react-native-fast-ws/src/spec.nitro.ts
+++ b/packages/react-native-fast-ws/src/spec.nitro.ts
@@ -1,6 +1,6 @@
import { HybridObject } from 'react-native-nitro-modules'
-export interface WebSocket extends HybridObject<{ ios: 'swift' }> {
+export interface WebSocket extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
send(message: string): void
sendArrayBuffer(buffer: ArrayBuffer): void
@@ -16,6 +16,6 @@ export interface WebSocket extends HybridObject<{ ios: 'swift' }> {
onArrayBuffer(callback: (buffer: ArrayBuffer) => void): void
}
-export interface WebSocketManager extends HybridObject<{ ios: 'swift' }> {
+export interface WebSocketManager extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
create(url: string, protocols: string[]): WebSocket
}