@@ -3,6 +3,8 @@ import { Channel as BaseChannel } from 'laravel-echo/src/channel/channel';
33import { PresenceChannel } from "laravel-echo/src/channel" ;
44import { Websocket } from "./Websocket" ;
55
6+ const LOG_PREFIX = '[LE-AG-Channel]' ;
7+
68/**
79 * This class represents a Pusher channel.
810 */
@@ -45,20 +47,26 @@ export class Channel extends BaseChannel implements PresenceChannel {
4547 * Subscribe to a Pusher channel.
4648 */
4749 subscribe ( ) : any {
50+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } subscribe for channel ${ this . name } ...` ) ;
51+
4852 this . socket . subscribe ( this )
4953 }
5054
5155 /**
5256 * Unsubscribe from a Pusher channel.
5357 */
5458 unsubscribe ( ) : void {
59+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } unsubscribe for channel ${ this . name } ...` ) ;
60+
5561 this . socket . unsubscribe ( this ) ;
5662 }
5763
5864 /**
5965 * Listen for an event on the channel instance.
6066 */
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+
6270 this . on ( this . eventFormatter . format ( event ) , callback ) ;
6371
6472 return this ;
@@ -67,7 +75,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
6775 /**
6876 * Stop listening for an event on the channel instance.
6977 */
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+
7181 this . socket . unbindEvent ( this , event , callback )
7282
7383 return this ;
@@ -76,7 +86,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
7686 /**
7787 * Register a callback to be called anytime a subscription succeeds.
7888 */
79- subscribed ( callback : Function ) : Channel {
89+ subscribed ( callback : Function ) : this {
90+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } subscribed for channel ${ this . name } ...` ) ;
91+
8092 this . on ( 'subscription_succeeded' , ( ) => {
8193 callback ( ) ;
8294 } ) ;
@@ -87,7 +99,9 @@ export class Channel extends BaseChannel implements PresenceChannel {
8799 /**
88100 * Register a callback to be called anytime a subscription error occurs.
89101 */
90- error ( callback : Function ) : Channel {
102+ error ( callback : Function ) : this {
103+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } error for channel ${ this . name } ...` ) ;
104+
91105 this . on ( 'error' , ( status ) => {
92106 callback ( status ) ;
93107 } ) ;
@@ -99,12 +113,14 @@ export class Channel extends BaseChannel implements PresenceChannel {
99113 * Bind a channel to an event.
100114 */
101115 on ( event : string , callback : Function ) : Channel {
116+ this . options [ "debug" ] && console . log ( `${ LOG_PREFIX } on ${ event } for channel ${ this . name } ...` ) ;
117+
102118 this . socket . bind ( this , event , callback )
103119
104120 return this ;
105121 }
106122
107- whisper ( event : string , data : object ) : Channel {
123+ whisper ( event : string , data : object ) : this {
108124 let channel = this . name ;
109125 let formattedEvent = "client-" + event ;
110126 this . socket . send ( {
@@ -116,7 +132,7 @@ export class Channel extends BaseChannel implements PresenceChannel {
116132 return this ;
117133 }
118134
119- here ( callback : Function ) : Channel {
135+ here ( callback : Function ) : this {
120136 // TODO: implement
121137
122138 return this
@@ -125,7 +141,7 @@ export class Channel extends BaseChannel implements PresenceChannel {
125141 /**
126142 * Listen for someone joining the channel.
127143 */
128- joining ( callback : Function ) : Channel {
144+ joining ( callback : Function ) : this {
129145 // TODO: implement
130146
131147 return this
@@ -134,9 +150,11 @@ export class Channel extends BaseChannel implements PresenceChannel {
134150 /**
135151 * Listen for someone leaving the channel.
136152 */
137- leaving ( callback : Function ) : Channel {
153+ leaving ( callback : Function ) : this {
138154 // TODO: implement
139155
140156 return this
141157 }
142158}
159+
160+ export { PresenceChannel } ;
0 commit comments