::xo::ChatClass
::xowiki::Chat
Class Hierarchy of ::xowiki::Chat
- ::xotcl::Object
- Meta-class:
- ::xotcl::Class
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- Methods for instances:
- __api_make_doc, __api_make_forward_doc, __timediff, abstract, ad_doc, ad_forward, ad_proc, appendC, arrayC, asHTML, autonameC, check, classC, cleanupC, configureC, containsC, copyC, db_0or1rowC, db_1rowC, debug, defaultmethodC, destroyC, destroy_on_cleanup, ds, evalC, existsC, extractConfigureArg, filterC, filterguardC, filtersearch, forward, hasclass, incrC, infoC, init, instvarC, invarC, isclass, ismetaclass, ismixin, isobject, istype, lappendC, log, method, mixinC, mixinguardC, moveC, msg, noinitC, objectparameter, parametercmdC, proc, procsearch, qn, requireNamespaceC, residualargsC, self, serialize, setC, set_instance_vars_defaults, show-object, substC, traceC, unknown, unsetC, uplevelC, upvarC, volatileC, vwait
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- getExitHandler, setExitHandler, unsetExitHandler
- ::xo::OrderedComposite
- Meta-class:
- ::xotcl::Class
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- Methods for instances:
- __compare, add, children, contains, delete, destroy, last_child, orderby, show
- Methods to be applied on the class:
- Methods provided by the meta-class
- ::xo::Chat
- Meta-class:
- ::xotcl::Class
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- Parameter for instances:
- chat_id, encoder (default "urlencode"), mode (default "default"), session_id, sweepinterval (default "600"), timewindow (default "600"), user_id
- Methods for instances:
- active_user_list, add_msg, broadcast_msg, check_age, current_message_valid, encode, get_all, get_new, get_users, init, init_user_color, js_encode_msg, json_encode, json_encode_msg, last_activity, login, logout, noencode, nr_active_users, register_nsvs, render, subscribe, sweeper, urlencode, user_active, user_color, user_link, user_name
- Methods to be applied on the class:
- Methods provided by the meta-class
- ::xowiki::Chat
- Meta-class:
- ::xo::ChatClass
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- initialize_nsvs, login
Class Relations
- superclass: ::xo::Chat
![[i]](/resources/acs-subsite/ZoomIn16.gif)
::xo::ChatClass create ::xowiki::Chat \
-superclass ::xo::Chat
Methods
proc initialize_nsvs
::266861 proc initialize_nsvs {} {;}
proc login
::266861 proc login {-chat_id -package_id {-mode ""} {-path ""}} {
#my log "--chat"
if {![ns_conn isconnected]} return
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 session_id [ad_conn session_id].[clock seconds]
set context id=$chat_id&s=$session_id
#my log "chat_id=$chat_id, path=$path"
if {$path eq ""} {
set path [lindex [site_node::get_url_from_object_id -object_id $package_id] 0]
} elseif {[string range $path end end] ne "/"} {
append path /
}
if {$mode eq ""} {
#
# 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}]} {
#
# scripted streaming should work everywhere
#
set mode scripted-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 {
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
}
default {
error "mode $mode unknown, valid are: polling, streaming and scripted-streaming"
}
}
set send_url ${path}ajax/chat?m=add_msg&$context&msg=
if { ![file exists [acs_root_dir]/$jspath] } {
return -code error "File [acs_root_dir]/$jspath does not exist"
}
set file [open [acs_root_dir]/$jspath]; set js [read $file]; close $file
my log "--CHAT mode=$mode"
set style {
margin:1.5em 0 1.5em 0;
padding:1em 0 1em 1em;
background-color: #f9f9f9;
border:1px solid #dedede;
height:150px;
font-size:.95em;
line-height:.7em;
color:#333;
overflow:auto;
}
switch $mode {
polling {return " <script type='text/javascript' language='javascript'>
$js
setInterval('$get_update',5000)
</script>
<form action='#' onsubmit='chatSendMsg(\"$send_url\",chatReceiver); return false;'>
<iframe name='ichat' id='ichat' frameborder='0' src='$login_url'
style='width:90%;' height='150'>
</iframe>
<input type='text' size='40' name='msg' id='chatMsg'>
</form>"
}
streaming {
::xowiki::Chat create c1 -destroy_on_cleanup -chat_id $chat_id -session_id $session_id -mode $mode
set r [ns_urldecode [c1 get_all]]
regsub -all {<[/]?div[^>]*>} $r "" r
return " <script type='text/javascript' language='javascript'>$js
var send_url = \"$send_url\";
chatSubscribe(\"$subscribe_url\");
</script>
<div id='messages' style='$style'>$r</div>
<form action='#' onsubmit='chatSendMsg(); return false;'>
<input type='text' size='40' name='msg' id='chatMsg'>
</form>"
}
scripted-streaming {
::xowiki::Chat create c1 -destroy_on_cleanup -chat_id $chat_id -session_id $session_id -mode $mode
set r [ns_urldecode [c1 get_all]]
regsub -all {<[/]?div[^>]*>} $r "" r
return " <script type='text/javascript' language='javascript'>
$js
var send_url = \"$send_url\";
</script>
<div id='messages' style='$style'></style>
<iframe name='ichat' id='ichat' frameborder='0' src='$subscribe_url'
style='width:0px; height:0px; border: 0px'>
</iframe>
<form action='#' onsubmit='chatSendMsg(); return false;'>
<input type='text' size='40' name='msg' id='chatMsg'>
</form>"
}
}
}