Hosts and Session module API

Hosts and Session utility API


Before version 3.11 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(<username or barejid>, [host]) - returns the bare session state for the supplied username either for the current module host or supplied host or the supplied bare jid, if currently online or nil
  • module:get_full_session(<username or fulljid>, [<resource>], [host]) - returns the full session state for the supplied username and resource for either the current module host or supplied host or the supplied full jid, if currently online or nil... in case you do supply the username, supplying the resource is mandatory
  • 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)