Exampple.Component (exampple v0.10.6)

Component is letting us to connect to a XMPP server as a XMPP Component. This module aims create a connection as a process letting us handle the connection easily. By default, using the configuration it's starting using the module name as registerd name for the process.

This module is designed to be in use in combination with Exampple.Router and the custom implementation of controllers which are using this module and implementing the functions which were defined in the implementation of the router.

Check the general documentation about the architecture and how to use it for further information.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Send the message to the component to perform the connection. This has effect only if the status of the server is disconnected.

Send the message to the component to perform the disconnection. This has effect only if the status is different from disconnected.

Send data using the socket to the XMPP server. You can send whatever binary data or a %Xmlel{} struct which will be converted first to string to be sent. It also works with %Conn{} but only if you stored the response inside of it. See Exampple.Stanza for further information.

Starts a process using the module name (Exampple.Component) as the registered name. The arguments we can provide are the following

Starts a process providing it a name. This function let you to create as many connections as component as needed. Check start_link/1 for further information about args.

Stop the process and therefore performs the disconnection from the XMPP server if any.

Performs a subscription to the XMPP component. This means the component is going to notify when it's ready. This could be used for testing and for synchronization at start. Only one process could be subscribed at the same time.

Wait until the system is ready to start processing messages. This is in use for functional tests and could be used as a phase in the start of the applications.

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Specs

connect() :: :ok

Send the message to the component to perform the connection. This has effect only if the status of the server is disconnected.

Specs

disconnect() :: :ok

Send the message to the component to perform the disconnection. This has effect only if the status is different from disconnected.

Link to this macro

not_ready(state)

(macro)

Specs

Send data using the socket to the XMPP server. You can send whatever binary data or a %Xmlel{} struct which will be converted first to string to be sent. It also works with %Conn{} but only if you stored the response inside of it. See Exampple.Stanza for further information.

Link to this function

start_link(args)

Starts a process using the module name (Exampple.Component) as the registered name. The arguments we can provide are the following:

  • otp_app: the name of the application. If you specify this only one parameter the rest of the configuration will be retrieved from the application configuration. This should be a keyword list.

If we provide a map instead we can specify the following args:

  • otp_app: in this level it's only needed to be sent to the router.
  • host: the name of the host where the XMPP server is.
  • port: the port where the XMPP server is listening for the components.
  • domain: the XMPP domain. Note that it is not necessary the same as the host.
  • trimmed: if the XML packet will be trimmed (removing all of the empty nodes). default to false.
  • set_from: if we have to set the from for each stanza. Default false.
  • ping: if we want to send a ping to the server we can specify the time in milliseconds to send an and ensure the connection is not closed because of idle. Default is false.
  • router_handler: the module which is going to handle the routing. This is only for testing purposes. Default to Exampple.Router.
  • tcp_handler: the module which is going to handle the connection for the component. This could be useful for TLS handling or testing purposes. You can see further information in Exampple.Tcp and Exampple.DummyTcpComponent. Default to Exampple.Tcp.
  • stanza_timeout: the amount of time we wait until we kill the process and reply back an error. The error will be a remote-server-timeout.
Link to this function

start_link(name, args)

Starts a process providing it a name. This function let you to create as many connections as component as needed. Check start_link/1 for further information about args.

Specs

stop() :: :ok

Stop the process and therefore performs the disconnection from the XMPP server if any.

Specs

subscribe() :: :ok

Performs a subscription to the XMPP component. This means the component is going to notify when it's ready. This could be used for testing and for synchronization at start. Only one process could be subscribed at the same time.

Link to this function

wait_for_ready()

Specs

wait_for_ready() :: :ok

Wait until the system is ready to start processing messages. This is in use for functional tests and could be used as a phase in the start of the applications.