|
QuickStartGuide
The quick 'n dirty way to get started writing a client with wimas3.
Overviewwimas3 is a set of ActionScript 3.0 libraries which handle integration with the Web AIM API (WIM). The core class for the wimas3 library is the session. The session handles sign on and also maintains the connection with the server. All calls to WIM will go through the session. Likewise, the session will fire events to represent events from the server. Since the session handles sign in and sign out, you will most likely only need to create the session once during the lifetime of your app. This example assumes you are familiar with working with AS3, and already know to build the UI for your client. The purpose of this tutorial is to explain how to get online and listen for events, so you can "bring your UI to life!" Creating a SessionTo create a session, the following parameters must be passed in:
The following parameters are optional, but recommended:
There are more parameters available. For a full list of parameters please see the reference documentation. Instantiating a session would look something like this: import com.aol.api.wim.Session; ... var devId:String = "xxxxxxxxxxxxxxxxx"; var session:Session = new Session(this.stage, devId, "WIM Test Client", ".1"); You do NOT need to create a new session every time you log in to WIM. See the next section on log-in. Logging in to AIMOnce the session is created, signing in is as simple as calling signOn. The important parameters are:
session.signOn("aimuser", "password");During the sign on process, there will be a few events fired by the Session. The important one to listen to is the SessionEvent.STATE_CHANGED event. This will be called with various states as the sign in process progresses. Once sign in is complete, a BuddyListEvent will fire and provide the user's buddy list. See the next section, "Listening for Events" for more information. To sign in with a different user, just call signOff and then call signOn again. There is no need to re-create the session object every time you want to log in with a different user. The session object allows for one user to be logged in at a time. Listening for EventsOnce the session is created, you need to listen for events if you want your app to do anything. :) Here are some some events which you might want to listen for:
import com.aol.api.wim.events.BuddyListEvent;
...
session.addEventListener(BuddyListEvent.LIST_RECEIVED, onBLReceived);
protected function onBLReceived(event:BuddyListEvent):void
{
displayBuddyList(event.buddyList);
}
protected function displayBuddyList(bl:BuddyList):void
{
//parse the buddy list and display it here.
}There are quite a few events available which you might need to provide the desired functionality. See the com.aol.api.wim.events package for a full list of events. Sending and Receiving IMsSending and receiving IMs is quite simple. To send an IM, just call sendIMToBuddy with the buddy name and the message. To send an offline message if the buddy is not available, the fourth parameter must be true. See the documentation for more details. Once the IM is sent, an IMEvent.IM_SEND_RESULT event will fire. Check the statusCode property for 200 to make sure that the send was successful. This would be the best time to show the IM in your IM history window. import com.aol.api.wim.events.IMEvent;
...
//this is in session creation
session.addEventListener(IMEvent.IM_SEND_RESULT, onIMSendResult);
...
//send the IM
session.sendIMToBuddy("chattingchuck", "Hey, how is it going?");
...
//when IMs are sent
protected function onIMSendResult(evt:IMEvent):void
{
//check evt.im.recipient and evt.im.sender to make sure you want to listen for the event
if(evt.statusCode == 200)
{
//im was sent succesfully. Now would be a good time to show the message in
//the message history.
}
}To receive IMs, all you have to do is listen to the IMEvent.IM_RECEIVED event. Note that if the IM is an offline IM, most of the user information will be empty and you will need to make a requestBuddyInfo call to get the sender's presence information. session.addEventListener(IMEvent.IM_RECEIVED, onIMReceived);
...
protected function onIMReceived(evt:IMEvent):void
{
//do something here.
}Getting Buddy InfoWhen you sign in, the BUDDY_LIST_RECEIVED event will give you presence information for all the users on the buddy list. In addition, UserEvent.BUDDY_PRESENCE_UPDATED events will automatically fire when the presence changes for users on the buddy list. If you wish to receive presence information for other users, you can call requestBuddyInfo. Once the information is retrieved, a UserEvent.BUDDY_PRESENCE_UPDATED event will fire for that user. If you pass an array of screennames to requestBuddyInfo, you will get one event per screenname. import com.aol.api.wim.events.UserEvent;
...
//add the event listener only once
session.addEventListener(UserEvent.BUDDY_PRESENCE_UPDATED, onPresenceUpdated);
...
//request the buddy information. Either pass a string or an array of strings.
session.requestBuddyInfo("chattingchuck");
...
//listen for the presence updated event
protected function onPresenceUpdated(evt:UserEvent):void
{
//update your display here
}requestBuddyInfo only returns a limited amount of information with the default options. You can pass it an object with optional parameters to get more data. See the API Reference Documentation for more details. |
Sign in to add a comment
Hi, thanks for this, it's really cool.
"There are more parameters available. For a full list of parameters please see the reference documentation."
Where can I find the reference documentation?
The docs are available in the downloads section: http://code.google.com/p/wimas3/downloads/list
Awesome, thank-you.
Is there a forum somewhere I can ask additional questions? I have a specific basic questions but seems like I shouldn't clutter this page with them.
Yes! http://groups.google.com/group/wimas3