- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Class ::xo::ChatClass
::xo::ChatClass create ...
Class Relations
::xotcl::Class create ::xo::ChatClass \ -superclass ::xotcl::ClassMethods (to be applied on the object)
Methods (to be applied on instances)
flush_messages (scripted)
set array "[self]-$chat_id" ::acs::clusterwide nsv_unset -nocomplain $array ::acs::clusterwide nsv_unset -nocomplain $array-seen ::acs::clusterwide nsv_unset -nocomplain $array-last-activityget_mode (scripted)
# 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 independent 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 commands ::thread::mutex] ne "" && ![catch {ns_conn contentsentlength}]} { # # scripted streaming should work everywhere # set mode scripted-streaming if {![regexp msie|opera [string tolower [ns_set iget [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 browser except them, we could use the # nice mode without the spinning load indicator. # set mode streaming } } return $modeinit (scripted)
# default setting is set19 from http://www.graphviz.org/doc/info/colors.html # per parameter settings in the chat package are available (param UserColors) set :colors [list #1b9e77 #d95f02 #7570b3 #e7298a #66a61e #e6ab02 #a6761d #666666]initialize_nsvs (scripted)
# empty stub for subclasses to extend
login (scripted, public)
<instance of xo::ChatClass> login -chat_id chat_id \ [ -skin skin ] [ -package_id package_id ] [ -mode mode ] \ [ -path path ] [ -avatar_p on|off ] [ -force_login_p on|off ] \ [ -login_messages_p on|off ] [ -logout_messages_p on|off ] \ [ -timewindow timewindow ]Logs into a chat
- Switches:
- -chat_id
(required)- -skin
(defaults to"classic"
) (optional)- -package_id
(optional)- -mode
(optional)- -path
(optional)- -avatar_p
(boolean) (defaults to"true"
) (optional)- -force_login_p
(boolean) (defaults to"false"
) (optional)- -login_messages_p
(boolean) (optional)- -logout_messages_p
(boolean) (optional)- -timewindow
(optional)- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
#:log "--chat" if {![ns_conn isconnected]} { return } if {$force_login_p} { auth::require_login } set session_id [ad_conn session_id].[clock seconds] set base_url [export_vars -base /shared/ajax/chat -no_empty { {id $chat_id} {s $session_id} {class "[self]"} }] # This might come in handy to get resources from the chat package # if we want to have e.g. a separate css. # set package_key [apm_package_key_from_id $package_id] # set resources_path /resources/${package_key} template::head::add_css -href /resources/xowiki/chat-skins/chat-$skin.css if {$mode eq ""} { # # The parameter "mode" was not specified, we try to guess the # "best" mode known to work for the currently used browser. # set mode [:get_mode] :log "--chat mode $mode" } switch -- $mode { polling { set jspath /resources/xowiki/chat.js set subscribe_url ${base_url}&m=get_new&mode=polling } streaming { set jspath /resources/xowiki/streaming-chat.js set subscribe_url ${base_url}&m=subscribe&mode=streaming } scripted-streaming { set jspath /resources/xowiki/scripted-streaming-chat.js set subscribe_url ${base_url}&m=subscribe&mode=scripted } default { error "mode $mode unknown, valid are: polling, streaming and scripted-streaming" } } # get LinkRegex parameter from the chat package set link_regex [::parameter::get_global_value -package_key "chat" -parameter "LinkRegex"] # Should we add a full screen link to the chat? set fs_link_p true # Should we display avatars? (JavaScript can only take 'true' or 'false' as boolean values) if {$avatar_p} { set show_avatar true } else { set show_avatar false } # small JavaScript library to obtain a portable ajax request object template::head::add_javascript -src urn:ad:js:get-http-object -order 10 template::head::add_javascript -script "const linkRegex = \"${link_regex}\";" -order 19 template::head::add_javascript -script "const show_avatar = $show_avatar;" -order 20 template::head::add_javascript -src /resources/xowiki/chat-common.js -order 21 template::head::add_javascript -src /resources/xowiki/chat-skins/chat-$skin.js -order 22 template::head::add_javascript -src $jspath -order 30 set send_url ${base_url}&m=add_msg&msg= #:log "--CHAT mode=$mode" template::add_body_script -script { document.getElementById('xowiki-chat-send').focus(); } set html "" if {[apm_package_installed_p chat]} { set message_label [_ chat.message] set send_label [_ chat.Send_Refresh] } else { set message_label "Message" set send_label "Send" } # TODO: it is currently not possible to embed multiple chats in # the same page. append html [subst { <div id='xowiki-chat'> <div id='xowiki-chat-messages-and-form'> <div id='xowiki-chat-messages'></div> <div id='xowiki-chat-messages-form-block'> <form id='xowiki-chat-messages-form' action='#'> <input type='text' placeholder="$message_label" name='msg' id='xowiki-chat-send' autocomplete="off" /> <button id='xowiki-chat-send-button' type='submit'>$send_label</button> </form> </div> </div> <div id='xowiki-chat-users'></div> </div> }] set conf [dict create] foreach var {force_login_p login_messages_p logout_messages_p timewindow} { if {[info exists $var]} { dict set conf $var [set $var] } } :create c1 -destroy_on_cleanup -chat_id $chat_id -session_id $session_id -mode $mode -conf $conf #:log "--CHAT created c1 with mode=$mode" append html [subst { <span id="xowiki-my-user-id" hidden>[c1 set user_id]</span> }] set js "" set data [c1 login] if {$data ne ""} { append js [subst -nocommands { let data = $data; for (var i = 0; i < data.length; i++) { renderData(data[i]); } }] } if {$fs_link_p} { append js {addFullScreenLink();} } append js {addSendPic();} #:log "--CHAT create HTML for mode=$mode" switch -- $mode { "polling" { append js [subst { chatSubscribe('$subscribe_url'); }] set send_msg_handler pollingSendMsgHandler } "streaming" { append js [subst { chatSubscribe('$subscribe_url'); }] set send_msg_handler streamingSendMsgHandler } "scripted-streaming" { append html [subst { <iframe name='ichat' id='ichat' src='[ns_quotehtml $subscribe_url]' style='width:0px; height:0px; border: 0px'> </iframe> }] set send_msg_handler scriptedStreamingSendMsgHandler } } append html [subst { <script nonce='[security::csp::nonce]'> $js </script> }] template::add_refresh_on_history_handler template::add_event_listener -id "xowiki-chat-messages-form" -event "submit" -script [subst {chatSendMsg('${send_url}', ${send_msg_handler});}] return $htmlsweep_all_chats (scripted)
#:log "-- starting" foreach nsv [nsv_names "[self]-*-seen"] { if { [regexp "[self]-(\[0-9\]+)-seen" $nsv _ chat_id] } { #:log "--Chat_id $chat_id" :new -volatile -chat_id $chat_id -user_id 0 -session_id 0 -init -sweeper } } #:log "-- ending"
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables