Open jseravalli opened 7 years ago
I have a same question, I want to subscribe to same channel with different parameters:
But the broadcaster.on( ChannelName, ...
is same.
I too am having the same problem... I'm finding it hard to grasp the set up. For example:
this.ng2Cable.subscribe(url, 'MessagesChannel');
Why do we need to subscribe to an initial channel when making the connection? Seems kind of redundant as I then also need to do the following:
this.broadcaster.on('MessagesChannel').subscribe(...)
Then If I want to subscribe to an additional channel, I need to do the following:
this.ng2Cable.subscribe(url, 'OtherChannel');
this.broadcaster.on('OtherChannel').subscribe(...)
Which unnecessarily opens up another WS connection to the server.
Perhaps this would be more intuitive:
this.subscription = this.ng2cable.connect(url: string).subscribe(); // connect to server
this.subscription.unsubscribe(); // disconnect from server
this.subscription = this.broadcaster.on('ChannelName').subscribe(...) // subscribe to channel
this.subscription.unsubscribe(); // unsubscribe from channel
Just my two cents worth.
I have a question about how the code works, say I have 2 channels,
NotificationsChannel
andChatsChannel
, then I would go and do:since every
subscribe
call does asetCable
which in turn callsActionCable.createConsumer
isn't this creating 2 connections to the same cable for the 2 channels?Sorry if this obvious, but I wanted to make sure since I was thinking it might be possible to have the cable support several channels with the same consumer and have
disconnect
andunsubscribe(channel)
methods.