core.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.  © 2012-2014 Patrick Stadler & Michael Weibel.  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 ejabberd, Openfire).
presencePriorityDefault priority for presence messages in order to receive messages across different resources
resourceJID resource to use when connecting to the server.
Private Functions
_addNamespaceAdds a namespace.
_addNamespacesAdds namespaces needed by Candy.
Functions
initInitialize Core.
registerEventHandlersAdds listening handlers to the connection.
connectConnect to the jabber host.
Events
candy:core.before-connectTriggered before a connection attempt is made.
Functions
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
removeRoomRemoves a room from the rooms list
getRoomsGets all joined rooms
getStropheStatusGet the status set by Strophe.
setStropheStatusSet the strophe status
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 ejabberd, Openfire).
presencePriorityDefault priority for presence messages in order to receive messages across different resources
resourceJID resource to use when connecting to the server.
Private Functions
_addNamespaceAdds a namespace.
_addNamespacesAdds namespaces needed by Candy.
Functions
initInitialize Core.
registerEventHandlersAdds listening handlers to the connection.
connectConnect to the jabber host.
Events
candy:core.before-connectTriggered before a connection attempt is made.
Functions
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
removeRoomRemoves a room from the rooms list
getRoomsGets all joined rooms
getStropheStatusGet the status set by Strophe.
setStropheStatusSet the strophe status
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: undefined

If set to `true` try to get the bookmarks and autojoin the rooms (supported by ejabberd, 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, ...)

presencePriority

presencePriority: 1

Default priority for presence messages in order to receive messages across different resources

resource

resource: Candy.about.name

JID resource to use when connecting to the server.  Specify `’’` (an empty string) to request a random resource.

Private Functions

_addNamespace

Adds a namespace.

Parameters

(String) namenamespace name (will become a constant living in Strophe.NS.*)
(String) valueXML Namespace

_addNamespaces

Adds namespaces needed by Candy.

Functions

init

self.init = function(service,
options)

Initialize Core.

Parameters

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

registerEventHandlers

self.registerEventHandlers = function()

Adds listening handlers to the connection.

Use with caution from outside of 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.

Events

candy:core.before-connect

Triggered before a connection attempt is made.

Plugins should register their stanza handlers using this event to ensure that they are set.

See also #84.

Parameters

(Strophe.Connection) conncetionStrophe connection

Functions

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

removeRoom

self.removeRoom = function(roomJid)

Removes a room from the rooms list

Parameters

(String) roomJidroomJid

getRooms

self.getRooms = function()

Gets all joined rooms

Returns

Object containing instances of Candy.Core.ChatRoom

getStropheStatus

self.getStropheStatus = function()

Get the status set by Strophe.

Returns

(Strophe.Status.*)one of Strophe’s statuses

setStropheStatus

self.setStropheStatus = function(status)

Set the strophe status

Called by

Candy.Core.Event.Strophe.Connect

Parameters

(Strophe.Status.*) statusStrophe’s status

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: undefined
If set to `true` try to get the bookmarks and autojoin the rooms (supported by ejabberd, Openfire).
presencePriority: 1
Default priority for presence messages in order to receive messages across different resources
resource: Candy.about.name
JID resource to use when connecting to the server.
self.init = function(service,
options)
Initialize Core.
self.registerEventHandlers = function()
Adds listening handlers to the connection.
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.removeRoom = function(roomJid)
Removes a room from the rooms list
self.getRooms = function()
Gets all joined rooms
self.getStropheStatus = function()
Get the status set by Strophe.
self.setStropheStatus = function(status)
Set the strophe status
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