JSJaC

## Class JSJaCConnection

    Object
       |
       +--JSJaCConnection

Direct Known Subclasses:
  JSJaCHttpBindingConnection, JSJaCHttpPollingConnection

class JSJaCConnection

Somewhat abstract base class for jabber connections. Contains all of the code in common for all jabber connections
Defined in JSJaCConnection.js

Field Summary
`Debugger` | `oDbg` Reference to debugger interface (needs to implement method `log`)

Constructor Summary
`JSJaCConnection(<JSON> oArg)` Creates a new Jabber connection (a connection to a jabber server)

Method Summary
`void` | `connect(oArg)`
`boolean` | `connected()` Tells whether this connection is connected
`void` | `disconnect()` Disconnects from jabber server and terminates session (if applicable)
`int` | `getPollInterval()` Gets current value of polling interval
`void` | `registerHandler(<String> event)` Registers an event handler (callback) for this connection.
`void` | `registerIQGet(<String> childName, <String> childNS, <Function> handler)` Register for iq packets of type 'get'.
`void` | `registerIQSet(<String> childName, <String> childNS, <Function> handler)` Register for iq packets of type 'set'.
`boolean` | `resume()` Resumes this connection from saved state (cookie)
`boolean` | `resumeFromData(data)` Resumes BOSH connection from data
`boolean` | `send(<JSJaCPacket> packet,<Function> cb,<Object> arg)` Sends a JSJaCPacket
`boolean` | `sendIQ(<JSJaCIQPacket> iq, <Object> handlers, <Object> arg)` Sends an IQ packet.
`int` | `setPollInterval(timerval)` Sets polling interval for this connection
`String` | `status()` Returns current status of this connection
`boolean` | `suspend()` Suspends this connection (saving state for later resume) Saves state to cookie
`Object` | `suspendToData()` Suspend connection and return serialized JSJaC connection state
`void` | `unregisterHandler(event,handler)`

Field Detail

### oDbg

    Debugger oDbg

Reference to debugger interface (needs to implement method `log`)

Constructor Detail

### JSJaCConnection

    JSJaCConnection(<JSON> oArg)

Creates a new Jabber connection (a connection to a jabber server)

Parameters:

`oArg` - JSON with properties:
* `httpbase` the http base address of the service to be used for connecting to jabber
* `oDbg` (optional) a reference to a debugger interface

Method Detail

### connect

    void connect(oArg)

### connected

    boolean connected()

Tells whether this connection is connected

Returns:

`true` if this connections is connected, `false` otherwise

### disconnect

    void disconnect()

Disconnects from jabber server and terminates session (if applicable)

### getPollInterval

    int getPollInterval()

Gets current value of polling interval

Returns:

Polling interval in milliseconds

### registerHandler

    void registerHandler(<String> event)

Registers an event handler (callback) for this connection.

Note: All of the packet handlers for specific packets (like message_in, presence_in and iq_in) fire only if there's no callback associated with the id.

Example:
`con.registerHandler('iq', 'query', 'jabber:iq:version', handleIqVersion);`

Parameters:

`event` - One of

- onConnect - connection has been established and authenticated
- onDisconnect - connection has been disconnected
- onResume - connection has been resumed
- onStatusChanged - connection status has changed, current status as being passed argument to handler. See status().
- onError - an error has occured, error node is supplied as argument, like this:
  `<error code='404' type='cancel'>
  <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>`
- packet_in - a packet has been received (argument: the packet)
- packet_out - a packet is to be sent(argument: the packet)
- message_in | message - a message has been received (argument: the packet)
- message_out - a message packet is to be sent (argument: the packet)
- presence_in | presence - a presence has been received (argument: the packet)
- presence_out - a presence packet is to be sent (argument: the packet)
- iq_in | iq - an iq has been received (argument: the packet)
- iq_out - an iq is to be sent (argument: the packet)

`childName` - A childnode's name that must occur within a retrieved packet [optional]

`childNS` - A childnode's namespace that must occure within a retrieved packet (works only if childName is given) [optional]

`type` - The type of the packet to handle (works only if childName and chidNS are given (both may be set to '*' in order to get skipped) [optional]

`handler` - The handler to be called when event occurs. If your handler returns 'true' it cancels bubbling of the event. No other registered handlers for this event will be fired.

### registerIQGet

    void registerIQGet(<String> childName, <String> childNS, <Function> handler)

Register for iq packets of type 'get'.

Parameters:

`childName` - A childnode's name that must occur within a retrieved packet

`childNS` - A childnode's namespace that must occure within a retrieved packet (works only if childName is given)

`handler` - The handler to be called when event occurs. If your handler returns 'true' it cancels bubbling of the event. No other registered handlers for this event will be fired.

### registerIQSet

    void registerIQSet(<String> childName, <String> childNS, <Function> handler)

Register for iq packets of type 'set'.

Parameters:

`childName` - A childnode's name that must occur within a retrieved packet

`childNS` - A childnode's namespace that must occure within a retrieved packet (works only if childName is given)

`handler` - The handler to be called when event occurs. If your handler returns 'true' it cancels bubbling of the event. No other registered handlers for this event will be fired.

### resume

    boolean resume()

Resumes this connection from saved state (cookie)

Returns:

Whether resume was successful

### resumeFromData

    boolean resumeFromData(data)

Resumes BOSH connection from data

Parameters:

`serialized` - jsjac state information

Returns:

Whether resume was successful

### send

    boolean send(<JSJaCPacket> packet,<Function> cb,<Object> arg)

Sends a JSJaCPacket

Parameters:

`packet` - The packet to send

`cb` - The callback to be called if there's a reply to this packet (identified by id) [optional]

`arg` - Arguments passed to the callback (additionally to the packet received) [optional]

Returns:

'true' if sending was successfull, 'false' otherwise

### sendIQ

    boolean sendIQ(<JSJaCIQPacket> iq, <Object> handlers, <Object> arg)

Sends an IQ packet. Has default handlers for each reply type. Those maybe overriden by passing an appropriate handler.

Parameters:

`iq` - - the iq packet to send

`handlers` - - object with properties 'error_handler', 'result_handler' and 'default_handler' with appropriate functions

`arg` - - argument to handlers

Returns:

'true' if sending was successfull, 'false' otherwise

### setPollInterval

    int setPollInterval(timerval)

Sets polling interval for this connection

Parameters:

`millisecs` - Milliseconds to set timer to

Returns:

effective interval this connection has been set to

### status

    String status()

Returns current status of this connection

Returns:

String to denote current state. One of

- 'initializing' ... well
- 'connecting' if connect() was called
- 'resuming' if resume() was called
- 'processing' if it's about to operate as normal
- 'onerror_fallback' if there was an error with the request object
- 'protoerror_fallback' if there was an error at the http binding protocol flow (most likely that's where you interested in)
- 'internal_server_error' in case of an internal server error
- 'suspending' if suspend() is being called
- 'aborted' if abort() was called
- 'disconnecting' if disconnect() has been called

### suspend

    boolean suspend()

Suspends this connection (saving state for later resume) Saves state to cookie

Returns:

Whether suspend (saving to cookie) was successful

### suspendToData

    Object suspendToData()

Suspend connection and return serialized JSJaC connection state

Returns:

JSJaC connection state object

### unregisterHandler

    void unregisterHandler(event,handler)

JSJaC

Documentation generated by JSDoc on Tue Jan 5 02:48:26 2021