Skip to content
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

add pusher private-encrypted #263 #264

Merged
merged 3 commits into from
Apr 3, 2020
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
1 change: 1 addition & 0 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './channel';
export * from './presence-channel';
export * from './pusher-channel';
export * from './pusher-private-channel';
export * from './pusher-encrypted-private-channel';
export * from './pusher-presence-channel';
export * from './socketio-channel';
export * from './socketio-private-channel';
Expand Down
15 changes: 15 additions & 0 deletions src/channel/pusher-encrypted-private-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PusherChannel } from './pusher-channel';

/**
* This class represents a Pusher private channel.
*/
export class PusherEncryptedPrivateChannel extends PusherChannel {
/**
* Trigger client event on the channel.
*/
whisper(eventName: string, data: any): PusherEncryptedPrivateChannel {
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);

return this;
}
}
23 changes: 22 additions & 1 deletion src/connector/pusher-connector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Connector } from './connector';
import { PusherChannel, PusherPrivateChannel, PusherPresenceChannel, PresenceChannel } from './../channel';
import {
PusherChannel,
PusherPrivateChannel,
PusherEncryptedPrivateChannel,
PusherPresenceChannel,
PresenceChannel,
} from './../channel';

/**
* This class creates a connector to Pusher.
Expand Down Expand Up @@ -55,6 +61,21 @@ export class PusherConnector extends Connector {
return this.channels['private-' + name];
}

/**
* Get a private encrypted channel instance by name.
*/
encryptedPrivateChannel(name: string): PusherChannel {
if (!this.channels['private-encrypted-' + name]) {
this.channels['private-encrypted-' + name] = new PusherEncryptedPrivateChannel(
this.pusher,
'private-encrypted-' + name,
this.options
);
}

return this.channels['private-encrypted-' + name];
}

/**
* Get a presence channel instance by name.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export default class Echo {
return this.connector.privateChannel(channel);
}

/**
* Get a private encrypted channel instance by name.
*/
encryptedPrivate(channel: string): Channel {
return this.connector.encryptedPrivateChannel(channel);
}

/**
* Get the Socket ID for the connection.
*/
Expand Down Expand Up @@ -133,7 +140,7 @@ export default class Echo {
* Register an Axios HTTP interceptor to add the X-Socket-ID header.
*/
registerAxiosRequestInterceptor(): any {
axios.interceptors.request.use(config => {
axios.interceptors.request.use((config) => {
if (this.socketId()) {
config.headers['X-Socket-Id'] = this.socketId();
}
Expand Down