Skip to content

Change subscribe function to consider private-encrypted channels #5

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
Jun 29, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun subscribe(channelName: String, promise: Promise) {
val channel = when {
channelName.startsWith("private-") -> pusher!!.subscribePrivate(channelName, this)
channelName.startsWith("private-encrypted-") -> pusher!!.subscribePrivateEncrypted(
channelName, this
)
channelName.startsWith("private-") -> pusher!!.subscribePrivate(channelName, this)
channelName.startsWith("presence-") -> pusher!!.subscribePresence(
channelName, this
)
Expand All @@ -127,15 +127,18 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :

@ReactMethod
fun trigger(channelName: String, eventName: String, data: String, promise: Promise) {
when {
channelName.startsWith("private-") -> pusher!!.getPrivateChannel(channelName)
.trigger(eventName, data)
channelName.startsWith("private-encrypted-") -> throw Exception("It's not currently possible to send a message using private encrypted channels.")
channelName.startsWith("presence-") -> pusher!!.getPresenceChannel(channelName)
.trigger(eventName, data)
else -> throw Exception("Messages can only be sent to private and presence channels.")
try {
when {
channelName.startsWith("private-encrypted-") -> throw Exception("It's not currently possible to send a message using private encrypted channels.")
channelName.startsWith("private-") -> pusher!!.getPrivateChannel(channelName).trigger(eventName, data)
channelName.startsWith("presence-") -> pusher!!.getPresenceChannel(channelName)
.trigger(eventName, data)
else -> throw Exception("Messages can only be sent to private and presence channels.")
}
promise.resolve(null)
} catch (e: Exception) {
promise.reject(e)
}
promise.resolve(null)
}

@ReactMethod
Expand Down