postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

env.channel does not exist

wolfscaptain opened this issue · comments

After going and debugging a little since the WebSocket example didn't want to work (got stuck in an infinite loop in on_close), it looks like I just missed the UPGRADE_DATA constant since "gem install goliath" doesn't install updated files.

Now I can open a WebSocket connection, but I can't do anything with it since env.channel does not exist. I looked through the source and it really isn't defined anywhere, although the example uses it.

The example also includes a file called "pp" which doesn't exist, not sure what that's supposed to be.

Can you put a little documentation? what is env.subscription in the first place? I don't see it defined in Rack.

+1 for documentation.. Channel does exist though, it is defined in the config file for websocket app: https://github.com/postrank-labs/goliath/blob/master/examples/config/websocket.rb

I see. Where is config defined, though? I set the channel manually in the WebSocket end point (just @channel = EM::Channel.new) and it works, but it would be nice to have it beforehand in env.

Thanks.

Goliath by convention looks in config/{name_of_api}.rb for the appropriate config file. You can override it by specifying a -c config_path. The whole point of setting up the channel in the config is to make it available across all requests. Hence env.channel is/should be accesible as is -- exactly what you're asking for. Take a look at some of the other examples to see the config stuff in action.

If it is defined in config, every connection shares the same end point so you automatically get some sort of a chat without any further work.
It really isn't the behavior I was looking for (which is every person sharing a different end point), but it is funny and useful as it is.
For the other behavior I will define the channel like I did before.

Thanks :)