If you want to implement something a little more robust, I suggest:
1) Grab ejabberd (http://www.process-one.net/en/ejabberd/) as a
full-featured jabber chat server
2) Implement the proper jabber protocol. Two good options:
a) Grab JWChat (http://jwchat.sourceforge.net/) for the full chat client
or,
b) Grab JSJaC (http://jsjac.jabberstudio.org/) for just the underlying
communication library
Probably a little more work, but it's already a full-featured, open-souce,
open-protocol chat client that way, and would potentially work with thick
clients as well, if that interests you...
-Jerod
On 2/3/07, Fabian Lange <[EMAIL PROTECTED]> wrote:
>
>
> Okay,
> this was much simpler than expected.
> SO ill share it :)
>
> I need two divs: one called chat. The other one called ts. Its holding a
> timestamp when the last update was made.
>
>
> <script type="text/javascript">
> //<![CDATA[
> new PeriodicalExecuter(function() {
> new Ajax.Request('/chat/get',
> {asynchronous:true, evalScripts:false,
> onComplete:function(request, json){updateJSON(request, json)},
> parameters:'ts=' + $('ts').innerHTML})}, 10)
> //]]>
>
> var chat = $('chat');
> function updateJSON(request, json)
> {
> var nbElementsInResponse = json.length;
> for (var i = 0; i < nbElementsInResponse; i++){
> if (json[i][0] == 'c') {
> var doScroll = false;
> if(chat.scrollTop == (chat.scrollHeight - 200)){ doScroll = true}
> Element.update(chat, chat.innerHTML + json[i][1]);
> if(doScroll){ chat.scrollTop = chat.scrollHeight }
> } else {
> Element.update(json[i][0], json[i][1]);
> }
> }
> }
> //]]>
> </script>
>
> The get serverside action will check if there are new messages to deliver.
> If that's the case its put into json. And ts is updated to a new
> timestamp.
>
> To input data
> <form onsubmit="new Ajax.Request('/chat/send',
> {asynchronous:true, evalScripts:false,
> onComplete:function(request, json){updateJSON(request,
> json);$('message').value='';$('go').disabled=false},
> onLoading:function(request, json){$('go').disabled=true},
> parameters:Form.serialize(this)}); return false;" action="/chat/send"
> method="post">
>
> <input type="text" name="message" id="message" value="" />
> <input type="submit" name="commit" value="Go" id="go" />
> </form>
>
>
> The send action on the server will just add the message into the database
> or
> memory and then directly call the get action described above
>
> Quite neat. And rapid to prototype. Now the finetuning will start.
> Comments
> always welcome
>
> .: Fabian
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---