Web Chat, Cross Browser

Hi all,

I am newly learning Rails and playing with Web Chat app. I looked
through what other people have done. I tested the following very
naive, skeleton app. It seems to work in my local machine when I open
two Firefox (or two Safari). But it does not work cross browser, eg,
Firefox-Safari. Strange? What’s going on? Thanks.

  • index.rhtml
    <% form_remote_tag :url => {:action => ‘say’} do %>
    <%= text_field_tag ‘said’ %>
    <%= submit_tag ‘Say’ %>
    <% end %>

<%= periodically_call_remote :url => {:action =>
‘get_new_line’ }, :frequency => 1.0 %>

  • chat_controller.rb
    def say
    session[:what_said] = params[:said]
    @line1 = session[:what_said]
    end

def get_new_line
@line2 = session[:what_said]
end

  • say.rhtml
    <%= @line1 %>

  • get_new_line.rhtml
    <%= @line2 %>

I would recommend going against the Rails option here as you’re making a
request at least once every second to an action in your application.
Imagine if 10 people were in the chat, that would mean 10 requests per
second.

Think of an alternative option here, like an IRC server or similar.

On 09 Feb 2008, at 08:01, Ryan B. wrote:

I would recommend going against the Rails option here as you’re
making a
request at least once every second to an action in your application.
Imagine if 10 people were in the chat, that would mean 10 requests per
second.

Think of an alternative option here, like an IRC server or similar.

Campfire does it, so it does work when done right.

You could have a look at juggernaut, does use a flash file and extra
process running on the server.

http://juggernaut.rubyforge.org/

Best regards

Peter De Berdt

On 9 Feb 2008, at 05:58, Sy wrote:

<% form_remote_tag :url => {:action => ‘say’} do %>
@line1 = session[:what_said]
end

def get_new_line
@line2 = session[:what_said]
end

Are you storing everything in the session ? The session will be stored
per user (ie per browser) so it’s not surprising it doesn’t work.

Fred

Hmm, I see. I guess everything has to be stored in models. Thanks.

On Feb 9, 4:16 am, Frederick C. [email protected]

Yeah, I should try Juggernaut. But I wonder if my web host will allow
push server stuff.
Thanks.

Yea just wanted to second the juggernaut option. I am using it and it
works great.

And a third from me. I met the developer of Juggernaut at RailsConf
and saw a demo. Very slick. It uses a small flash object to keep a
persistent connection open between client and server so you eliminate
a lot of issues there. From a development perspective it was
basically as simple as saying “open chat channel 9” (work out the
details for your app) and then the client/browser just listens.

Another option, if you’re shopping, is Jabber. I was leaning towards
this until I ran into Juggernaut.

Good luck,
AndyV

On Feb 9, 5:32 am, Nathan E. [email protected]

Sly -

On 9-Feb-08, at 3:47 PM, Sy wrote:

Yeah, I should try Juggernaut. But I wonder if my web host will allow
push server stuff.
Thanks.

if you’re not adverse to having your chat scripts being stored on a
public service lingr.com can be integrated easily in a day.

I’ve had nice success making private password protected chat rooms
for a community using lingr.

You can find docs on their blog, etc.

cheers,
Jodi

On Feb 10, 2008 3:43 PM, AndyV [email protected] wrote:

Good luck,
AndyV

On Feb 9, 5:32 am, Nathan E. [email protected]
wrote:

Yea just wanted to second the juggernaut option. I am using it and it
works great.

Posted viahttp://www.ruby-forum.com/.

Jabber is a communication protocol. You’ll still need a Comet
(official term) implementation like Juggernaut to push chats out to
the user or do polling like Gmail’s in-browser chat client does
(IIRC),

Jason

Right, Jabber won’t allow a persistent connection without some “comet”
alternative. I already advocated Juggernaut but here is another
alternative:

http://shooting-star.rubyforge.org/wiki/wiki.pl?Making_A_Chat_System_Within_5_Minutes

That is using a more standard comet implementation called shooting_star.

Like Juggernaut, it opens a persistent connection which can be used for
implementing a chat system.

I have looked at both and I chose Juggernaut but it easily could have
been the wrong decision. However, juggernaut was so easy to use and it
worked so I had no reason to move away from it. As long as the browser
has Flash, it works like a charm.

Thank you all for great suggestions! In fact, I installed Juggernat
today.
I followed its README file example included below. It works, but
whenever Rails call is made, alert window ( "Juggernaut: Received
data:
try { … " ) pops up all the time. How can I block this?

-chat controller:

class ChatController < ApplicationController
def index
end

def send_data
render :juggernaut do |page|
page.insert_html :top, ‘chat_data’, “

  • #{h
    params[:chat_input]}

  • end
    render :nothing => true
    end
    end

    -index.rhtml

    <%= javascript_include_tag :defaults, :juggernaut %> <%= juggernaut %> <%= form_remote_tag( :url => { :action => :send_data }, :complete => "$('chat_input').value = ''" ) %> <%= text_field_tag( 'chat_input', '', { :size => 20, :id => 'chat_input'} ) %> <%= submit_tag "Add" %>

    On Feb 10, 4:13 pm, Nathan E. <rails-mailing-l…@andreas-

    Yea, I get that too. It only happens in development (on your local PC).
    It is for your debugging purposes. Once deployed to the server, these
    messages are not displayed. (Make sure on the server, the juggernaut
    config file is set to production mode).

    Great, thanks!

    On Feb 11, 12:05 am, Nathan E. <rails-mailing-l…@andreas-