Arc Forumnew | comments | leaders | submitlogin
2 points by thaddeus 5431 days ago | link | parent

Here's an option:

  HTML Layout:

  <html>
  <head>
    <script type="text/javascript">
      (pr (get+xmlhttp (string "chatlog?room=" room "&max=" maxm))
          (checkif+xmlhttp (string "checkchat?room=" room))
    </script>
  </head>
  <body onLoad="javascript: GetData();">
     <div id='chatlog'  ....>
     </div>
   </body>
  <html>

  Services:
1. chatlog?room=1&max=20 , this service returns the conversation data you would like placed in your div having an id of 'chatlog'. The room is the id for a conversation and max is the number of items you want returned from the conversation history.

2. checkchat?room=1, this service checks to see if there's been an update in the chatlog since the last time the user checked. So you need to store the last time checked, and compare that to the timestamp of when the chatlog, for that room, was last updated. Comparing the two will return either Y or N. Y will trigger the update. There's javascript noted below that will auto check this for you.

  Javascript: 

  (def get+xmlhttp (url) 
     (string 
	"function GetData(){
	  if (window.XMLHttpRequest){
          var xmlHttp = new XMLHttpRequest ();}
          if (window.ActiveXObject){
          var xmlHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}
          xmlHttp.open (\"GET\",\"" url "\", false);
          xmlHttp.send (null);
          var targetNode = document.getElementById (\"chatlog\");
          targetNode.innerHTML = xmlHttp.responseText;};"))

  (def checkif+xmlhttp (url)
    (string 
	   "function CheckChatLog(){
	      if (window.XMLHttpRequest){
                var textHttp = new XMLHttpRequest ();}
                if (window.ActiveXObject){
                var textHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}
                textHttp.open (\"GET\",\"" url "\", false);
                textHttp.send (null);
                if (textHttp.responseText == \"Y\") GetData();};	     
           window.setInterval(\"CheckChatLog()\",5000);"))

The 'CheckChatLog' function checks the 'checkchat' service to see if there's been an update. If there has been, then 'GetData' is called which pushes the data into your 'chatlog' div.

Notice 'checkif+xmlhttp' has 'window.setInterval', so the js will periodically run 'CheckChatLog' for you - you may want to tweak the 5000 time interval.

I hope that's useful. I created one a year or so ago, which haven't touched it since, so if something doesn't make sense, ask away.