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.15 -r1.16 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 13 Sep 2012 16:05:26 -0000 1.15 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 17 Feb 2013 11:48:06 -0000 1.16 @@ -34,37 +34,70 @@ Chat proc initialize_nsvs {} {;} ;# noop Chat proc login {-chat_id -package_id -mode} { - my log "--" + #my log "--chat" auth::require_login if {![info exists package_id]} {set package_id [ad_conn package_id] } if {![info exists chat_id]} {set chat_id $package_id } set context id=$chat_id&s=[ad_conn session_id].[clock seconds] set path [lindex [site_node::get_url_from_object_id -object_id $package_id] 0] if {![info exists mode]} { + # + # The parameter "mode" was not specified, we try to guess the + # "best" mode known to work for the currently used browser. + # + # The most conservative mode is + # - "polling" (which requires for every connected client polling + # requests), followed by + # - "scripted-streaming" (which opens and "infinitely long" HTML + # files with embedded script tags; very portable, but this + # causes the loading indicator to spin), followed by + # - "streaming" (true streaming, but this requires + # an HTTP stack supporting partial reads). + # + # NOTICE 1: The guessing is based on current versions of the + # browsers. Older versions of the browser might behave + # differently. + # + # NOTICE 2: "streaming" (and to a lesser extend + # "scripted-streaming" - which used chunked encoding) might be + # influenced by the buffering behavior of a reverse proxy, which + # might have to be configured appropriately. + # + # To be independet of the guessing mode, instantiate the chat + # object with "mode" specified. + # set mode polling + # + # Check, whether we have the tcllibthread and a sufficiently new + # aolserver/naviserver supporting bgdelivery transfers. + # if {[info command ::thread::mutex] ne "" && ![catch {ns_conn contentsentlength}]} { - # we seem to have libthread installed, and the patch for obtaining the tcl-stream - # from a connection thread, so 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 - # currently, streaming mode seems broken with current firefox... - #set mode streaming - } + if {![regexp msie|opera [string tolower [ns_set get [ns_conn headers] User-Agent]]]} { + # Explorer doesn't expose partial response until request state != 4, while Opera fires + # onreadystateevent only once. For this reason, for every broser except them, we could + # use the nice mode without the spinning load indicator. + # + set mode streaming + } } my log "--chat mode $mode" } + # small javascript library to obtain a portable ajax request object + ::xo::Page requireJS "/resources/xowiki/get-http-object.js" + switch $mode { polling { - ::xo::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)" + 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 @@ -117,7 +150,8 @@ overflow:auto; '>
- " + +
" }