@@ -106,10 +106,10 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
106
106
@ReactMethod
107
107
fun subscribe (channelName : String , promise : Promise ) {
108
108
val channel = when {
109
- channelName.startsWith(" private-" ) -> pusher!! .subscribePrivate(channelName, this )
110
109
channelName.startsWith(" private-encrypted-" ) -> pusher!! .subscribePrivateEncrypted(
111
110
channelName, this
112
111
)
112
+ channelName.startsWith(" private-" ) -> pusher!! .subscribePrivate(channelName, this )
113
113
channelName.startsWith(" presence-" ) -> pusher!! .subscribePresence(
114
114
channelName, this
115
115
)
@@ -127,15 +127,18 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
127
127
128
128
@ReactMethod
129
129
fun trigger (channelName : String , eventName : String , data : String , promise : Promise ) {
130
- when {
131
- channelName.startsWith(" private-" ) -> pusher!! .getPrivateChannel(channelName)
132
- .trigger(eventName, data)
133
- channelName.startsWith(" private-encrypted-" ) -> throw Exception (" It's not currently possible to send a message using private encrypted channels." )
134
- channelName.startsWith(" presence-" ) -> pusher!! .getPresenceChannel(channelName)
135
- .trigger(eventName, data)
136
- else -> throw Exception (" Messages can only be sent to private and presence channels." )
130
+ try {
131
+ when {
132
+ channelName.startsWith(" private-encrypted-" ) -> throw Exception (" It's not currently possible to send a message using private encrypted channels." )
133
+ channelName.startsWith(" private-" ) -> pusher!! .getPrivateChannel(channelName).trigger(eventName, data)
134
+ channelName.startsWith(" presence-" ) -> pusher!! .getPresenceChannel(channelName)
135
+ .trigger(eventName, data)
136
+ else -> throw Exception (" Messages can only be sent to private and presence channels." )
137
+ }
138
+ promise.resolve(null )
139
+ } catch (e: Exception ) {
140
+ promise.reject(e)
137
141
}
138
- promise.resolve(null )
139
142
}
140
143
141
144
@ReactMethod
0 commit comments