I'm attempting to write an IRC client using WebSockets. The IRC client I found on GitHub uses EventMachine, but I'm trying to use WebSockets as well to notify any connected clients when they're connected. However, I don't think I'm quite understanding EventMachine, because although the client successfully connects and joins the IRC channel, the puts 'Connected...'
nor the subsequent line gets executed.
I assume this is because of a fundamental misunderstanding of EventMachine on my behalf.
EM.run {
EventMachine::WebSocket.start(:host => '0.0.0.0', :port => 8080) do |websocket|
websocket.onopen {
irc = Net::YAIL.new(
:address => 'irc.my-example-server.net',
:port => 6667,
:username => 'MyExample',
:realname => 'My Example Bot',
:nicknames => ['MyExample1', 'MyExample2', 'MyExample3']
)
irc.on_welcome proc { |event|
irc.join('#ExampleChannel')
EM.next_tick {
puts 'Connected...'
websocket.send({ :message => 'Connected' })
}
}
irc.start_listening!
}
end
}