|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Session
Encapsulates one instant message session, using YMSG. When writing a client, this is the entry point into the API, allowing access to YMSG features and generating events based upon incoming network activity.
This document uses various terms
Term | Meaning |
User | A single unique Yahoo user |
Friend | A user who is in your Yahoo friends list |
Group | One sub-division of your Yahoo friends list |
Contact | A Yahoo user (not necessarily a friend) who has contacted you |
Packet | A single Yahoo network message |
YMSG | Yahoo Instant Messager protocol |
The connection handling and general housekeeping methods are:
YahooUser
object. The latter are canonical, meaning that
only one object is ever created for each user. If you hold a reference
to a YahooUser object, the values inside it will be updated as the
status of the user changes. The friends/groups/users methods are:
try { // Create a session, try fallback ports if default fails Session ss = new Session(); // Register for session events ss.addSessionListener(new MySessionHandler()); // Optionally, set status to login as invisible ss.setStatus(StatusConstants.STATUS_INVISIBLE); // Login (obviously you'd use your real username/password) ss.login("username","password"); // Did we successfully log in? if(ss.getSessionStatus()==MESSAGING) { // We might want to save the port somewhere for next login attempt System.out.println("Success on port: "+session.getPort()); // Send a message to myFriend, wait for 5 seconds, then logout ss.sendMessage("myFriend","Borag Thung, Earthlet"); try { Thread.sleep(5*1000); } catch(InterruptedException e) {} ss.logout(); } else { // Failed to log in - reset so we can re-use the same object ss.reset(); } }catch(Exception e) { ss.reset(); }To modify the status there are a couple of overloaded methods. Here's some examples of how to use them:
// Change to on phone and change to invisible ss.setStatus(StatusConstants.STATUS_ONPHONE); ss.setStatus(StatusConstants.STATUS_INVISIBLE);To print the group and friends list, we might do something like this:// Change to custom away message, and custom back (available) message // (the API automatically sets the status to custom for us) ss.setStatus("I'm otta'here!",true); ss.setStatus("Ready and waiting!!",false);
YahooGroup[] yg = ss.getGroups(); for(int i=0;i<yg.length;i++) { System.out.println(yg[i].getName()); for(int j=0;j<yg[i].size();j++) { YahooUser yu = yg[i].getUserAt(j); System.out.println(" "+yu.toString()); } }Upon receiving a message we might do something like this (note: see
SessionListener
for messageReceived
details) :
public void messageReceived(SessionEvent ev) { String from=ev.getFrom() , msg=ev.getMessage(); Hashtable h = ss.getUsers(); YahooUser yu = (YahooUser)h.get(from); if(yu==null) { System.out.println("<Not a friend> "+from+": "+msg); } else { if(yu.isIgnored()) return; else System.out.println(yu.getId()+": "+msg); } }Before we log into a chatroom we need to select one from the list of room lobbies available at Yahoo. Rooms are organised into a hierarchy of categories, each category holding zero or more categories and/or zero or more public rooms and/or zero or more private rooms. Each room holds one or more lobby.
// Load first lobby of first room of first category YahooChatCategory root = YahooChatCategory.loadCategories(); YahooChatCategory ycc = (YahooChatCategory)root.getCategories().elementAt(0); YahooChatRoom ycr = (YahooChatRoom)ycc.getPublicRooms().elementAt(0); YahooChatLobby ycl = (YahooChatLobby)ycr.getLobbies().elementAt(0);Having selected a lobby, connecting and using a room is easy.
// Connect to a lobby, send a message, then logout ss.chatLogin(ycl); ss.sendChatMessage("Hello world!"); ss.chatLogout();Messages from the room arrive as part of methods in the
SessionListener
interface. chatLogonReceived
and chatLogoffReceived
inform us of members arriving and
leaving, while chatMessageReceived
details a new chat
message.
Identities are Yahoo's way of allowing users to have multiple aliases,
and this package supports them via the YahooIdentity
object.
An array of these objects is created during the login process, accessible
via the getIdentities
method. The objects in this array can
then be passed to various overloaded methods, and the resulting network
messages will be 'badged' with that identity.
YahooIdentity[] ids = ss.getIdentities(); ss.sendMessage("lois","This looks like a job for...",ids[0]); ss.sendMessage("lois","Superman!",ids[1]);In the above example the user lois will be sent a message from two apparently different users. Little does she suspect that they are the same person. (In reality you should not 'hard code' identity objects by index like this, as objects may be re-ordered each time the data is refreshed.)
Field Summary |
Constructor Summary | |
Session()
Creates a single Yahoo session using the best guess connection handler. |
|
Session(ConnectionHandler ch)
Creates a single Yahoo session, using the prescribed connection handler. |
Method Summary | |
void |
acceptConferenceInvite(YahooConference room)
Accepts a conference invite from another user. |
void |
activateIdentity(YahooIdentity yid,
boolean activate)
Activates or deactivates a Yahoo identity. |
void |
addFriend(String friend,
String group)
Add a user to a group. |
void |
addSessionListener(SessionListener ss)
Adds a listener object to receive events from the session. |
void |
addTypingNotification(String user,
Component com)
Sets the AWT component being used for typing notification. |
void |
chatLogin(YahooChatLobby ycl)
Requests a chat login, blocking until the login process is over. |
void |
chatLogin(YahooChatLobby ycl,
YahooIdentity yid)
Requests a chat login, using a specific identity, blocking until the login process is over. |
void |
chatLogout()
Requests to be logged out of a chat room. |
YahooConference |
createConference(String[] users,
String msg)
Creates a new conference. |
YahooConference |
createConference(String[] users,
String msg,
YahooIdentity yid)
Creates a new conference, using a specific identity. |
void |
declineConferenceInvite(YahooConference room,
String msg)
Decline a conference invite from another user. |
void |
extendConference(YahooConference room,
String user,
String msg)
Invites a user to an existing conference. |
int |
getChatSessionStatus()
Returns the status of the chat connection. |
ConnectionHandler |
getConnectionHandler()
Returns the currently employed connection handler. |
String[] |
getCookies()
Returns the three cookies Yahoo sends the client upon successful login. |
YahooChatLobby |
getCurrentChatLobby()
Returns the current chatroom lobby, or null if not logged into a chatroom. |
String |
getCustomStatusMessage()
Returns the custom status message. |
YahooGroup[] |
getGroups()
Gets a copy of the array of groups containing Yahoo friends. |
YahooIdentity[] |
getIdentities()
Returns a list of valid identities for this Yahoo account. |
String |
getImvironment()
Returns the Imvironment string passed to the client during login. |
YahooIdentity |
getLoginIdentity()
Returns the login identity for this Yahoo account. |
YahooIdentity |
getPrimaryIdentity()
Returns the true identity for this Yahoo account. |
int |
getSessionStatus()
Gets the status of the connection. |
long |
getStatus()
Returns the actual status of the Yahoo user. |
YahooUser |
getUser(String id)
Returns the object for the given Yahoo id string. |
Hashtable |
getUsers()
Returns a hashtable of all users known by this session. |
void |
ignoreContact(String friend,
boolean ignore)
Change the ignore status of a Yahoo user. |
boolean |
isCustomBusy()
Returns the custom status busy flag. |
void |
keyTyped(String user)
Manually update key notification. |
void |
leaveConference(YahooConference room)
Leaves a conference. |
void |
login(String u,
String p)
Requests the session be logged in. |
void |
logout()
Requests the session be logged out (disconnected). |
void |
refreshFriends()
Sends a request for the friends/groups data to be updated. |
void |
refreshStats()
Requests a refresh of status and new mail count from server. |
void |
rejectContact(String friend,
String msg)
Reject an offer to be added to a friends list. |
void |
removeFriend(String friend,
String group)
Remove a friend from a group. |
void |
removeSessionListener(SessionListener ss)
Removes a listener object to receive events from the session. |
void |
removeTypingNotification(String user)
Clears the AWT component being used for typing notification. |
void |
reset()
Resets a spent session so the object can be re-used. |
void |
resetChat()
Resets a failed chat login. |
void |
saveFileTransferAs(SessionFileTransferEvent ev,
String filename)
Saves an incoming file transfer to the specified filename. |
void |
saveFileTransferTo(SessionFileTransferEvent ev,
String dir)
Saves an incoming file transfer to the specified directory. |
void |
sendBuzz(String to)
Sends a buzz message. |
void |
sendBuzz(String to,
YahooIdentity yid)
Sends a buzz message, using a specific identity. |
void |
sendChatEmote(String emote)
Send a message to the current chatroom lobby, marked as an emote. |
void |
sendChatMessage(String msg)
Send a message to the current chatroom lobby. |
void |
sendConferenceMessage(YahooConference room,
String msg)
Sends a message to users in a conference. |
void |
sendFileTransfer(String user,
String filename,
String msg)
Send a binary file to the specified Yahoo user. |
void |
sendMessage(String to,
String msg)
Sends a message. |
void |
sendMessage(String to,
String msg,
YahooIdentity yid)
Sends a message, using a specific identity. |
void |
setStatus(long s)
Sets the status of the Yahoo user. |
void |
setStatus(String m,
boolean b)
Sets the status of the Yahoo user using custom status. |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Session()
socksProxyHost
is
set, a SOCKSConnectionHandler
is installed; otherwise
if http.proxyHost
or proxyHost
are set,
a HTTPConnectionHandler
is installed; otherwise
a DirectConnectionHandler
is installed. (In all three
cases the default (no args) constructor of the connection handler
is called.)
public Session(ConnectionHandler ch)
ch
- connection handlerMethod Detail |
public void addSessionListener(SessionListener ss)
Multiple listeners may be added for a single session, but duplicates are ignored. The order in which each listener is served a given event is not guaranteed - do not assume the event handlers will be called in the same order that the listeners were registered.
ss
- the event listener to addremoveSessionListener(SessionListener ss)
public void removeSessionListener(SessionListener ss)
ss
- the event listener to removeaddSessionListener(SessionListener ss)
public ConnectionHandler getConnectionHandler()
public void login(String u, String p) throws IllegalStateException, IOException, AccountLockedException, LoginRefusedException
SessionListener
be registered with the session before
this method is called. After calling this method (which will block
until logon is complete) getSessionStatus
should be
checked to see if the login attempt was successful. Unsuccessful
Session objects
must be reset
before being
re-used.
Yahoo doesn't really have a good line in error conditions. We
either logged in or we failed, although the overwhelming source of
errors (barring poor network connections) will come from bad
usernames and/or passwords. This method throws two exceptions
which are subclasses of YahooException
- the first
is AccountLockedException
and the second is
LoginRefusedException
. Both indicate a failure to
log into the Yahoo service. The first typically carries a
URL
of a Web page to display when the account is
locked - usually the generic Yahoo login page.
Usernames are converted to lower case, as Yahoo's usernames are case insensitive.
The property ymsg.network.loginTimeout
can be used to
specify a timeout, in seconds, after which the method will throw an
IOException
. A value of zero or below disables the
timeout facility.
u
- Yahoo username of the account to be connected top
- password of said Yahoo account
IllegalStateException
- if already logged in
IOException
- if i/o problems from underlying streams or timeout
AccountLockedxception
- if Yahoo is blocking the account
LoginRefusedException
- if the username/password is refused
AccountLockedException
logout()
,
getSessionStatus()
,
reset()
public void logout() throws IllegalStateException, IOException
IllegalStateException
- if not logged in
IOException
- if i/o problems from underlying streamslogin(String u,String p)
public void reset() throws IllegalStateException
IllegalStateException
- if still logged in.login(String u,String p)
,
logout()
public void sendMessage(String to, String msg) throws IllegalStateException, IOException
to
- Yahoo id of person to send message tomsg
- Text of message (ASCII or UTF-8 please!)
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void sendMessage(String to, String msg, YahooIdentity yid) throws IllegalStateException, IOException, IllegalIdentityException
to
- Yahoo id of person to send message tomsg
- Text of message (ASCII or UTF-8 please!)yid
- Yahoo id (alias) to send the message as
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streams
IllegalIdentityException
- if the user does not 'own' the supplied identitypublic void sendBuzz(String to) throws IllegalStateException, IOException
to
- Yahoo id of person to send buzz to
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void sendBuzz(String to, YahooIdentity yid) throws IllegalStateException, IOException, IllegalIdentityException
to
- Yahoo id of person to send buzz toyid
- Yahoo id (alias) to send the message as
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streams
IllegalIdentityException
- if the user does not 'own' the supplied identitypublic int getSessionStatus()
UNSTARTED
when idle and ready to go, AUTH
when currently engaged in trying to log in, MESSAGING
when successfully connected or FAILED
when a login was
unsuccessful.
Note: DO NOT confuse this with the status of the Yahoo user
themself. The session status documents the state of the network
connection to the Yahoo service. The Yahoo status (see
getStatus
and setStatus
) documents the
state of the Yahoo user to the 'outside world' (ie: available, busy,
not in the office, etc).
StatusConstants
public long getStatus()
setStatus(long s)
public void setStatus(long s) throws IllegalArgumentException, IOException
s
- status integer, preferably from StatusConstants
IllegalArgumentException
- if the status is set to something
other than available or invisible and the session
is unstarted.
IOException
- if i/o problems from underlying streamsgetStatus()
,
setStatus(String m,boolean b)
public void setStatus(String m, boolean b) throws IllegalArgumentException, IOException
m
- custom message textb
- busy (true) or available (false) flag - busy changes the
user's smiley face icon to feature a no-entry sign
IllegalArgumentException
- if the session is unstarted (only
available or invisible allowed) or the message is null.
IOException
- if i/o problems from underlying streamsgetStatus()
,
setStatus(long s)
public String getCustomStatusMessage()
isCustomBusy()
public boolean isCustomBusy()
getCustomStatusMessage()
public void refreshStats() throws IllegalStateException, IOException
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic YahooIdentity[] getIdentities()
YahooIdentity
parameter.
Do not rely on the order of these identities in the array. To find an identity object with a given username, search the array, do not assume it will always be at the same index.
public YahooIdentity getPrimaryIdentity()
public YahooIdentity getLoginIdentity()
public void activateIdentity(YahooIdentity yid, boolean activate) throws IllegalStateException, IllegalIdentityException, IOException
The primary identity cannot be deactivated. Attempting to call this
method with the primary identity, either for activation or
deactivation, will result in an IllegalIdentityException
.
yid
- Yahoo id (alias) to de/activateactivate
- true to activate, false to deactivate
IllegalStateException
- if not connected to Yahoo
IllegalIdentityException
- if the user does not 'own' the supplied identity
or the primary identity is used
IOException
- if i/o problems from underlying streamspublic void addTypingNotification(String user, Component com)
Yahoo sends out notification packets whenever it knows you are typing a message to someone (yes - it sounds like a waste of network bandwidth to me too... but never the less, this is what it does!). These messages can be automatically generated if you provide an AWT component for the jYMSG API to monitor. A listener will be registered with the target component to monitor key presses, and notification packets automatically sent at intervals.
Only one notification handler can be set for each target user. Attempts to add a second, without first removing the current one, will be ignored.
For clients which do not use AWT or Swing, the notification system
now supports a manual scheme for sending typing events. To use
the manual scheme, call this method with a null component parameter,
then use keyTyped
to inform the session of each key press.
Note: DO NOT use this feature for conferences, only regular one to one style messages.
user
- Yahoo id to send notifications tocom
- AWT component to monitor for key presses, or nullremoveTypingNotification(String user)
,
keyTyped(String user)
public void removeTypingNotification(String user)
Yahoo sends out notification packets when it knows you are typing to someone. The jYMSG API can generate these automatically. This method clears the current AWT component being monitored. Specifically, it attempts to unregister it's key event listener. It has no effect if an event source has not already been set.
user
- Yahoo id to stop notifcations foraddTypingNotification(String user,Component com)
public void keyTyped(String user)
addTypingNotfication
can be called
with a null component, then this method used to manually inform the
notification thread of each key press. The notification thread will
dispatch notify packets, as necessary.
Note: this method can also be used to send 'fake' key presses to notifiers which are registered with an AWT/Swing component - although there is no legitimate reason to do this.
user
- Yahoo id to 'fake' a key notifcation foraddTypingNotification(String user,Component com)
public YahooGroup[] getGroups()
YahooUser
objects. Each friend is represented by a specific object unique to
that user id. if a friend appears more than once, either within a
single group or in more than one group, then the same
YahooUser
object will be referenced.
This method will return null if the session is not connected.
Note: this method returns a clone of the array, not the original, which makes it more expensive than simply returning a reference - avoid calling this method repeately inside a tight loop.
getUsers()
public Hashtable getUsers()
YahooUser
objects for every user that this session has come into contact with,
either via the friends group listing, or because they were in a chat
room the session visited.
There is no ability to maintain the details or status of Yahoo users which the session is no longer in contact with. If we leave a chatroom, although the member's objects will remain, they will not necessarily get updated (unless the session is also connected with that user via another path - such as if they are in a friends group).
public YahooUser getUser(String id)
Looking up users is handy when a message comes in and we quickly need
to check if the sender is ignored, a friend, or something similar. Use
the accessor methods on the returned YahooUser
object to
determine a user's status.
This method will return null if the Yahoo id is unknown. Unknown users are those who have not already come to the session's attention (via the friends list, for example).
Take note of the issues with maintaining accurate status details, as
mentioned in the getUsers
method above.
id
- string id of Yahoo user
public String getImvironment()
public String[] getCookies()
public YahooConference createConference(String[] users, String msg) throws IllegalStateException, IOException
This method returns a conference name string, which is used to identify this specific conference when using other conference methods.
Do not put the current user, or any of their identities, into the
users
list. For logistics, jYMSG maintains a sharp
distinction between conferences created by the user, and those
the user was invited to. Inviting yourself to your own conference
will confuse matters. (At some point this restiction may be lifted.)
users
- array of Yahoo id's to invitemsg
- invite message / topic
IllegalStateException
- if not connected to Yahoo
IllegalIdentityException
- if the 'users' array contains the current user
IOException
extendConference(YahooConference room,String user,String msg)
public YahooConference createConference(String[] users, String msg, YahooIdentity yid) throws IllegalStateException, IOException, IllegalIdentityException
The identity used to create the conference is stored as part of the
YahooConference
object, with all subsequent calls using
said conference object automatically using this identity.
This method returns a conference name string, which is used to identify this specific conference when using other conference methods.
Do not put the current user, or any of their identities, into the
users
list. For logistics, jYMSG maintains a sharp
distinction between conferences created by the user, and those
the user was invited to. Inviting yourself to your own conference
will confuse matters. (At some point this restiction may be lifted.)
users
- array of Yahoo id's to invitemsg
- invite message / topic
IllegalStateException
- if not connected to Yahoo
IllegalIdentityException
- if the user does not 'own' the supplied identity
IllegalIdentityException
- if the 'users' array contains the current user
IOException
extendConference(YahooConference room,String user,String msg)
public void acceptConferenceInvite(YahooConference room) throws NoSuchConferenceException, IOException, IllegalStateException
SessionListener
method
conferenceInviteReceived
. The room
parameter
can be found by using getRoom
in SessionConferenceEvent
.
room
- conference object
IllegalStateException
- if not connected to Yahoo
NoSuchConferenceException
- if no such conference exists
(this should never happen, unless called outside
an invite event!)
IOException
- if i/o problems from underlying streamspublic void declineConferenceInvite(YahooConference room, String msg) throws NoSuchConferenceException, IOException, IllegalStateException
SessionListener
method
conferenceInviteReceived
. The room
parameter
can be found by using getRoom
in SessionConferenceEvent
.
room
- conference objectmsg
- rejection message
IllegalStateException
- if not connected to Yahoo
NoSuchConferenceException
- if no such conference exists
(this should never happen, unless called outside
an invite event!)
IOException
- if i/o problems from underlying streamspublic void extendConference(YahooConference room, String user, String msg) throws NoSuchConferenceException, IOException, IllegalStateException
See createConference
for notes on the restriction on
identities of the current user.
room
- conference objectuser
- Yahoo id of user to invitemsg
- invite message / topic
IllegalStateException
- if not connected to Yahoo
NoSuchConferenceException
- if no such conference exists
IOException
- if i/o problems from underlying streams
IllegalIdentityException
- if 'user' is the current usercreateConference(String[] users,String msg)
public void sendConferenceMessage(YahooConference room, String msg) throws NoSuchConferenceException, IOException, IllegalStateException
room
- conference objectmsg
- message text
IllegalStateException
- if not connected to Yahoo
NoSuchConferenceException
- if no such conference exists
IOException
- if i/o problems from underlying streamspublic void leaveConference(YahooConference room) throws NoSuchConferenceException, IOException, IllegalStateException
room
- conference object
IllegalStateException
- if not connected to Yahoo
NoSuchConferenceException
- if no such conference exists
IOException
- if i/o problems from underlying streamspublic void addFriend(String friend, String group) throws IllegalStateException
Note: A request packet will be sent to the specified user (if
they are offline if will be held for them and delivered at the
earliest available time) giving them a chance to reject your
addition, causing their Yahoo id to be removed from your friends
list. The event method contactRejectionReceived
will
be called when confirmation of a refusal is received (please
remember, this may be some time, even days, after we added the
user).
friend
- Yahoo id of friend to addgroup
- group name
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void removeFriend(String friend, String group) throws IllegalStateException
friend
- Yahoo id of friend to removegroup
- group name
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void rejectContact(String friend, String msg) throws IllegalStateException
SessionListener
method
contactRequestReceived
. The getFrom
method
of SessionEvent
will reveal the id of the user who is
trying to add us to their list.
Note: the way Yahoo works with regard to friends lists is unusual. It is the responsibility of the target to reject unwanted attempts to add them to other user's lists. If the target does nothing, the attempt is successful (indeed, the intended way to allow yourself to be added to someone else's list is to just ignore their request - without a refusal the addition stands!)
friend
- Yahoo id of contact wishing to add us to their listmsg
- rejection message
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void ignoreContact(String friend, boolean ignore) throws IllegalStateException
friend
- Yahoo id of contact to changeignore
- True to ignore, false to unignore
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void refreshFriends()
Note: this method merely sends a request to Yahoo for a refresh
of the data. The SessionListener
should be used to
determine when (or if!) this data has arrived, via its
friendsUpdateReceived
method.
IllegalStateException
- if not connected to Yahoo
IOException
- if i/o problems from underlying streamspublic void sendFileTransfer(String user, String filename, String msg) throws IllegalStateException, FileTransferFailedException, IOException
There is a system properties which alters the target of a connection.
ymsg.network.fileTransferHost
can be used to set the
host to which the connection will be made. In reality is it highly
unlikely that this property should need to be changed from its
default: filetransfer.msg.yahoo.com
.
user
- the Yahoo user to send the file tofilename
- the full filename and path of the file to sendmsg
- an accompanying message text
IllegalStateException
- if not connected to Yahoo
FailedFileTransferException
- if the upload fails or is rejected
IOException
- if i/o problems from underlying streams
FileTransferFailedException
public void saveFileTransferAs(SessionFileTransferEvent ev, String filename) throws FileTransferFailedException, IOException
ev
- The event object associated with this file transferfilename
- The full filename and path of the file to save the
incoming data to
FailedFileTransferException
- if the download fails
IOException
- if i/o problems from underlying streams
FileTransferFailedException
public void saveFileTransferTo(SessionFileTransferEvent ev, String dir) throws FileTransferFailedException, IOException
Content-Disposition:
header with a filename, this will be used in preference.
ev
- The event object associated with this file transferdir
- The full path of the directory to save the file to
FailedFileTransferException
- if the download fails
IOException
- if i/o problems from underlying streams
FileTransferFailedException
public void chatLogin(YahooChatLobby ycl) throws IllegalStateException, IOException, LoginRefusedException
To check the outcome, use getChatSessionStatus
. As
with the session login itself, an unsuccessful chat login must be
reset by using resetChatStatus
before a second login
can be attempted.
The property ymsg.network.loginTimeout
can be used to
specify a timeout, in seconds, after which the method will throw an
IOException
. A value of zero or below disables the
timeout facility.
Yahoo only permits a session to be logged into one lobby at a time. Joining a second lobby will result in being removed from the first. (Don't blame me - blame Yahoo!)
ycl
- the chat lobby to join
IllegalStateException
- if already logged into a lobby
IOException
- if i/o problems from underlying streams
LoginRefusedException
- if the room is inaccessible/fullpublic void chatLogin(YahooChatLobby ycl, YahooIdentity yid) throws IllegalStateException, IOException, LoginRefusedException, IllegalIdentityException
To check the outcome, use getChatSessionStatus
. As
with the session login itself, an unsuccessful chat login must be
reset by using resetChatStatus
before a second login
can be attempted.
The property ymsg.network.loginTimeout
can be used to
specify a timeout, in seconds, after which the method will throw an
IOException
. A value of zero or below disables the
timeout facility.
Yahoo only permits a session to be logged into one lobby at a time. Joining a second lobby will result in being removed from the first. (Don't blame me - blame Yahoo!)
ycl
- the chat lobby to join
IllegalStateException
- if already logged into a lobby
IOException
- if i/o problems from underlying streams
IllegalIdentityException
- if the user does not 'own' the supplied identity
LoginRefusedException
- if the room is inaccessible/fullpublic void chatLogout() throws IllegalStateException, IOException
chatLogin
again.
IllegalStateException
- if not logged into a lobby
IOException
- if i/o problems from underlying streamspublic void sendChatMessage(String msg) throws IllegalStateException, IOException
Note: Yahoo does not echo the message back to the sending client, so to maintain a correct transcript on the client GUI, a well-behaved application should parrot the message to the chat display as well as transmitting it.
msg
- Text of message (ASCII or UTF-8 please!)
IllegalStateException
- if not logged into a lobby
IOException
- if i/o problems from underlying streamspublic void sendChatEmote(String emote) throws IllegalStateException, IOException
Note 1: Yahoo does not echo the message back to the sending client, so to maintain a correct transcript on the client GUI, a well-behaved application should parrot the message to the chat display as well as transmitting it.
Note 2: The ymsg.support
package has an EmoteManager
class which can be used to handle arrays of Emote strings.
emote
- Text of message (ASCII or UTF-8 please!)
IllegalStateException
- if not logged into a lobby
IOException
- if i/o problems from underlying streamspublic YahooChatLobby getCurrentChatLobby()
YahooChatLobby
, of nullpublic int getChatSessionStatus()
UNSTARTED
when idle, CONNECT
during the
handshaking stage of connecting to a room, LOGON
when
in the second stage, MESSAGING
when successfully
connected or FAILED
when a login was unsuccessful.
public void resetChat() throws IllegalStateException
IllegalStateException
- if still logged in.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |