Skip to content

Fix broken Typescript presence channel interface "whisper" method #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/channel/null-presence-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export class NullPresenceChannel extends NullChannel implements PresenceChannel
}

/**
* Listen for someone leaving the channel.
* Send a whisper event to other clients in the channel.
*/
leaving(callback: Function): NullPresenceChannel {
whisper(eventName: string, data: any): NullPresenceChannel {
return this;
}

/**
* Trigger client event on the channel.
* Listen for someone leaving the channel.
*/
whisper(eventName: string, data: any): NullPresenceChannel {
leaving(callback: Function): NullPresenceChannel {
return this;
}
}
2 changes: 1 addition & 1 deletion src/channel/null-private-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NullChannel } from './null-channel';
*/
export class NullPrivateChannel extends NullChannel {
/**
* Trigger client event on the channel.
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): NullPrivateChannel {
return this;
Expand Down
5 changes: 5 additions & 0 deletions src/channel/presence-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface PresenceChannel extends Channel {
*/
joining(callback: Function): PresenceChannel;

/**
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): PresenceChannel;

/**
* Listen for someone leaving the channel.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/channel/pusher-encrypted-private-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PusherChannel } from './pusher-channel';
*/
export class PusherEncryptedPrivateChannel extends PusherChannel {
/**
* Trigger client event on the channel.
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): PusherEncryptedPrivateChannel {
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);
Expand Down
16 changes: 8 additions & 8 deletions src/channel/pusher-presence-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ export class PusherPresenceChannel extends PusherChannel implements PresenceChan
}

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

return this;
}

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

return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/channel/pusher-private-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PusherChannel } from './pusher-channel';
*/
export class PusherPrivateChannel extends PusherChannel {
/**
* Trigger client event on the channel.
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): PusherPrivateChannel {
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);
Expand Down
13 changes: 13 additions & 0 deletions src/channel/socketio-presence-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ export class SocketIoPresenceChannel extends SocketIoPrivateChannel implements P
return this;
}

/**
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): SocketIoPresenceChannel {
this.socket.emit('client event', {
channel: this.name,
event: `client-${eventName}`,
data: data,
});

return this;
}

/**
* Listen for someone leaving the channel.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/channel/socketio-private-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SocketIoChannel } from './socketio-channel';
*/
export class SocketIoPrivateChannel extends SocketIoChannel {
/**
* Trigger client event on the channel.
* Send a whisper event to other clients in the channel.
*/
whisper(eventName: string, data: any): SocketIoChannel {
this.socket.emit('client event', {
Expand Down