Created
November 22, 2013 14:42
-
-
Save NiDi/7600937 to your computer and use it in GitHub Desktop.
POC: Websockets für Projektseminar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//= require jquery | |
//= require jquery_ujs | |
//= require turbolinks | |
//= require websocket_rails/main | |
//= require_tree . | |
$ -> | |
dispatcher = new WebSocketRails('localhost:3000/websocket') | |
dispatcher.bind('new_message', (data) -> | |
$('body').append("<p>"+data.message+"</p>") | |
) | |
$('#send').on('click', -> | |
dispatcher.trigger('new_message', {data: $('#my-message').val()}) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WebsocketRails::EventMap.describe do | |
# You can use this file to map incoming events to controller actions. | |
# One event can be mapped to any number of controller actions. The | |
# actions will be executed in the order they were subscribed. | |
# | |
# Uncomment and edit the next line to handle the client connected event: | |
subscribe :new_message, :to => MessagesController, :with_method => :new_message | |
# | |
# Here is an example of mapping namespaced events: | |
# namespace :product do | |
# subscribe :new, :to => ProductController, :with_method => :new_product | |
# end | |
# The above will handle an event triggered on the client like `product.new`. | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#.... | |
gem 'websocket-rails' | |
gem 'thin' | |
#... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1> My Chat</h1> | |
<input type="text" name="fname" id="my-message"> | |
<a href="javascript:void(0)" id="send"> send </a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessagesController < WebsocketRails::BaseController | |
def new_message | |
broadcast_message 'new_message', {message: message} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment