Skip to content

Commit 3748e93

Browse files
Fix broken Typescript presence channel interface "whisper" method (#377)
* Add Whisper typescript Prototype * Fixed broken class * formatting --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8f8316d commit 3748e93

8 files changed

+34
-16
lines changed

src/channel/null-presence-channel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ export class NullPresenceChannel extends NullChannel implements PresenceChannel
2020
}
2121

2222
/**
23-
* Listen for someone leaving the channel.
23+
* Send a whisper event to other clients in the channel.
2424
*/
25-
leaving(callback: Function): NullPresenceChannel {
25+
whisper(eventName: string, data: any): NullPresenceChannel {
2626
return this;
2727
}
2828

2929
/**
30-
* Trigger client event on the channel.
30+
* Listen for someone leaving the channel.
3131
*/
32-
whisper(eventName: string, data: any): NullPresenceChannel {
32+
leaving(callback: Function): NullPresenceChannel {
3333
return this;
3434
}
3535
}

src/channel/null-private-channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NullChannel } from './null-channel';
55
*/
66
export class NullPrivateChannel extends NullChannel {
77
/**
8-
* Trigger client event on the channel.
8+
* Send a whisper event to other clients in the channel.
99
*/
1010
whisper(eventName: string, data: any): NullPrivateChannel {
1111
return this;

src/channel/presence-channel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export interface PresenceChannel extends Channel {
1414
*/
1515
joining(callback: Function): PresenceChannel;
1616

17+
/**
18+
* Send a whisper event to other clients in the channel.
19+
*/
20+
whisper(eventName: string, data: any): PresenceChannel;
21+
1722
/**
1823
* Listen for someone leaving the channel.
1924
*/

src/channel/pusher-encrypted-private-channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PusherChannel } from './pusher-channel';
55
*/
66
export class PusherEncryptedPrivateChannel extends PusherChannel {
77
/**
8-
* Trigger client event on the channel.
8+
* Send a whisper event to other clients in the channel.
99
*/
1010
whisper(eventName: string, data: any): PusherEncryptedPrivateChannel {
1111
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);

src/channel/pusher-presence-channel.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ export class PusherPresenceChannel extends PusherChannel implements PresenceChan
2828
}
2929

3030
/**
31-
* Listen for someone leaving the channel.
31+
* Send a whisper event to other clients in the channel.
3232
*/
33-
leaving(callback: Function): PusherPresenceChannel {
34-
this.on('pusher:member_removed', (member) => {
35-
callback(member.info);
36-
});
33+
whisper(eventName: string, data: any): PusherPresenceChannel {
34+
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);
3735

3836
return this;
3937
}
4038

4139
/**
42-
* Trigger client event on the channel.
40+
* Listen for someone leaving the channel.
4341
*/
44-
whisper(eventName: string, data: any): PusherPresenceChannel {
45-
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);
42+
leaving(callback: Function): PusherPresenceChannel {
43+
this.on('pusher:member_removed', (member) => {
44+
callback(member.info);
45+
});
4646

4747
return this;
4848
}

src/channel/pusher-private-channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PusherChannel } from './pusher-channel';
55
*/
66
export class PusherPrivateChannel extends PusherChannel {
77
/**
8-
* Trigger client event on the channel.
8+
* Send a whisper event to other clients in the channel.
99
*/
1010
whisper(eventName: string, data: any): PusherPrivateChannel {
1111
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);

src/channel/socketio-presence-channel.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ export class SocketIoPresenceChannel extends SocketIoPrivateChannel implements P
2525
return this;
2626
}
2727

28+
/**
29+
* Send a whisper event to other clients in the channel.
30+
*/
31+
whisper(eventName: string, data: any): SocketIoPresenceChannel {
32+
this.socket.emit('client event', {
33+
channel: this.name,
34+
event: `client-${eventName}`,
35+
data: data,
36+
});
37+
38+
return this;
39+
}
40+
2841
/**
2942
* Listen for someone leaving the channel.
3043
*/

src/channel/socketio-private-channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SocketIoChannel } from './socketio-channel';
55
*/
66
export class SocketIoPrivateChannel extends SocketIoChannel {
77
/**
8-
* Trigger client event on the channel.
8+
* Send a whisper event to other clients in the channel.
99
*/
1010
whisper(eventName: string, data: any): SocketIoChannel {
1111
this.socket.emit('client event', {

0 commit comments

Comments
 (0)