@@ -106,9 +106,13 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
106
106
@ReactMethod
107
107
fun subscribe (channelName : String , promise : Promise ) {
108
108
val channel = when {
109
- channelName.startsWith(" private-encrypted-" ) -> pusher!! .subscribePrivateEncrypted(channelName, this )
109
+ channelName.startsWith(" private-encrypted-" ) -> pusher!! .subscribePrivateEncrypted(
110
+ channelName, this
111
+ )
110
112
channelName.startsWith(" private-" ) -> pusher!! .subscribePrivate(channelName, this )
111
- channelName.startsWith(" presence-" ) -> pusher!! .subscribePresence(channelName, this )
113
+ channelName.startsWith(" presence-" ) -> pusher!! .subscribePresence(
114
+ channelName, this
115
+ )
112
116
else -> pusher!! .subscribe(channelName, this )
113
117
}
114
118
channel.bindGlobal(this )
@@ -123,14 +127,18 @@ class PusherWebsocketReactNativeModule(reactContext: ReactApplicationContext) :
123
127
124
128
@ReactMethod
125
129
fun trigger (channelName : String , eventName : String , data : String , promise : Promise ) {
126
- when {
127
- channelName.startsWith(" private-encrypted-" ) -> throw Exception (" It's not currently possible to send a message using private encrypted channels." )
128
- channelName.startsWith(" private-" ) -> pusher!! .getPrivateChannel(channelName).trigger(eventName, data)
129
- channelName.startsWith(" presence-" ) -> pusher!! .getPresenceChannel(channelName)
130
- .trigger(eventName, data)
131
- 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)
132
141
}
133
- promise.resolve(null )
134
142
}
135
143
136
144
@ReactMethod
0 commit comments