Skip to content

allow reinit and update packages #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Changelog

## 1.1.1

* [CHANGED] Allow re-init of the Pusher singleton.
* [CHANGED] Update dependencies

## 1.1.0

* [CHANGED] Add support for the new subscription_count event
* [CHANGED] Add support for the new subscription_count event
* [CHANGED] Using latest pusher-websocket-java and pusher-websocket-swift

## 1.0.2

* [CHANGED] Use latest pusher websocket java sdk.
* [ADDED] Example to use a custom authorizer.
* [CHANGED] Use latest pusher websocket java sdk.
* [ADDED] Example to use a custom authorizer.

## 1.0.1

Expand Down
36 changes: 18 additions & 18 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri Aug 19 11:19:42 CEST 2022
PusherWebsocketReactNative_kotlinVersion=1.7.10
PusherWebsocketReactNative_targetSdkVersion=33
PusherWebsocketReactNative_compileSdkVersion=33
android.useAndroidX=true
android.enableJetifier=true
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri Aug 19 11:19:42 CEST 2022
PusherWebsocketReactNative_kotlinVersion=1.7.21
PusherWebsocketReactNative_targetSdkVersion=33
PusherWebsocketReactNative_compileSdkVersion=33
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,30 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
promise: Promise
) {
try {
if (pusher == null) {
val options = PusherOptions()
if (arguments.hasKey("cluster")) options.setCluster(arguments.getString("cluster"))
if (arguments.hasKey("useTLS")) options.isUseTLS =
arguments.getBoolean("useTLS")
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
arguments.getInt("activityTimeout").toLong()
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
arguments.getInt("pongTimeout").toLong()
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
arguments.getInt("maxReconnectionAttempts")
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
arguments.getInt("maxReconnectGapInSeconds")
if (arguments.hasKey("authEndpoint")) options.channelAuthorizer =
HttpChannelAuthorizer(arguments.getString("authEndpoint"))
if (arguments.hasKey("authorizer") && arguments.getBoolean("authorizer")) options.channelAuthorizer =
this
if (arguments.hasKey("proxy")) {
val (host, port) = arguments.getString("proxy")!!.split(':')
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
}
pusher = Pusher(arguments.getString("apiKey"), options)
} else {
throw Exception("Pusher Channels already initialized.")
if (pusher != null) {
pusher!!.disconnect()
}
val options = PusherOptions()
if (arguments.hasKey("cluster")) options.setCluster(arguments.getString("cluster"))
if (arguments.hasKey("useTLS")) options.isUseTLS =
arguments.getBoolean("useTLS")
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
arguments.getInt("activityTimeout").toLong()
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
arguments.getInt("pongTimeout").toLong()
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
arguments.getInt("maxReconnectionAttempts")
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
arguments.getInt("maxReconnectGapInSeconds")
if (arguments.hasKey("authEndpoint")) options.channelAuthorizer =
HttpChannelAuthorizer(arguments.getString("authEndpoint"))
if (arguments.hasKey("authorizer") && arguments.getBoolean("authorizer")) options.channelAuthorizer =
this
if (arguments.hasKey("proxy")) {
val (host, port) = arguments.getString("proxy")!!.split(':')
options.proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port.toInt()))
}
pusher = Pusher(arguments.getString("apiKey"), options)
Log.i(TAG, "Start $pusher")
promise.resolve(null)
} catch (e: Exception) {
Expand Down
139 changes: 118 additions & 21 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"

import com.android.build.OutputFile
import org.apache.tools.ant.taskdefs.condition.Os

/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
Expand All @@ -15,7 +16,9 @@ import com.android.build.OutputFile
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://reactnative.dev/docs/performance#enable-the-ram-format
Expand All @@ -37,7 +40,7 @@ import com.android.build.OutputFile
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for PusherWebsocketReactNativeExample: to disable dev mode in the staging build type (if configured)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
Expand All @@ -64,7 +67,7 @@ import com.android.build.OutputFile
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for PusherWebsocketReactNativeExample, you might want to remove it from here.
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
Expand All @@ -76,8 +79,7 @@ import com.android.build.OutputFile
*/

project.ext.react = [
enableHermes: false, // clean and rebuild if changing
entryFile: "index.tsx",
enableHermes: true, // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
Expand All @@ -100,7 +102,7 @@ def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For PusherWebsocketReactNativeExample, to use the international variant, you can use:
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
Expand All @@ -113,35 +115,102 @@ def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* This should be set on project.ext.react and that value will be read here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for.
*/
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion rootProject.ext.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
applicationId "com.example.pusherwebsocketreactnative"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

if (isNewArchitectureEnabled()) {
// We configure the CMake build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
arguments "-DPROJECT_BUILD_DIR=$buildDir",
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
"-DANDROID_STL=c++_shared"
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
}

if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
path "$projectDir/src/main/jni/CMakeLists.txt"
}
}
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
afterEvaluate {
// If you wish to add a custom TurboModule or component locally,
// you should uncomment this line.
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)

// Due to a bug inside AGP, we have to explicitly set a dependency
// between configureCMakeDebug* tasks and the preBuild tasks.
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
configureCMakeDebug.dependsOn(preDebugBuild)
reactNativeArchitectures().each { architecture ->
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
dependsOn("preDebugBuild")
}
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
dependsOn("preReleaseBuild")
}
}
}
}

splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
include (*reactNativeArchitectures())
}
}
namespace 'com.example.pusherwebsocketreactnative'
signingConfigs {
debug {
storeFile file('debug.keystore')
Expand All @@ -150,7 +219,6 @@ android {
keyPassword 'android'
}
}
namespace 'com.example.pusherwebsocketreactnative'
buildTypes {
debug {
signingConfig signingConfigs.debug
Expand All @@ -163,16 +231,18 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
Expand All @@ -181,33 +251,52 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules


implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
//noinspection GradleDynamicVersion
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
exclude group:'com.facebook.fbjni'
}
} else {
implementation jscFlavor
}

implementation project(':pusher-websocket-react-native')
}

if (isNewArchitectureEnabled()) {
// If new architecture is enabled, we let you build RN from source
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
// This will be applied to all the imported transtitive dependency.
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.facebook.react:react-native"))
.using(project(":ReactAndroid"))
.because("On New Architecture we're building React Native from source")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
Expand All @@ -216,3 +305,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}
Loading