Class jabberwerx.ChatSession
Extends
jabberwerx.JWModel.
Represents a chat session with another user. There is only one ChatSession object per bare jid. The locked resource (if the session is currently locked) is specified by the jid property.
This class provides the following events:
Constructor Attributes | Constructor Name and Description |
---|---|
jabberwerx.ChatSession(client, jid, thread)
Creates a new ChatSession with the given client, jid, and optional thread |
Field Attributes | Field Name and Description |
---|---|
Used to bind to events and send messages
|
|
The Controller that created this ChatSession
|
|
The jid with which this chat session is communicating.
|
|
Our current chat state (XEP-0085) in this chat session.
|
|
Indicates if this session is for a private message.
|
|
The state of the correspondent in this session.
|
|
<static> |
jabberwerx.ChatSession.StateNotSupportedError
Thrown when a client tries to set this chat session's state to an
unsupported state.
|
Thread element for this chat session.
|
Method Attributes | Method Name and Description |
---|---|
destroy()
Method called to clean up object.
|
|
Retrieves the entity associated with this ChatSession. |
|
sendMessage(body)
Sends a message to the correspondent.
|
|
setChatState(state)
Set this clients chat state (XEP-0085).
|
- Methods borrowed from class jabberwerx.JWModel:
- applyEvent, event, shouldBeSavedWithGraph
- Methods borrowed from class jabberwerx.JWBase:
- getClassName, graphUnserialized, init, invocation, shouldBeSerializedInline, toString, wasUnserialized, willBeSerialized
Class Detail
jabberwerx.ChatSession(client, jid, thread)
Creates a new ChatSession with the given client, jid, and optional thread
- Parameters:
- {jabberwerx.Client} client
- The client object with which event observees are registered.
- {jabberwerx.JID|String} jid
- A JID object or JID string to use as a basis for a jid.
- {String} thread Optional
- The thread value to use for this conversation.
- Throws:
- {TypeError}
- if {client} is not valid
- {jabberwerx.JID.InvalidJIDError}
- if {jid} does not represent a valid JID
Field Detail
{jabberwerx.Client}
client
Used to bind to events and send messages
{jabberwerx.ChatController}
controller
The Controller that created this ChatSession
{jabberwerx.JID}
jid
The jid with which this chat session is communicating.
If the chat session has locked onto a resource, the resource
value can be found by using jabberwerx.JID#getResource.
{String}
localState
Our current chat state (XEP-0085) in this chat session. It can
be one of 'active', 'composing', 'paused', 'inactive' or 'gone'.
State is set to active automatically when #sendMessage
is called and set to gone automatically when #destroy is
called.
Note: Do not set this property directly; Use #setChatState instead.
{Boolean}
privateMessage
Indicates if this session is for a private message.
{String}
remoteState
The state of the correspondent in this session.
<static>
jabberwerx.ChatSession.StateNotSupportedError
Thrown when a client tries to set this chat session's state to an
unsupported state.
{String}
thread
Thread element for this chat session. Included in all outgoing
messages. Mirrors the value of the thread element been received
in messages from the correspondent (if present).
Method Detail
destroy()
Method called to clean up object. This method unbinds all
handlers for client events and sends 'gone' chat state.
{jabberwerx.Entity}
getEntity()
Retrieves the entity associated with this ChatSession.
- Returns:
- {jabberwerx.Entity} The entity for jabberwerx.ChatSession#jid
sendMessage(body)
Sends a message to the correspondent. Fires the
chatStateChanged, beforeChatSent and chatSent events.
- Parameters:
- {String} body
- The body of the message to send
{Boolean}
setChatState(state)
Set this clients chat state (XEP-0085). Can be one of 'active',
'composing', 'paused', 'inactive' or 'gone'. Sends out message
specifying the new chat state provided the ChatControllers
sendChatStates flag is set to true.
- Parameters:
- {String} state
- The state to set this client to.
- Throws:
- {jabberwerx.ChatSession.StateNotSupportedError}
- thrown if an unsupported state is specified as the argument.
- Returns:
- {Boolean} true if successfully changed, otherwise false