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
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
connect()
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
.
disconnect()
Specs
disconnect() :: :ok
Send the message to the component to perform the disconnection. This has effect
only if the status is different from disconnected
.
send(data)
Specs
send(binary() | Exampple.Xml.Xmlel.t() | Exampple.Router.Conn.t()) :: :ok
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.
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 tofalse
.set_from
: if we have to set the from for each stanza. Defaultfalse
.ping
: if we want to send a ping to the server we can specify the time in milliseconds to send anand 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 toExampple.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 inExampple.Tcp
andExampple.DummyTcpComponent
. Default toExampple.Tcp
.stanza_timeout
: the amount of time we wait until we kill the process and reply back an error. The error will be aremote-server-timeout
.
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
.
stop()
Specs
stop() :: :ok
Stop the process and therefore performs the disconnection from the XMPP server if any.
subscribe()
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.
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.