Skip to content

Commit 1ac5116

Browse files
committed
Add leaveOne method to connectors
At the moment it's impossible to only leave a public channel and not a presence or private channel. With this method people can use it for this behavior if they want. Closes #202
1 parent 16760a6 commit 1ac5116

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

src/connector/connector.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ export abstract class Connector {
8181
abstract presenceChannel(channel: string): PresenceChannel;
8282

8383
/**
84-
* Leave the given channel.
84+
* Leave the given channel and its private & presence channels.
8585
*/
8686
abstract leave(channel: string): void;
8787

88+
/**
89+
* Leave the given channel.
90+
*/
91+
abstract leaveOne(channel: string): void;
92+
8893
/**
8994
* Get the socket_id of the connection.
9095
*/

src/connector/null-connector.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,19 @@ export class NullConnector extends Connector {
4848
}
4949

5050
/**
51-
* Leave the given channel.
51+
* Leave the given channel and its private & presence channels.
5252
*/
5353
leave(name: string): void {
5454
//
5555
}
5656

57+
/**
58+
* Leave the given channel.
59+
*/
60+
leaveOne(name: string): void {
61+
//
62+
}
63+
5764
/**
5865
* Get the socket ID for the connection.
5966
*/

src/connector/pusher-connector.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,27 @@ export class PusherConnector extends Connector {
8181
}
8282

8383
/**
84-
* Leave the given channel.
84+
* Leave the given channel and its private & presence channels.
8585
*/
8686
leave(name: string): void {
8787
let channels = [name, 'private-' + name, 'presence-' + name];
8888

8989
channels.forEach((name: string, index: number) => {
90-
if (this.channels[name]) {
91-
this.channels[name].unsubscribe();
92-
93-
delete this.channels[name];
94-
}
90+
this.leaveOne(name);
9591
});
9692
}
9793

94+
/**
95+
* Leave the given channel.
96+
*/
97+
leaveOne(name: string): void {
98+
if (this.channels[name]) {
99+
this.channels[name].unsubscribe();
100+
101+
delete this.channels[name];
102+
}
103+
}
104+
98105
/**
99106
* Get the socket ID for the connection.
100107
*/

src/connector/socketio-connector.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,27 @@ export class SocketIoConnector extends Connector {
9494
}
9595

9696
/**
97-
* Leave the given channel.
97+
* Leave the given channel and its private & presence channels.
9898
*/
9999
leave(name: string): void {
100100
let channels = [name, 'private-' + name, 'presence-' + name];
101101

102102
channels.forEach(name => {
103-
if (this.channels[name]) {
104-
this.channels[name].unsubscribe();
105-
106-
delete this.channels[name];
107-
}
103+
this.leaveOne(name);
108104
});
109105
}
110106

107+
/**
108+
* Leave the given channel.
109+
*/
110+
leaveOne(name: string): void {
111+
if (this.channels[name]) {
112+
this.channels[name].unsubscribe();
113+
114+
delete this.channels[name];
115+
}
116+
}
117+
111118
/**
112119
* Get the socket ID for the connection.
113120
*/

0 commit comments

Comments
 (0)