Index: openacs-4/packages/xowiki/tcl/chat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/chat-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 8 Apr 2006 15:00:44 -0000 1.6 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 9 Apr 2006 00:07:10 -0000 1.7 @@ -6,7 +6,7 @@ @cvs-id $Id$ } namespace eval ::xowiki { - ::xo::ChatClass Chat -superclass ::xo::Chat + ::xo::ChatClass Chat -superclass ::xo::Chat Chat instproc render {} { my orderby time @@ -43,22 +43,35 @@ if {![info exists mode]} { set mode polling - set user_agent [string tolower [ns_set get [ns_conn headers] User-Agent]] - if {[regexp (firefox) $user_agent] && [info command ::thread::mutex] ne ""} { - set mode streaming + if {[info command ::thread::mutex] ne ""} { + # we seem to have libthread installed, we can use the background delivery thread + # scripted streaming should work everywhere + set mode scripted-streaming + if {[regexp (firefox) [string tolower [ns_set get [ns_conn headers] User-Agent]]]} { + # for firefox, we could use the nice mode without the spinning load indicator + set mode streaming + } } - my log "--mode $mode, user_agent=$user_agent" + my log "--mode $mode" } - - if {$mode eq "polling"} { - ::xowiki::Page requireJS "/resources/xowiki/get-http-object.js" - set jspath packages/xowiki/www/ajax/chat.js - set login_url ${path}ajax/chat?m=login&$context - set get_update "chatSendCmd(\"$path/ajax/chat?m=get_new&$context\",chatReceiver)" - set get_all "chatSendCmd(\"$path/ajax/chat?m=get_all&$context\",chatReceiver)" - } else { - set jspath packages/xowiki/www/ajax/streaming-chat.js - set subscribe_url ${path}ajax/chat?m=subscribe&$context + + switch $mode { + polling { + ::xowiki::Page requireJS "/resources/xowiki/get-http-object.js" + set jspath packages/xowiki/www/ajax/chat.js + set login_url ${path}ajax/chat?m=login&$context + set get_update "chatSendCmd(\"$path/ajax/chat?m=get_new&$context\",chatReceiver)" + set get_all "chatSendCmd(\"$path/ajax/chat?m=get_all&$context\",chatReceiver)" + } + streaming { + set jspath packages/xowiki/www/ajax/streaming-chat.js + set subscribe_url ${path}ajax/chat?m=subscribe&$context + } + scripted-streaming { + append context &mode=scripted + set jspath packages/xowiki/www/ajax/scripted-streaming-chat.js + set subscribe_url ${path}ajax/chat?m=subscribe&$context + } } set send_url ${path}ajax/chat?m=add_msg&$context&msg= @@ -67,22 +80,20 @@ } set file [open [acs_root_dir]/$jspath]; set js [read $file]; close $file - if {$mode eq "polling"} { - return "\ + switch $mode { + polling {return "\
-
- " - } else { - return "\ + " + } + streaming {return "\ +
+ +
+ +
" + } } } } Index: openacs-4/packages/xowiki/www/ajax/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/chat.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/xowiki/www/ajax/chat.tcl 8 Apr 2006 00:11:55 -0000 1.3 +++ openacs-4/packages/xowiki/www/ajax/chat.tcl 9 Apr 2006 00:07:10 -0000 1.4 @@ -9,10 +9,11 @@ id s msg:optional + {mode ""} } -#ns_log notice "--c m=$m session_id = $s [clock format [lindex [split $s .] 1] -format %H:%M:%S]" -::xowiki::Chat c1 -volatile -chat_id $id -session_id $s +#ns_log notice "--c m=$m session_id=$s [clock format [lindex [split $s .] 1] -format %H:%M:%S] mode=$mode" +::xowiki::Chat c1 -volatile -chat_id $id -session_id $s -mode $mode switch -- $m { add_msg { #ns_log notice "--c call c1 $m '$msg'" Index: openacs-4/packages/xowiki/www/ajax/scripted-streaming-chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/scripted-streaming-chat.js,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/ajax/scripted-streaming-chat.js 9 Apr 2006 00:07:10 -0000 1.1 @@ -0,0 +1,73 @@ +// simple javascript support for streaming ajax based chat interface +// $Id: scripted-streaming-chat.js,v 1.1 2006/04/09 00:07:10 gustafn Exp $ +// -gustaf neumann April 2006 + +function getHttpObject() { + var http_request = false; + if (window.XMLHttpRequest) { // Mozilla, Safari,... + http_request = new XMLHttpRequest(); + } else if (window.ActiveXObject) { // IE + try { + http_request = new ActiveXObject('Msxml2.XMLHTTP'); + } catch (e) { + try { + http_request = new ActiveXObject('Microsoft.XMLHTTP'); + } catch (e) {} + } + } + + if (!http_request) { + alert('Cannot create and instance of XMLHTTP'); + } + return http_request; +} + +function getData(data) { + var messages = document.getElementById('messages'); + for (var i=0;i