core.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.

Summary
core.js
Candy.CoreCandy Chat Core
Variables
autojoinIf set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
Functions
initInitialize Core.
connectConnect to the jabber host.
attachAttach an already binded & connected session to the server
disconnectLeave all rooms and disconnect
addHandlerWrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
getUserGets current user
setUserSet current user.
getConnectionGets Strophe connection
getRoomsGets all joined rooms
isAnonymousConnectionReturns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
getOptionsGets options
getRoomGets a specific room
onWindowUnloadwindow.onbeforeunload event which disconnects the client from the Jabber server.
rawInput(Overridden from Strophe.Connection.rawInput)
logOverridden to do something useful if debug is set to true.

Candy.Core

Candy Chat Core

Parameters

(Candy.Core) selfitself
(Strophe) StropheStrophe JS
(jQuery) $jQuery
Summary
Variables
autojoinIf set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
Functions
initInitialize Core.
connectConnect to the jabber host.
attachAttach an already binded & connected session to the server
disconnectLeave all rooms and disconnect
addHandlerWrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
getUserGets current user
setUserSet current user.
getConnectionGets Strophe connection
getRoomsGets all joined rooms
isAnonymousConnectionReturns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
getOptionsGets options
getRoomGets a specific room
onWindowUnloadwindow.onbeforeunload event which disconnects the client from the Jabber server.
rawInput(Overridden from Strophe.Connection.rawInput)
logOverridden to do something useful if debug is set to true.

Variables

autojoin

autojoin: true

If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).  You may want to define an array of rooms to autojoin: `[‘ro.nosp@m.om1@conferenc.nosp@m.e.host.tld’, ‘room2...]` (ejabberd, Openfire, ...)

Functions

init

self.init = function(service,
options)

Initialize Core.

Parameters

(String) serviceURL of BOSH service
(Object) optionsOptions for candy

connect

self.connect = function(jidOrHost,
password,
nick)

Connect to the jabber host.

There are four different procedures to login

connect(‘JID’, ‘password’)Connect a registered user
connect(‘domain’)Connect anonymously to the domain.  The user should receive a random JID.
connect(‘domain’, null, ‘nick’)Connect anonymously to the domain.  The user should receive a random JID but with a nick set.
connect(‘JID’)Show login form and prompt for password.  JID input is hidden.
connect()Show login form and prompt for JID and password.

See

Candy.Core.attach() for attaching an already established session.

Parameters

(String) jidOrHostJID or Host
(String) passwordPassword of the user
(String) nickNick of the user.  Set one if you want to anonymously connect but preset a nick.  If jidOrHost is a domain and this param is not set, Candy will prompt for a nick.

attach

self.attach = function(jid,
sid,
rid)

Attach an already binded & connected session to the server

See Strophe.Connection.attach

Parameters

(String) jidJabber ID
(Integer) sidSession ID
(Integer) ridrid

disconnect

self.disconnect = function()

Leave all rooms and disconnect

addHandler

self.addHandler = function(handler,
ns,
name,
type,
id,
from,
options)

Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.

Parameters

(Function) handlerThe user callback.
(String) nsThe namespace to match.
(String) nameThe stanza name to match.
(String) typeThe stanza type attribute to match.
(String) idThe stanza id attribute to match.
(String) fromThe stanza from attribute to match.
(String) optionsThe handler options

Returns

A reference to the handler that can be used to remove it.

getUser

self.getUser = function()

Gets current user

Returns

Instance of Candy.Core.ChatUser

setUser

self.setUser = function(user)

Set current user.  Needed when anonymous login is used, as jid gets retrieved later.

Parameters

(Candy.Core.ChatUser) userUser instance

getConnection

self.getConnection = function()

Gets Strophe connection

Returns

Instance of Strophe.Connection

getRooms

self.getRooms = function()

Gets all joined rooms

Returns

Object containing instances of Candy.Core.ChatRoom

isAnonymousConnection

self.isAnonymousConnection = function()

Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.

Returns

(Boolean)

getOptions

self.getOptions = function()

Gets options

Returns

Object

getRoom

self.getRoom = function(roomJid)

Gets a specific room

Parameters

(String) roomJidJID of the room

Returns

If the room is joined, instance of Candy.Core.ChatRoom, otherwise null.

onWindowUnload

self.onWindowUnload = function()

window.onbeforeunload event which disconnects the client from the Jabber server.

rawInput

self.rawInput = function(data)

(Overridden from Strophe.Connection.rawInput)

Logs all raw input if debug is set to true.

log

self.log = function()

Overridden to do something useful if debug is set to true.

See: Candy.Core#init

autojoin: true
If set to `true` try to get the bookmarks and autojoin the rooms (supported by Openfire).
self.init = function(service,
options)
Initialize Core.
self.connect = function(jidOrHost,
password,
nick)
Connect to the jabber host.
self.attach = function(jid,
sid,
rid)
Attach an already binded & connected session to the server
self.disconnect = function()
Leave all rooms and disconnect
self.addHandler = function(handler,
ns,
name,
type,
id,
from,
options)
Wrapper for Strophe.Connection.addHandler() to add a stanza handler for the connection.
self.getUser = function()
Gets current user
self.setUser = function(user)
Set current user.
self.getConnection = function()
Gets Strophe connection
self.getRooms = function()
Gets all joined rooms
self.isAnonymousConnection = function()
Returns true if Candy.Core.connect was first called with a domain instead of a jid as the first param.
self.getOptions = function()
Gets options
self.getRoom = function(roomJid)
Gets a specific room
self.onWindowUnload = function()
window.onbeforeunload event which disconnects the client from the Jabber server.
self.rawInput = function(data)
(Overridden from Strophe.Connection.rawInput)
self.log = function()
Overridden to do something useful if debug is set to true.
Close