1
1
import { EventFormatter } from 'laravel-echo/src/util' ;
2
- import { Channel } from 'laravel-echo/src/channel/channel' ;
2
+ import { Channel as BaseChannel } from 'laravel-echo/src/channel/channel' ;
3
3
import { PresenceChannel } from "laravel-echo/src/channel" ;
4
- import { LaravelEchoApiGatewayWebsocket } from "./LaravelEchoApiGatewayWebsocket " ;
4
+ import { Websocket } from "./Websocket " ;
5
5
6
6
/**
7
7
* This class represents a Pusher channel.
8
8
*/
9
- export class ApiGatewayChannel extends Channel implements PresenceChannel {
9
+ export class Channel extends BaseChannel implements PresenceChannel {
10
10
/**
11
11
* The Pusher client instance.
12
12
*/
13
- socket : LaravelEchoApiGatewayWebsocket ;
13
+ socket : Websocket ;
14
14
15
15
/**
16
16
* The name of the channel.
17
17
*/
18
- name : any ;
18
+ name : string ;
19
19
20
20
/**
21
21
* Channel options.
22
22
*/
23
- options : any ;
23
+ options : object ;
24
24
25
25
/**
26
26
* The event formatter.
@@ -32,13 +32,13 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
32
32
/**
33
33
* Create a new class instance.
34
34
*/
35
- constructor ( socket : LaravelEchoApiGatewayWebsocket , name : any , options : any ) {
35
+ constructor ( socket : Websocket , name : string , options : object ) {
36
36
super ( ) ;
37
37
38
38
this . name = name ;
39
39
this . socket = socket ;
40
40
this . options = options ;
41
- this . eventFormatter = new EventFormatter ( this . options . namespace ) ;
41
+ this . eventFormatter = new EventFormatter ( this . options [ " namespace" ] ) ;
42
42
43
43
this . subscribe ( ) ;
44
44
}
@@ -54,13 +54,13 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
54
54
* Unsubscribe from a Pusher channel.
55
55
*/
56
56
unsubscribe ( ) : void {
57
- this . socket . unsubscribe ( this . name ) ;
57
+ this . socket . unsubscribe ( this ) ;
58
58
}
59
59
60
60
/**
61
61
* Listen for an event on the channel instance.
62
62
*/
63
- listen ( event : string , callback : Function ) : ApiGatewayChannel {
63
+ listen ( event : string , callback : Function ) : Channel {
64
64
this . on ( this . eventFormatter . format ( event ) , callback ) ;
65
65
66
66
return this ;
@@ -69,7 +69,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
69
69
/**
70
70
* Stop listening for an event on the channel instance.
71
71
*/
72
- stopListening ( event : string , callback ?: Function ) : ApiGatewayChannel {
72
+ stopListening ( event : string , callback ?: Function ) : Channel {
73
73
if ( this . listeners [ event ] && ( ! callback || this . listeners [ event ] === callback ) ) {
74
74
delete this . listeners [ event ]
75
75
}
@@ -80,7 +80,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
80
80
/**
81
81
* Register a callback to be called anytime a subscription succeeds.
82
82
*/
83
- subscribed ( callback : Function ) : ApiGatewayChannel {
83
+ subscribed ( callback : Function ) : Channel {
84
84
this . on ( 'subscription_succeeded' , ( ) => {
85
85
callback ( ) ;
86
86
} ) ;
@@ -91,7 +91,7 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
91
91
/**
92
92
* Register a callback to be called anytime a subscription error occurs.
93
93
*/
94
- error ( callback : Function ) : ApiGatewayChannel {
94
+ error ( callback : Function ) : Channel {
95
95
this . on ( 'error' , ( status ) => {
96
96
callback ( status ) ;
97
97
} ) ;
@@ -102,19 +102,19 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
102
102
/**
103
103
* Bind a channel to an event.
104
104
*/
105
- on ( event : string , callback : Function ) : ApiGatewayChannel {
105
+ on ( event : string , callback : Function ) : Channel {
106
106
this . listeners [ event ] = callback
107
107
108
108
return this ;
109
109
}
110
110
111
- handleEvent ( event : string , data : object ) {
111
+ handleEvent ( event : string , data : object ) : void {
112
112
if ( this . listeners [ event ] ) {
113
113
this . listeners [ event ] ( event , data )
114
114
}
115
115
}
116
116
117
- whisper ( event : string , data : object ) : ApiGatewayChannel {
117
+ whisper ( event : string , data : object ) : Channel {
118
118
this . socket . send ( {
119
119
event,
120
120
data,
@@ -123,21 +123,27 @@ export class ApiGatewayChannel extends Channel implements PresenceChannel {
123
123
return this ;
124
124
}
125
125
126
- here ( callback : Function ) : ApiGatewayChannel {
126
+ here ( callback : Function ) : Channel {
127
+ // TODO: implement
128
+
127
129
return this
128
130
}
129
131
130
132
/**
131
133
* Listen for someone joining the channel.
132
134
*/
133
- joining ( callback : Function ) : ApiGatewayChannel {
135
+ joining ( callback : Function ) : Channel {
136
+ // TODO: implement
137
+
134
138
return this
135
139
}
136
140
137
141
/**
138
142
* Listen for someone leaving the channel.
139
143
*/
140
- leaving ( callback : Function ) : ApiGatewayChannel {
144
+ leaving ( callback : Function ) : Channel {
145
+ // TODO: implement
146
+
141
147
return this
142
148
}
143
149
}
0 commit comments