- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Message relay based on ns_connchan
Class Relations
::xo::MessageRelay create ::xo::mr::connchan
Methods (to be applied on the object)
can_be_used (scripted, public)
xo::mr::connchan
can_be_used
ns_connchan can be used on every recent NaviServer.
- Testcases:
- No testcase defined.
# # ns_connchan can be used on every recent NaviServer. # return [expr {[info commands ::ns_connchan] ne ""}]
send_to_subscriber (scripted, public)
xo::mr::connchan
send_to_subscriber key msg
Write directly to the subscribers from the connection thread via ns_connchan. It would be possible, to perform asynchronous operations via "ns_connchan callback", which would be handled in the background. Not sure, this is necessary.
- Parameters:
- key (required)
- msg (required)
- Testcases:
- No testcase defined.
# # Write directly to the subscribers from the connection thread # via ns_connchan. It would be possible, to perform asynchronous # operations via "ns_connchan callback", which would be handled # in the background. Not sure, this is necessary. # #ns_log notice "#### [self] send_to_subscriber <[nsv_array names mr_connchan_$key]>" foreach handle [nsv_array names mr_connchan_$key] { try { set mode [nsv_get mr_connchan_$key $handle] ns_connchan write $handle [:encode_message $mode $msg] } on error {errorMsg} { ns_log warning "message relay: duplicate registration for <$key> attempted" :cleanup $key $handle } }
subscribe (scripted, public)
xo::mr::connchan
subscribe [ -initmsg initmsg ] [ -mode mode ] key
ns_log notice "#### [self] subscribe $key mode $mode" Unplug the connection channel from the current connection thread. The currently unplugged channels can be queried via "ns_connchan list"
- Switches:
- -initmsg (optional)
- -mode (optional)
- Parameters:
- key (required)
- Testcases:
- No testcase defined.
#ns_log notice "#### [self] subscribe $key mode $mode" # # Unplug the connection channel from the current connection # thread. The currently unplugged channels can be queried via # "ns_connchan list" # set handle [ns_connchan detach] # # should check and append # if {![nsv_exists mr_connchan_$key $handle]} { nsv_set mr_connchan_$key $handle $mode try { ns_connchan write $handle [:start_of_page $mode] } on error {errorMsg} { ns_log warning "message relay: write on <$key> failed: $errorMsg" :cleanup $key $handle } } else { ns_log warning "message relay: duplicate registration for <$key> attempted" } #::bgdelivery do ::Subscriber new # -channel $ch -key $key # -user_id [ad_conn user_id] -mode $mode
sweep (scripted, public)
xo::mr::connchan
sweep key
For the time being, do nothing. Since the chat is verbose on logins/logouts, write operations will fail, in which case the array is cleaned up. If this is not sufficient, probably a "ns_connchan eof" operation would be useful.
- Parameters:
- key (required)
- Testcases:
- No testcase defined.
# # For the time being, do nothing. Since the chat is verbose on # logins/logouts, write operations will fail, in which case the # array is cleaned up. If this is not sufficient, probably a # "ns_connchan eof" operation would be useful. #
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables