Skip to content

Commit 3aac759

Browse files
Do not throw exception when user subscribes to a channel twice (#94)
* Do not throw exception when user subscribes to a channel twice * Run lint * Bump to version 1.2.2 --------- Co-authored-by: Pusher CI <[email protected]>
1 parent ef09875 commit 3aac759

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
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.2.2
4+
5+
* [FIXED] Crash when a user subscribes to a channel twice on Android
6+
* [FIXED] Wait for unsubscription before deleting the local channel (#88)
7+
38
## 1.2.1
49

510
* [FIXED] Fixed event name conflicts with other libs using RCTDeviceEventEmitter

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pusher/pusher-websocket-react-native",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Pusher Channels Client for React Native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class Pusher {
209209
default:
210210
const pusherEvent = new PusherEvent(event);
211211
args.onEvent?.(pusherEvent);
212-
channel.onEvent?.(pusherEvent);
212+
channel?.onEvent?.(pusherEvent);
213213
break;
214214
}
215215
});
@@ -287,10 +287,15 @@ export class Pusher {
287287
onMemberRemoved?: (member: PusherMember) => void;
288288
onEvent?: (event: PusherEvent) => void;
289289
}) {
290-
const channel = new PusherChannel(args);
291-
this.channels.set(args.channelName, channel);
290+
const channel = this.channels.get(args.channelName);
291+
if (channel) {
292+
return channel;
293+
}
294+
295+
const newChannel = new PusherChannel(args);
292296
await PusherWebsocketReactNative.subscribe(args.channelName);
293-
return channel;
297+
this.channels.set(args.channelName, newChannel);
298+
return newChannel;
294299
}
295300

296301
public async unsubscribe({ channelName }: { channelName: string }) {

0 commit comments

Comments
 (0)