Hosts and Session module API

Hosts and Session utility API in v3.11.x


Before this version performing operations on hosts and sessions required to directly reference the hosts, bare_sessions and full_sessions table in the global Metronome's state, this had the disadvantage to end in unelegant, often duplicated, if statements and to potentially cause tampering of the session states container tables by referencing 'em directly.

To resolve these issues a few new APIs have been introduced and some other modified:

  • module:get_host_type([host]) - returns the type (string) of the current module or the given host
  • module:get_bare_session(jid) - returns the bare session state for the supplied bare jid if currently online or nil
  • module:get_full_session(jid) - returns the full session state for the supplied full jid if currently online or nil
  • module:get_bare_sessions([host]) - returns an iterator with all bare session states for the current module or given host
  • module:get_full_sessions([host]) - returns an iterator with all full session states for the current module or given host
  • module:get_host_session([host]) - returns the current module or provided host session
  • module:get_host_sessions([host]) - returns the sessions table from host session (e.g. hosts["example.com"].sessions) or nil
  • module:host_is_component([host]) - returns true if the current module or provided host is a component or false
  • module:host_is_muc([host]) - returns true if the current module or provided host is a MUC or false
  • module:get_host_modules([host]) - returns the modules map from the current module host or the provided host (e.g. hosts["example.com"].modules)