observer.js

CandyChats are not dead yet.

Authors

Copyright

© 2011 Amiado Group AG.  All rights reserved.  © 2012-2014 Patrick Stadler & Michael Weibel

Summary
observer.js
Candy.View.ObserverObserves Candy core events
Candy.View.Observer.ChatChat events
Functions
ConnectionThe update method gets called whenever an event to which “Chat” is subscribed.
Events
candy:view.connection.status-<STROPHE-STATUS>Using this event, you can alter the default Candy (View) behaviour when reacting to connection updates.
Functions
MessageDispatches admin and info messages
Candy.View.Observer.PresencePresence update events
Functions
updateEvery presence update gets dispatched from this method.
Events
candy:view.presencePresence update when kicked or banned
Functions
notifyPrivateChatsNotify private user chats if existing
Candy.View.Observer.PresenceErrorPresence errors get handled in this method
Candy.View.Observer.MessageMessages received get dispatched from this method.
Candy.View.Observer.LoginThe login event gets dispatched to this method
Candy.View.Observer.AutojoinMissingDisplays an error about missing autojoin information

Candy.View.Observer

Observes Candy core events

Parameters

(Candy.View.Observer) selfitself
(jQuery) $jQuery

Candy.View.Observer.Chat

Chat events

Summary
Functions
ConnectionThe update method gets called whenever an event to which “Chat” is subscribed.
Events
candy:view.connection.status-<STROPHE-STATUS>Using this event, you can alter the default Candy (View) behaviour when reacting to connection updates.
Functions
MessageDispatches admin and info messages

Functions

Connection

Connection: function(event,
args)

The update method gets called whenever an event to which “Chat” is subscribed.

Currently listens for connection status updates

Parameters

(jQuery.Event) eventjQuery Event object
(Object) args{status (Strophe.Status.*)}

Events

candy:view.connection.status-<STROPHE-STATUS>

Using this event, you can alter the default Candy (View) behaviour when reacting to connection updates.

STROPHE-STATUS has to be replaced by one of Strophe.Status

  • ERROR: 0,
  • CONNECTING: 1,
  • CONNFAIL: 2,
  • AUTHENTICATING: 3,
  • AUTHFAIL: 4,
  • CONNECTED: 5,
  • DISCONNECTED: 6,
  • DISCONNECTING: 7,
  • ATTACHED: 8

If your event handler returns `false`, no View changes will take place.  You can, of course, also return `true` and do custom things but still let Candy (View) do it’s job.

This event has been implemented due to issue #202 and here’s an example use-case for it:

// react to DISCONNECTED event
$(Candy).on('candy:view.connection.status-6', function() {
  // on next browser event loop
  setTimeout(function() {
    // reload page to automatically reattach on disconnect
    window.location.reload();
  }, 0);
  // stop view changes right here.
  return false;
});

Functions

Message

Message: function(event,
args)

Dispatches admin and info messages

Parameters

(jQuery.Event) eventjQuery Event object
(Object) args{type (message/chat/groupchat), subject (if type = message), message}

Candy.View.Observer.Presence

Presence update events

Summary
Functions
updateEvery presence update gets dispatched from this method.
Events
candy:view.presencePresence update when kicked or banned
Functions
notifyPrivateChatsNotify private user chats if existing
Candy.View.Observer.PresenceErrorPresence errors get handled in this method
Candy.View.Observer.MessageMessages received get dispatched from this method.
Candy.View.Observer.LoginThe login event gets dispatched to this method

Functions

update

update: function(event,
args)

Every presence update gets dispatched from this method.

Parameters

(jQuery.Event) eventjQuery.Event object
(Object) argsArguments differ on each type

Uses

Events

candy:view.presence

Presence update when kicked or banned

Parameters

(String) typePresence type [kick, ban]
(String) reasonReason for the kick|ban [optional]
(String) roomJidRoom JID
(Candy.Core.ChatUser) userUser which has been kicked or banned

Functions

notifyPrivateChats

notifyPrivateChats: function(user,
type)

Notify private user chats if existing

Parameters

(Candy.Core.ChatUser) userUser which has done the event
(String) typeEvent type (leave, join, kick/ban)

Candy.View.Observer.PresenceError

Presence errors get handled in this method

Parameters

(jQuery.Event) eventjQuery.Event object
(Object) args{msg, type, roomJid, roomName}

Candy.View.Observer.Message

Messages received get dispatched from this method.

Parameters

(jQuery.Event) eventjQuery Event object
(Object) args{message, roomJid}

Candy.View.Observer.Login

The login event gets dispatched to this method

Parameters

(jQuery.Event) eventjQuery Event object
(Object) args{presetJid}

Candy.View.Observer.AutojoinMissing

Displays an error about missing autojoin information

Connection: function(event,
args)
The update method gets called whenever an event to which “Chat” is subscribed.
Message: function(event,
args)
Dispatches admin and info messages
update: function(event,
args)
Every presence update gets dispatched from this method.
notifyPrivateChats: function(user,
type)
Notify private user chats if existing
Close