Class ::xo::MessageRelay

::xo::MessageRelay[i] create ...

Generic Message Relay class
Defined in packages/xotcl-core/tcl/message-relay-procs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::xo::MessageRelay \
     -superclass ::nx::Object

Methods (to be applied on instances)

  • can_be_used (scripted, public)

     <instance of xo::MessageRelay[i]> can_be_used

    Check, if a message relay can be used in the current configuration.

    Testcases:
    No testcase defined.
    return 1
  • encode_message (scripted, public)

     <instance of xo::MessageRelay[i]> encode_message mode msg

    Provide different "encoding" depending on the mode. Notice that for one chat, multiple clients might have difference modes, since the modes are determined at also by the capabilities of the client browser. So the incoming message has to be recoded multiple times.

    Parameters:
    mode (required)
    msg (required)

    Testcases:
    No testcase defined.
    set msg [encoding convertto utf-8 $msg]
    if {$mode eq "scripted"} {
      #::sec_handler_reset
      #ns_log notice "SEND data <$msg> encoded <$emsg>"
      set jsMsg [subst {
        <script nonce='[::security::csp::nonce]'>
            window.parent.postMessage($msg);
        </script>
      }]
      set msg [format %x [string length $jsMsg]]\r\n$jsMsg\r\n
    } else {
      set msg [string cat {data: } $msg \n\n]
    }
    #ns_log notice "#### [self] encode_message <$mode> returns <$msg>"
    return $msg
  • send_to_subscriber (scripted, public)

     <instance of xo::MessageRelay[i]> send_to_subscriber key msg

    Send a message to a service identified by the key (communication hub).

    Parameters:
    key (required)
    id for an existing communication hub
    msg (required)
    message to be sent

    Testcases:
    No testcase defined.
  • subscribe (scripted, public)

     <instance of xo::MessageRelay[i]> subscribe [ -initmsg initmsg ] \
        [ -mode mode ] key

    Subscribe to a service identified by a key.

    Switches:
    -initmsg (optional)
    optional message to be sent, when subscription happens
    -mode (optional, defaults to "default")
    optional mode
    Parameters:
    key (required)
    unique id for a (potentially new communication hub)

    Testcases:
    No testcase defined.
  • sweep (scripted, public)

     <instance of xo::MessageRelay[i]> sweep key

    Check existing subscriptions and clean stale ones.

    Parameters:
    key (required)
    key of the communication hub

    Testcases:
    No testcase defined.