Skip to content

Commit f0448c5

Browse files
authored
Merge pull request #264 from it-can/master
add pusher private-encrypted #263
2 parents 43907da + 1aea3fe commit f0448c5

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/channel/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './channel';
22
export * from './presence-channel';
33
export * from './pusher-channel';
44
export * from './pusher-private-channel';
5+
export * from './pusher-encrypted-private-channel';
56
export * from './pusher-presence-channel';
67
export * from './socketio-channel';
78
export * from './socketio-private-channel';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { PusherChannel } from './pusher-channel';
2+
3+
/**
4+
* This class represents a Pusher private channel.
5+
*/
6+
export class PusherEncryptedPrivateChannel extends PusherChannel {
7+
/**
8+
* Trigger client event on the channel.
9+
*/
10+
whisper(eventName: string, data: any): PusherEncryptedPrivateChannel {
11+
this.pusher.channels.channels[this.name].trigger(`client-${eventName}`, data);
12+
13+
return this;
14+
}
15+
}

src/connector/pusher-connector.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Connector } from './connector';
2-
import { PusherChannel, PusherPrivateChannel, PusherPresenceChannel, PresenceChannel } from './../channel';
2+
import {
3+
PusherChannel,
4+
PusherPrivateChannel,
5+
PusherEncryptedPrivateChannel,
6+
PusherPresenceChannel,
7+
PresenceChannel,
8+
} from './../channel';
39

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

64+
/**
65+
* Get a private encrypted channel instance by name.
66+
*/
67+
encryptedPrivateChannel(name: string): PusherChannel {
68+
if (!this.channels['private-encrypted-' + name]) {
69+
this.channels['private-encrypted-' + name] = new PusherEncryptedPrivateChannel(
70+
this.pusher,
71+
'private-encrypted-' + name,
72+
this.options
73+
);
74+
}
75+
76+
return this.channels['private-encrypted-' + name];
77+
}
78+
5879
/**
5980
* Get a presence channel instance by name.
6081
*/

src/echo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export default class Echo {
9191
return this.connector.privateChannel(channel);
9292
}
9393

94+
/**
95+
* Get a private encrypted channel instance by name.
96+
*/
97+
encryptedPrivate(channel: string): Channel {
98+
return this.connector.encryptedPrivateChannel(channel);
99+
}
100+
94101
/**
95102
* Get the Socket ID for the connection.
96103
*/
@@ -133,7 +140,7 @@ export default class Echo {
133140
* Register an Axios HTTP interceptor to add the X-Socket-ID header.
134141
*/
135142
registerAxiosRequestInterceptor(): any {
136-
axios.interceptors.request.use(config => {
143+
axios.interceptors.request.use((config) => {
137144
if (this.socketId()) {
138145
config.headers['X-Socket-Id'] = this.socketId();
139146
}

0 commit comments

Comments
 (0)