@@ -47,10 +47,14 @@ enum MessageType {
4747
4848type MessageHandlers = Record < MessageType , MessageHandler > ;
4949
50- interface SubscriptionWithWhisper extends ActionCable . Channel {
51- channel : {
52- whisper ( data : any ) : boolean ;
53- } ;
50+ // AnyCable is an ActionCable compatible websocket implementation, which offers a "whisper" feature
51+ // for publishing transient broadcasts between clients, without touching your Rails backend
52+ // https://docs.anycable.io/rails/extensions?id=whispering
53+ // It was built with cursor position sharing in mind, and works great for awareness updates
54+ // Make sure to add `whisper: true` to your Rails channels when using this provider and AnyCable
55+ // https://docs.anycable.io/edge/rails/extensions?id=whispering
56+ interface ChannelWithWhisper extends ActionCable . Channel {
57+ whisper ( data : any ) : boolean ;
5458}
5559
5660const permissionDeniedHandler = (
@@ -219,7 +223,7 @@ export class WebsocketProvider {
219223 const update = encodeBinaryToBase64 ( buffer ) ;
220224
221225 if ( whisper && hasWhisper ( this . channel ) ) {
222- this . channel . channel . whisper ( { update } ) ;
226+ this . channel . whisper ( { update } ) ;
223227 } else {
224228 this . channel ?. send ( { update } ) ;
225229 }
@@ -368,13 +372,10 @@ function decodeBase64ToBinary(update: string) {
368372 return Uint8Array . from ( atob ( update ) , c => c . charCodeAt ( 0 ) ) ;
369373}
370374
371- function hasWhisper ( channel : ActionCable . Channel | undefined ) : channel is SubscriptionWithWhisper {
375+ function hasWhisper ( channel : ActionCable . Channel | undefined ) : channel is ChannelWithWhisper {
372376 return (
373377 channel !== undefined &&
374- 'channel' in channel &&
375- channel . channel !== null &&
376- typeof channel . channel === 'object' &&
377- 'whisper' in channel . channel &&
378- typeof channel . channel . whisper === 'function'
378+ 'whisper' in channel &&
379+ typeof channel . whisper === 'function'
379380 ) ;
380381}
0 commit comments