org.elkoserver.server.context.mods
Class Chat

java.lang.Object
  extended by org.elkoserver.server.context.Mod
      extended by org.elkoserver.server.context.mods.Chat
All Implemented Interfaces:
Cloneable, DispatchTarget, Encodable, ContextMod, ObjectCompletionWatcher

public class Chat
extends Mod
implements ObjectCompletionWatcher, ContextMod

Mod to enable users in a context to chat with each other. This mod must be attached to a context.

See Also:
PrivateChat

Constructor Summary
Chat(OptBoolean allowChat, OptBoolean allowPrivate, OptBoolean allowPush, OptBoolean allowPrivatePush)
          JSON-driven constructor.
 
Method Summary
 JSONLiteral encode(EncodeControl control)
          Encode this mod for transmission or persistence.
 void objectIsComplete()
          If this mod's configuration enables private chat and/or private push, arrange to automatically attach ephemeral PrivateChat mods to arriving users.
 void push(User from, String url, OptString frame, OptString features)
          Message handler for the 'push' message.
 void say(User from, String text)
          Message handler for the 'say' message.
 
Methods inherited from class org.elkoserver.server.context.Mod
attachTo, clone, context, ensureHolding, ensureInContext, ensureReachable, ensureSameContext, ensureSameUser, holder, isEphemeral, markAsChanged, markAsEphemeral, object
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Chat

@JSONMethod(value={"allowchat","allowprivate","allowpush","allowprivatepush"})
public Chat(OptBoolean allowChat,
                            OptBoolean allowPrivate,
                            OptBoolean allowPush,
                            OptBoolean allowPrivatePush)
JSON-driven constructor. Initialization parameters configuring the specific chat operations this mod will enable.

If 'allowPrivate' or 'allowPrivatePush' is true, this mod will automatically attach a correspondingly configured ephemeral PrivateChat mod to any user who enters the context.

Note that setting all four 'allow' parameters to false is permitted but not useful.

Parameters:
allowChat - If true, users can chat publicly, i.e., issue utterances that are broadcast to everyone in the context.
allowPrivate - If true, users can chat privately, i.e., transmit utterances to other individual users.
allowPush - If true, users can push URLs publicly, i.e., to everyone in the context.
allowPrivatePush - If true, users can push URLs privately, i.e., to other individual users.
Method Detail

encode

public JSONLiteral encode(EncodeControl control)
Encode this mod for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this mod.

objectIsComplete

public void objectIsComplete()
If this mod's configuration enables private chat and/or private push, arrange to automatically attach ephemeral PrivateChat mods to arriving users.

Application code should not call this method.

Specified by:
objectIsComplete in interface ObjectCompletionWatcher

push

@JSONMethod(value={"url","frame","features"})
public void push(User from,
                                 String url,
                                 OptString frame,
                                 OptString features)
          throws MessageHandlerException
Message handler for the 'push' message.

This message pushes a URL to everyone in the context. This is done by echoing the 'push' message to the context, marked as being from the user who sent it.

recv: { to:REF, op:"push", url:STR, frame:optSTR, features:optSTR }
send: { to:REF, op:"push", url:STR, frame:optSTR, features:optSTR, from:REF }

Parameters:
url - The URL being pushed.
frame - Optional name of a frame to push it to.
features - Optional features string to associate with it.
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod or if the 'allowPush' configuration was parameter false.

say

@JSONMethod(value="text")
public void say(User from,
                                String text)
         throws MessageHandlerException
Message handler for the 'say' message.

This message broadcasts chat text to everyone in the context. This is done by echoing the 'say' message to the context, marked as being from the user who sent it.

recv: { to:REF, op:"say", text:STR }
send: { to:REF, op:"say", text:STR, from:fromREF }

Parameters:
text - The chat text being "spoken".
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod or if the 'allowChat' configuration parameter was false.