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

Emit events to client #1

Open
ngshvanam52 opened this issue Jun 14, 2012 · 5 comments
Open

Emit events to client #1

ngshvanam52 opened this issue Jun 14, 2012 · 5 comments

Comments

@ngshvanam52
Copy link

Server to client emitting the events is not happening. Can please provide the necessary details. My email Id is [email protected]
Thank you.

@codeholic
Copy link

I experience the same problem. I tried the following code. The block that invokes send_message is executed, but the message is not being sent. What am I probably doing wrong?

require 'eventmachine-tail'
require 'json'

class TailAction < Cramp::Action
  include SocketIo::Websocket

  on_start :subscribe
  on_finish :unsubscribe

  @@channel = EventMachine::Channel.new
  @@filetail = EventMachine::file_tail('/tmp/ponytail') do |filetail, line|
    @@channel.push line
  end

  def subscribe
    @sid = @@channel.subscribe do |m|
      send_message(data: { message: m }.to_json)
    end
  end

  def unsubscribe
    @@channel.unsubscribe(@sid) if @sid
  end
end
<html>
<head>
  <title>Ponytail</title>
  <script type="text/javascript" src="javascripts/socket.io.min.js"></script>
  <script>
    var socket = io.connect('/socket.io');
    socket.on('message', function(message) {
      alert(message);
    });
  </script>
</head>
<body>
</body>
</html>

@erithmetic
Copy link
Owner

I've abandoned this project for two reasons: 1.) I'm not longer working on the problem this tool attempted to solve, and 2.) Cramp has been superseded by Celluloid/Lattice https://github.com/celluloid/lattice

If I find myself needing a Ruby socket-io implementation, I'd focus on a lattice-based service.

I'll accept pull requests, but I have no plans of maintaining this.

@codeholic
Copy link

Thank you for your feedback!

@ghost
Copy link

ghost commented Sep 2, 2012

I actually happen to be working on an app right now where this library would be perfect (Socket.IO without dealing with JS!).

I noticed you mentioned Lattice, but as far as I can tell, that is completely unfinished - there is no real code in the lib folder, besides a script that sets a VERSION constant. Am I missing something?

Besides that, do you have any other recommendations on libraries that may be useful for building a WebSocket application?

Thanks in advance!

@codeholic
Copy link

I decided not to use WebSockets, after all. SSE (with long polling fallback for IE) seemed to me the way to go. Cramp supports both out of box.

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

No branches or pull requests

3 participants