Client
Object
SAMP.SAMPClientId
— TypeSAMPClientId
A simple structure to save the client ID of a SAMP client.
This structure contains a single string field, client_id
. It is defined only to avoid type piracy and to resolve some parameter ambiguities in the code.
SAMP.SAMPClient
— TypeSAMPClient{H <:
SAMP.AbstractSAMPHub
}
A structure representing a SAMP client.
The same structure is used for clients of a SAMPHub
or of SAMPWebHub
.
Members
hub
: the hub servername
: the name of the client (compulsory)key
: a string representing the secret key used by the client to contact the serverhub_id
: the id the hub has assigned to himself, as aSAMPClientId
client_id
: the id the hud has assigned to the client, as aSAMPClientId
translator
: the URL translator (only present if the server is aSAMPWebHub
)hub_query_by_meta
: a string that, if non-void, indicates the mtype accepted by the hub to perform queries by meta (can be "x-samp.query.by-meta" or "samp.query.by-meta")
Contructors
SAMPClient([hub,] name)
register([hub,] name [; metadata])
The first form simply create and register the client. The second form, register
, also accepts metadata as keywords, which will be sent to the server (see setMetadata).
SAMP.register
— FunctionSAMPClient{H <:
SAMP.AbstractSAMPHub
}
A structure representing a SAMP client.
The same structure is used for clients of a SAMPHub
or of SAMPWebHub
.
Members
hub
: the hub servername
: the name of the client (compulsory)key
: a string representing the secret key used by the client to contact the serverhub_id
: the id the hub has assigned to himself, as aSAMPClientId
client_id
: the id the hud has assigned to the client, as aSAMPClientId
translator
: the URL translator (only present if the server is aSAMPWebHub
)hub_query_by_meta
: a string that, if non-void, indicates the mtype accepted by the hub to perform queries by meta (can be "x-samp.query.by-meta" or "samp.query.by-meta")
Contructors
SAMPClient([hub,] name)
register([hub,] name [; metadata])
The first form simply create and register the client. The second form, register
, also accepts metadata as keywords, which will be sent to the server (see setMetadata).
SAMP.defaultClient
— ConstantdefaultClient::Union{SAMPClient,Nothing}
The default client.
Can be obtained (and set, if it is nothing
) using getClient
.
SAMP.getClient
— FunctiongetClient()
Return the default client.
This function also sets it the first time it is called.
Methods
All methods can use the default client SAMP.defaultClient
, which is automatically registered using the `SAMP.getClient method. This can be handy if one just need to perform queries and not receive messages.
Each registered client (including the default one) should be unregistered by a call to `SAMP.unregister when not needed anymore. This is done automatically by the code at the exit of Julia.
SAMP.unregister
— Functionunregister([client])
Unregister client
from the associated hub.
SAMP.setMetadata
— FunctionsetMetadata([client]; metadata)
declareMetadata([client]; metadata)
Set the metadata associated with the client.
The metadata are passed as keyword arguments; metadata consisting of non-valid Julia keywords can be passed with the var"long.name"
syntax. For example
setMetadata(client; var"samp.description.text"="A fast FITS image displayer")
Standard metadata can be entered using a shorter syntax. In particular, the following aliases are recognized
name => samp.name
description => samp.description.text
icon => samp.icon.url
documentation => samp.documentation.url
Note that, by design, if no icon is provided this function uses a standard icon; if no icon is desired, enter icon=""
as keyword parameter.
If this function is called multiple times, the latest metadata are kept (all the others are discarded). Both functions are identical: declareMetadata
is just an alias for setMetadata
, kept to honour the original SAMP command.
SAMP.declareMetadata
— FunctionsetMetadata([client]; metadata)
declareMetadata([client]; metadata)
Set the metadata associated with the client.
The metadata are passed as keyword arguments; metadata consisting of non-valid Julia keywords can be passed with the var"long.name"
syntax. For example
setMetadata(client; var"samp.description.text"="A fast FITS image displayer")
Standard metadata can be entered using a shorter syntax. In particular, the following aliases are recognized
name => samp.name
description => samp.description.text
icon => samp.icon.url
documentation => samp.documentation.url
Note that, by design, if no icon is provided this function uses a standard icon; if no icon is desired, enter icon=""
as keyword parameter.
If this function is called multiple times, the latest metadata are kept (all the others are discarded). Both functions are identical: declareMetadata
is just an alias for setMetadata
, kept to honour the original SAMP command.
SAMP.getMetadata
— FunctiongetMetadata([client,] dest=client.client_id)
getMetadata(dest)
Return the metadata set for the client dest
.
SAMP.getSubscriptions
— FunctiongetSubscriptions([client,] dest)
Return the subscriptions for the client dest
.
SAMP.getRegisteredClients
— FunctiongetRegisteredClients([client])
Return a list of all clients registered with the hub of client
.
SAMP.getSubscribedClients
— FunctiongetSubscribedClients([client,] mtype)
Return a list of all clients that subscribed to the given mtype
.
Base.notify
— Methodnotify(client, dest, mtype [; args...])
Notify the message mtype
with the optional arguments args
to dest
.
dest
must be the ID of the destination client: this can be obtained from getSubscribedClients
or getRegisteredClients
.
The optional message arguments can be passed as keywords: as with setMetadata
, arguments with non-valid Julia names can be entered as var"long.name"=value
.
The alias communicate
is used to avoid type piracy.
SAMP.notifyAll
— FunctionSAMP.callAndWait
— FunctioncallAndWait([client,] dest, mtype; timeout=0 [, args...])
Send the message mtype
to dest
and wait for the reply.
Arguments to the message can be added as keywords, similarly to notify
.
The timeout
keyword controls the timeout in seconds: if set to 0 or to a negative number, there is no timeout (this is the default). Note that in this case the client can wait indefinitely.
SAMP.findFirstClient
— FunctionfindFirstClient([client,] name; key="samp.name")
Return the first client with the metadata key = name
Returns nothing
if no client is found.
name
can be a simple string (and then it must match exactly key
), or a regular expression.
Equivalent to first(findFirstClient(client, name))
, but with less allocations.
SAMP.findAllClients
— FunctionfindAllClients([client,] name; key="samp.name")
Return all clients with the metadata key = name
name
can be a simple string (and then it must match exactly key
), or a regular expression.