Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consuming 2 channels on one connection #11

Open
jseravalli opened this issue Jun 10, 2017 · 2 comments
Open

Consuming 2 channels on one connection #11

jseravalli opened this issue Jun 10, 2017 · 2 comments

Comments

@jseravalli
Copy link

I have a question about how the code works, say I have 2 channels, NotificationsChannel and ChatsChannel, then I would go and do:

this.cable.subscribe(url, 'NotificationsChannel');
this.cable.subscribe(url, ChatsChannel');

since every subscribe call does a setCable which in turn calls ActionCable.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 and unsubscribe(channel) methods.

@bhaveshvyas007
Copy link

I have a same question, I want to subscribe to same channel with different parameters:

But the broadcaster.on( ChannelName, ...

is same.

@jaybloke
Copy link

jaybloke commented Dec 4, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants