Skip to content

Commit b485b43

Browse files
authored
Merge pull request #32 from pusher/add-subscription-count
Add subscription count
2 parents b65a2c5 + 4b2c9ef commit b485b43

20 files changed

+1001
-876
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.1.0
4+
5+
* [CHANGED] Add support for the new subscription_count event
6+
* [CHANGED] Using latest pusher-websocket-java and pusher-websocket-swift
7+
38
## 1.0.2
49

510
* [CHANGED] Use latest pusher websocket java sdk.

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ a minimal application to connect to a channel and send events.
4747
- [`onSubscriptionSucceeded`](#onsubscriptionsucceeded)
4848
- [`onSubscriptionError`](#onsubscriptionerror)
4949
- [`onDecryptionFailure`](#ondecryptionfailure)
50+
- [`onSubscriptionCount`](#onsubscriptioncount)
5051
- [`onMemberAdded`](#onmemberadded)
5152
- [`onMemberRemoved`](#onmemberremoved)
5253
- [`onAuthorizer`](#onauthorizer)
@@ -134,6 +135,7 @@ try {
134135
onDecryptionFailure,
135136
onMemberAdded,
136137
onMemberRemoved,
138+
onSubscriptionCount,
137139
});
138140

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

235+
#### `onSubscriptionCount`
236+
237+
```typescript
238+
function onSubscriptionCount(subscriptionCount:number) {
239+
console.log(`onSubscriptionSucceeded: ${subscriptionCount}`);
240+
}
241+
```
242+
243+
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.
244+
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.
245+
233246
#### `onMemberAdded`
234247

235248
```typescript

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:7.2.0'
11+
classpath 'com.android.tools.build:gradle:7.3.0'
1212
// noinspection DifferentKotlinGradleVersion
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}

android/gradle.properties

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
PusherWebsocketReactNative_kotlinVersion=1.3.50
2-
PusherWebsocketReactNative_compileSdkVersion=29
3-
PusherWebsocketReactNative_targetSdkVersion=29
1+
## For more details on how to configure your build environment visit
2+
# http://www.gradle.org/docs/current/userguide/build_environment.html
3+
#
4+
# Specifies the JVM arguments used for the daemon process.
5+
# The setting is particularly useful for tweaking memory settings.
6+
# Default value: -Xmx1024m -XX:MaxPermSize=256m
7+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
8+
#
9+
# When configured, Gradle will run in incubating parallel mode.
10+
# This option should only be used with decoupled projects. More details, visit
11+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12+
# org.gradle.parallel=true
13+
#Fri Aug 19 11:19:42 CEST 2022
14+
PusherWebsocketReactNative_kotlinVersion=1.7.10
15+
PusherWebsocketReactNative_targetSdkVersion=33
16+
PusherWebsocketReactNative_compileSdkVersion=33
17+
android.useAndroidX=true
18+
android.enableJetifier=true

android/src/main/java/com/pusherwebsocketreactnative/PusherWebsocketReactNativeModule.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
6565
if (arguments.hasKey("useTLS")) options.isUseTLS =
6666
arguments.getBoolean("useTLS")
6767
if (arguments.hasKey("activityTimeout")) options.activityTimeout =
68-
arguments.getInt("activityTimeout") as Long
68+
arguments.getInt("activityTimeout").toLong()
6969
if (arguments.hasKey("pongTimeout")) options.pongTimeout =
70-
arguments.getInt("pongTimeout") as Long
70+
arguments.getInt("pongTimeout").toLong()
7171
if (arguments.hasKey("maxReconnectionAttempts")) options.maxReconnectionAttempts =
7272
arguments.getInt("maxReconnectionAttempts")
7373
if (arguments.hasKey("maxReconnectGapInSeconds")) options.maxReconnectGapInSeconds =
@@ -160,8 +160,7 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
160160
authorizerMutex[key]!!.acquire()
161161
val authParams = authorizerResult.remove(key)!!
162162
val gson = Gson()
163-
val json = gson.toJson(authParams.toHashMap())
164-
return json
163+
return gson.toJson(authParams.toHashMap())
165164
}
166165

167166
@ReactMethod
@@ -198,12 +197,23 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
198197

199198
override fun onEvent(event: PusherEvent) {
200199
// Log.i(TAG, "Received event with data: $event")
200+
// The java sdk transforms some events from pusher_internal
201+
// to pusher:... events, we translate them back.
202+
val finalEvent = if (event.eventName === "pusher:subscription_count") {
203+
PusherEvent(
204+
"pusher_internal:subscription_count",
205+
event.channelName,
206+
event.userId,
207+
event.data)
208+
} else {
209+
event
210+
}
201211
emitEvent(
202212
"onEvent", mapOf(
203-
"channelName" to event.channelName,
204-
"eventName" to event.eventName,
205-
"userId" to event.userId,
206-
"data" to event.data
213+
"channelName" to finalEvent.channelName,
214+
"eventName" to finalEvent.eventName,
215+
"userId" to finalEvent.userId,
216+
"data" to finalEvent.data
207217
)
208218
)
209219
}

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ dependencies {
205205
implementation jscFlavor
206206
}
207207

208-
implementation project(':pusherwebsocketreactnative')
208+
implementation project(':pusher-websocket-react-native')
209209
}
210210

211211
// Run this once to be able to run the application with BUCK

example/android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
buildscript {
44
ext {
55
minSdkVersion = 21
6-
compileSdkVersion = 31
7-
targetSdkVersion = 31
6+
compileSdkVersion = 33
7+
targetSdkVersion = 33
88
}
99
repositories {
1010
google()
1111
mavenCentral()
1212
}
1313
dependencies {
14-
classpath('com.android.tools.build:gradle:7.2.0')
14+
classpath('com.android.tools.build:gradle:7.2.1')
1515

1616
// NOTE: Do not place your application dependencies here; they belong
1717
// in the individual module build.gradle files

example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
android.useAndroidX=true
2121
android.enableJetifier=true
22-
FLIPPER_VERSION=0.142.0
22+
FLIPPER_VERSION=0.159.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Wed Mar 30 18:12:52 CEST 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

example/android/settings.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ rootProject.name = 'PusherWebsocketReactNativeExample'
22
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
33
include ':app'
44

5-
include ':pusherwebsocketreactnative'
6-
project(':pusherwebsocketreactnative').projectDir = new File(rootProject.projectDir, '../../android')
5+
include ':pusher-websocket-react-native'
6+
project(':pusher-websocket-react-native').projectDir = new File(rootProject.projectDir, '../../android')

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ target 'PusherWebsocketReactNativeExample' do
1414
#
1515
# Note that if you have use_frameworks! enabled, Flipper will not work and
1616
# you should disable these next few lines.
17-
use_flipper!({ 'Flipper' => '0.145.0' })
17+
use_flipper!({ 'Flipper' => '0.159.0' })
1818
post_install do |installer|
1919
flipper_post_install(installer)
2020
end

0 commit comments

Comments
 (0)