Skip to content

Commit

Permalink
Do not throw exception when user subscribes to a channel twice (#94)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
fbenevides and pusher-ci authored May 17, 2023
1 parent ef09875 commit 3aac759
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.2

* [FIXED] Crash when a user subscribes to a channel twice on Android
* [FIXED] Wait for unsubscription before deleting the local channel (#88)

## 1.2.1

* [FIXED] Fixed event name conflicts with other libs using RCTDeviceEventEmitter
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pusher/pusher-websocket-react-native",
"version": "1.2.1",
"version": "1.2.2",
"description": "Pusher Channels Client for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
13 changes: 9 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class Pusher {
default:
const pusherEvent = new PusherEvent(event);
args.onEvent?.(pusherEvent);
channel.onEvent?.(pusherEvent);
channel?.onEvent?.(pusherEvent);
break;
}
});
Expand Down Expand Up @@ -287,10 +287,15 @@ export class Pusher {
onMemberRemoved?: (member: PusherMember) => void;
onEvent?: (event: PusherEvent) => void;
}) {
const channel = new PusherChannel(args);
this.channels.set(args.channelName, channel);
const channel = this.channels.get(args.channelName);
if (channel) {
return channel;
}

const newChannel = new PusherChannel(args);
await PusherWebsocketReactNative.subscribe(args.channelName);
return channel;
this.channels.set(args.channelName, newChannel);
return newChannel;
}

public async unsubscribe({ channelName }: { channelName: string }) {
Expand Down

0 comments on commit 3aac759

Please sign in to comment.