Skip to content

Commit

Permalink
Merge pull request #32 from pusher/add-subscription-count
Browse files Browse the repository at this point in the history
Add subscription count
  • Loading branch information
fbenevides authored Oct 7, 2022
2 parents b65a2c5 + 4b2c9ef commit b485b43
Show file tree
Hide file tree
Showing 20 changed files with 1,001 additions and 876 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.0

* [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.
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ a minimal application to connect to a channel and send events.
- [`onSubscriptionSucceeded`](#onsubscriptionsucceeded)
- [`onSubscriptionError`](#onsubscriptionerror)
- [`onDecryptionFailure`](#ondecryptionfailure)
- [`onSubscriptionCount`](#onsubscriptioncount)
- [`onMemberAdded`](#onmemberadded)
- [`onMemberRemoved`](#onmemberremoved)
- [`onAuthorizer`](#onauthorizer)
Expand Down Expand Up @@ -134,6 +135,7 @@ try {
onDecryptionFailure,
onMemberAdded,
onMemberRemoved,
onSubscriptionCount,
});

await pusher.subscribe({ channelName });
Expand Down Expand Up @@ -230,6 +232,17 @@ function onDecryptionFailure(event:string, string reason:string) {
```
Used with private channels only. Use this if you want to be notified if any messages fail to decrypt.

#### `onSubscriptionCount`

```typescript
function onSubscriptionCount(subscriptionCount:number) {
console.log(`onSubscriptionSucceeded: ${subscriptionCount}`);
}
```

is an event that can be manually enabled on the server to count the number of connections that are currently subscribed to a particular channel. They work with all channel types, except presence channels.
See [Counting live users at scale with subscription_count events](https://blog.pusher.com/counting-live-users-at-scale-with-subscription-count-events/) for more information.

#### `onMemberAdded`

```typescript
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.android.tools.build:gradle:7.3.0'
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
21 changes: 18 additions & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
PusherWebsocketReactNative_kotlinVersion=1.3.50
PusherWebsocketReactNative_compileSdkVersion=29
PusherWebsocketReactNative_targetSdkVersion=29
## 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
if (arguments.hasKey("useTLS")) options.isUseTLS =
arguments.getBoolean("useTLS")
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
arguments.getInt("activityTimeout") as Long
arguments.getInt("activityTimeout").toLong()
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
arguments.getInt("pongTimeout") as Long
arguments.getInt("pongTimeout").toLong()
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
arguments.getInt("maxReconnectionAttempts")
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
Expand Down Expand Up @@ -160,8 +160,7 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
authorizerMutex[key]!!.acquire()
val authParams = authorizerResult.remove(key)!!
val gson = Gson()
val json = gson.toJson(authParams.toHashMap())
return json
return gson.toJson(authParams.toHashMap())
}

@ReactMethod
Expand Down Expand Up @@ -198,12 +197,23 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :

override fun onEvent(event: PusherEvent) {
// Log.i(TAG, "Received event with data: $event")
// The java sdk transforms some events from pusher_internal
// to pusher:... events, we translate them back.
val finalEvent = if (event.eventName === "pusher:subscription_count") {
PusherEvent(
"pusher_internal:subscription_count",
event.channelName,
event.userId,
event.data)
} else {
event
}
emitEvent(
"onEvent", mapOf(
"channelName" to event.channelName,
"eventName" to event.eventName,
"userId" to event.userId,
"data" to event.data
"channelName" to finalEvent.channelName,
"eventName" to finalEvent.eventName,
"userId" to finalEvent.userId,
"data" to finalEvent.data
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ dependencies {
implementation jscFlavor
}

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

// Run this once to be able to run the application with BUCK
Expand Down
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
buildscript {
ext {
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
compileSdkVersion = 33
targetSdkVersion = 33
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:7.2.0')
classpath('com.android.tools.build:gradle:7.2.1')

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

android.useAndroidX=true
android.enableJetifier=true
FLIPPER_VERSION=0.142.0
FLIPPER_VERSION=0.159.0
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Mar 30 18:12:52 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
4 changes: 2 additions & 2 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ rootProject.name = 'PusherWebsocketReactNativeExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

include ':pusherwebsocketreactnative'
project(':pusherwebsocketreactnative').projectDir = new File(rootProject.projectDir, '../../android')
include ':pusher-websocket-react-native'
project(':pusher-websocket-react-native').projectDir = new File(rootProject.projectDir, '../../android')
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target 'PusherWebsocketReactNativeExample' do
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!({ 'Flipper' => '0.145.0' })
use_flipper!({ 'Flipper' => '0.159.0' })
post_install do |installer|
flipper_post_install(installer)
end
Expand Down
Loading

0 comments on commit b485b43

Please sign in to comment.