@@ -3,6 +3,8 @@ import { Channel as BaseChannel } from 'laravel-echo/src/channel/channel';
3
3
import { PresenceChannel } from "laravel-echo/src/channel" ;
4
4
import { Websocket } from "./Websocket" ;
5
5
6
+ const LOG_PREFIX = '[LE-AG-Channel]' ;
7
+
6
8
/**
7
9
* This class represents a Pusher channel.
8
10
*/
@@ -45,20 +47,26 @@ export class Channel extends BaseChannel implements PresenceChannel {
45
47
* Subscribe to a Pusher channel.
46
48
*/
47
49
subscribe ( ) : any {
50
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } subscribe for channel ${ this . name } ...` ) ;
51
+
48
52
this . socket . subscribe ( this )
49
53
}
50
54
51
55
/**
52
56
* Unsubscribe from a Pusher channel.
53
57
*/
54
58
unsubscribe ( ) : void {
59
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } unsubscribe for channel ${ this . name } ...` ) ;
60
+
55
61
this . socket . unsubscribe ( this ) ;
56
62
}
57
63
58
64
/**
59
65
* Listen for an event on the channel instance.
60
66
*/
61
- listen ( event : string , callback : Function ) : Channel {
67
+ listen ( event : string , callback : Function ) : this {
68
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } listen to ${ event } for channel ${ this . name } ...` ) ;
69
+
62
70
this . on ( this . eventFormatter . format ( event ) , callback ) ;
63
71
64
72
return this ;
@@ -67,7 +75,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
67
75
/**
68
76
* Stop listening for an event on the channel instance.
69
77
*/
70
- stopListening ( event : string , callback ?: Function ) : Channel {
78
+ stopListening ( event : string , callback ?: Function ) : this {
79
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } stop listening to ${ event } for channel ${ this . name } ...` ) ;
80
+
71
81
this . socket . unbindEvent ( this , event , callback )
72
82
73
83
return this ;
@@ -76,7 +86,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
76
86
/**
77
87
* Register a callback to be called anytime a subscription succeeds.
78
88
*/
79
- subscribed ( callback : Function ) : Channel {
89
+ subscribed ( callback : Function ) : this {
90
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } subscribed for channel ${ this . name } ...` ) ;
91
+
80
92
this . on ( 'subscription_succeeded' , ( ) => {
81
93
callback ( ) ;
82
94
} ) ;
@@ -87,7 +99,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
87
99
/**
88
100
* Register a callback to be called anytime a subscription error occurs.
89
101
*/
90
- error ( callback : Function ) : Channel {
102
+ error ( callback : Function ) : this {
103
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } error for channel ${ this . name } ...` ) ;
104
+
91
105
this . on ( 'error' , ( status ) => {
92
106
callback ( status ) ;
93
107
} ) ;
@@ -99,12 +113,14 @@ export class Channel extends BaseChannel implements PresenceChannel {
99
113
* Bind a channel to an event.
100
114
*/
101
115
on ( event : string , callback : Function ) : Channel {
116
+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } on ${ event } for channel ${ this . name } ...` ) ;
117
+
102
118
this . socket . bind ( this , event , callback )
103
119
104
120
return this ;
105
121
}
106
122
107
- whisper ( event : string , data : object ) : Channel {
123
+ whisper ( event : string , data : object ) : this {
108
124
let channel = this . name ;
109
125
let formattedEvent = "client-" + event ;
110
126
this . socket . send ( {
@@ -116,7 +132,7 @@ export class Channel extends BaseChannel implements PresenceChannel {
116
132
return this ;
117
133
}
118
134
119
- here ( callback : Function ) : Channel {
135
+ here ( callback : Function ) : this {
120
136
// TODO: implement
121
137
122
138
return this
@@ -125,7 +141,7 @@ export class Channel extends BaseChannel implements PresenceChannel {
125
141
/**
126
142
* Listen for someone joining the channel.
127
143
*/
128
- joining ( callback : Function ) : Channel {
144
+ joining ( callback : Function ) : this {
129
145
// TODO: implement
130
146
131
147
return this
@@ -134,9 +150,11 @@ export class Channel extends BaseChannel implements PresenceChannel {
134
150
/**
135
151
* Listen for someone leaving the channel.
136
152
*/
137
- leaving ( callback : Function ) : Channel {
153
+ leaving ( callback : Function ) : this {
138
154
// TODO: implement
139
155
140
156
return this
141
157
}
142
158
}
159
+
160
+ export { PresenceChannel } ;
0 commit comments