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

feature: multiple websocket connection #63

Open
asim-aashish opened this issue Nov 25, 2016 · 7 comments
Open

feature: multiple websocket connection #63

asim-aashish opened this issue Nov 25, 2016 · 7 comments

Comments

@asim-aashish
Copy link

Actioncable connects to only one websocket connection defined by
ActionCableConfig.wsUri
Multiple websocket connection and their channel management could be a feature

@b264
Copy link
Member

b264 commented Nov 25, 2016

I think if you want to use more than one actioncable server simultaneously, then probably a library with less abstraction would be a better fit. I don't really see a clear way to implement that cleanly. You could use the https://github.com/AngularClass/angular-websocket library and manage your own low-level ws connections or start with the Rails coffeescripts https://github.com/rails/rails/tree/d89238d767ddfbd3b32f6d5ec7fe5583e409973f/actioncable/app/assets/javascripts

@asim-aashish
Copy link
Author

I understand that there is no clear way to implement it, thanks for providing other possible solutions

@asim-aashish
Copy link
Author

It could be implemented with a complete refactor in a 2.0

@b264
Copy link
Member

b264 commented Nov 26, 2016

The purpose of this library when created was to get the actioncable and angular working together seamlessy with a high state of abstraction and ease of use-- there are lots of other options if you want to do more than that, but they involve more troubleshooting and edge-cases that this library hides away and handles automatically. I'm wondering, do you have an example of "some code you wish worked"? Like, what specifically do you want to do? I'm guessing make the config a class instead of a singleton?

var ws1= new ActionCableConfig("url1");
var ws2= new ActionCableConfig("url2");
var consumer1 = new ActionCableChannel("MyChannel", {user: 42, chat: 37}, ws1);
var consumer2 = new ActionCableChannel("MyChannel", {user: 42, chat: 37}, ws2);

The goal of handling reconnections and resubscriptions automatically after connection problems precludes doing it a lot of ways that would otherwise work.

@b264
Copy link
Member

b264 commented Nov 26, 2016

You could also fork this repo and just make 2 different ActionCableChannel classes that use 2 different URLs... though I'm not sure that is the best strategy

@asim-aashish
Copy link
Author

asim-aashish commented Nov 26, 2016

You put my thoughts beautifully, i was thinking of
ActionCableConfig.ws1.wsUri = url1
ActionCableConfig.ws2.wsUri = url2
var consumer1 = new ActionCableChannel("ws1.MyChannel", {user: 42, chat: 37});
but
var ws1= new ActionCableConfig(url1);
is much better

@b264
Copy link
Member

b264 commented Nov 26, 2016

Let me think about how that could work. The problem I am thinking about is the Rails meta tag and how to handle that, the <meta name="action-cable-url" content="ws://localhost:3000/cable"/> and if the websocket library this one depends on can do that as well

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

No branches or pull requests

2 participants