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

Expose server instance #5

Open
ioquatix opened this issue Nov 19, 2024 · 1 comment
Open

Expose server instance #5

ioquatix opened this issue Nov 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ioquatix
Copy link

ioquatix commented Nov 19, 2024

ActionCable.server in Channel instances is a code smell. It makes testing more difficult than it should be (parallel tests might have more than one server).

I think Connection should expose server, e.g.

class TestChannel < ActionCable::Channel::Base
	def broadcast(data)
		# ActionCable.server.broadcast ... # bad!!!
		self.server.broadcast("testing-#{test_id}", data)
	end
	
	private def server
		@connection.send(:server)
	end

I don't think we should encourage users to write ActionCable.server except as a last resort.

@palkan
Copy link
Member

palkan commented Nov 25, 2024

Agree on that. I never liked it.

I'd even prefer to have just broadcast within the channel, not even server.broadcast, but we already have broadcast_to that has a slightly different logic (prepend stream names with the channel class name).

Given current design and compatibility with the previous version, probably, having connection.broadcast(...) is the way to go.

@palkan palkan added the enhancement New feature or request label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@ioquatix @palkan and others