Skip to content

Instantly share code, notes, and snippets.

@tobias
Created July 3, 2014 20:24
Show Gist options
  • Save tobias/941e6594bd9b117e4c43 to your computer and use it in GitHub Desktop.
Save tobias/941e6594bd9b117e4c43 to your computer and use it in GitHub Desktop.
require 'torquebox-web'
require 'torquebox-messaging'
topic = TorqueBox::Messaging::Topic.new('browser-messages')
TorqueBox::Web::Server.sockjs('/messages').on_connection do |conn|
listener = topic.listen do |m|
conn.write(m)
end
conn.on_data do |data|
topic.publish(data)
end
conn.on_close do
listener.close
end
topic.publish("Welcome!")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment