Created
September 15, 2010 09:54
-
-
Save ffaerber/580496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" | |
layout="absolute" | |
width="100%" height="100%" | |
verticalGap="0" | |
horizontalGap="0" | |
creationComplete="popuplogin()"> | |
<mx:Script> | |
<![CDATA[ | |
import events.LoginViewEvent; | |
import mx.containers.TitleWindow; | |
import mx.controls.Label; | |
import mx.events.CloseEvent; | |
import mx.managers.PopUpManager; | |
import org.igniterealtime.xiff.conference.Room; | |
import org.igniterealtime.xiff.core.UnescapedJID; | |
import org.igniterealtime.xiff.core.XMPPConnection; | |
import org.igniterealtime.xiff.data.*; | |
import org.igniterealtime.xiff.data.forms.FormExtension; | |
import org.igniterealtime.xiff.data.muc.MUC; | |
import org.igniterealtime.xiff.data.muc.MUCAdminExtension; | |
import org.igniterealtime.xiff.data.muc.MUCItem; | |
import org.igniterealtime.xiff.data.muc.MUCOwnerExtension; | |
import org.igniterealtime.xiff.events.IncomingDataEvent; | |
import org.igniterealtime.xiff.events.LoginEvent; | |
import org.igniterealtime.xiff.events.MessageEvent; | |
import org.igniterealtime.xiff.events.OutgoingDataEvent; | |
import org.igniterealtime.xiff.events.RoomEvent; | |
import org.igniterealtime.xiff.events.RosterEvent; | |
import org.igniterealtime.xiff.im.Roster; | |
import spark.components.Group; | |
import view.components.LoginView; | |
// you will need to set these | |
private var titleWindow:TitleWindow; | |
private var connection:XMPPConnection; | |
private var chatRoom:Room; | |
private var roster:Roster; | |
private var people:Dictionary; | |
private var roomjid:UnescapedJID | |
private var _keepAlive:Timer; | |
[Bindable] | |
private var SERVER:String = "jabber.ccc.de"; | |
private var CONFERENCE_SERVER:String = "conference.jabber.ccc.de"; | |
private var PORT:Number = 5222; | |
private function init(e:LoginViewEvent):void | |
{ | |
connection = new XMPPConnection(); | |
connection.addEventListener(LoginEvent.LOGIN, onLogin); | |
connection.useAnonymousLogin = true; | |
connection.username = e.getUsername(); | |
connection.password = e.getPassword() | |
connection.server = e.getServer() | |
connection.port = PORT; | |
connection.connect() | |
_keepAlive = new Timer(2 * 60 * 1000); | |
_keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop); | |
roster = new Roster(connection); | |
roster.addEventListener(RosterEvent.ROSTER_LOADED, onRoster); | |
roster.addEventListener(RosterEvent.SUBSCRIPTION_DENIAL, onRoster); | |
roster.addEventListener(RosterEvent.SUBSCRIPTION_REQUEST, onRoster); | |
roster.addEventListener(RosterEvent.SUBSCRIPTION_REVOCATION, onRoster); | |
roster.addEventListener(RosterEvent.USER_ADDED, onRoster); | |
roster.addEventListener(RosterEvent.USER_AVAILABLE, onRoster); | |
roster.addEventListener(RosterEvent.USER_PRESENCE_UPDATED, onRoster); | |
roster.addEventListener(RosterEvent.USER_REMOVED, onRoster); | |
roster.addEventListener(RosterEvent.USER_SUBSCRIPTION_UPDATED, onRoster); | |
roster.addEventListener(RosterEvent.USER_UNAVAILABLE, onRoster); | |
} | |
private function createRoom():void | |
{ | |
chatRoom = new Room(connection); | |
chatRoom.roomJID = new UnescapedJID("[email protected]"); | |
//chatRoom.roomName = "toplink1"; | |
//chatRoom.conferenceServer = "conference.jabber.ccc.de"; | |
//chatRoom.nickname = "tippe toppe"; | |
chatRoster.dataProvider = chatRoom; | |
chatRoom.connection = connection; | |
chatRoom.addEventListener(RoomEvent.ADMIN_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.AFFILIATIONS, onRoom); | |
chatRoom.addEventListener(RoomEvent.BANNED_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.DECLINED, onRoom); | |
chatRoom.addEventListener(RoomEvent.GROUP_MESSAGE, onRoom); | |
chatRoom.addEventListener(RoomEvent.LOCKED_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.MAX_USERS_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.NICK_CONFLICT, onRoom); | |
chatRoom.addEventListener(RoomEvent.PASSWORD_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.PRIVATE_MESSAGE, onRoom); | |
chatRoom.addEventListener(RoomEvent.REGISTRATION_REQ_ERROR, onRoom); | |
chatRoom.addEventListener(RoomEvent.ROOM_JOIN, onRoom); | |
chatRoom.addEventListener(RoomEvent.ROOM_LEAVE, onRoom); | |
chatRoom.addEventListener(RoomEvent.SUBJECT_CHANGE, onRoom); | |
chatRoom.addEventListener(RoomEvent.USER_BANNED, onRoom); | |
chatRoom.addEventListener(RoomEvent.USER_DEPARTURE, onRoom); | |
chatRoom.addEventListener(RoomEvent.USER_JOIN, onRoom); | |
chatRoom.addEventListener(RoomEvent.USER_KICKED, onRoom); | |
chatRoom.join(); | |
} | |
private function onRoom(event:RoomEvent):void | |
{ | |
switch (event.type) | |
{ | |
case RoomEvent.ADMIN_ERROR : | |
break; | |
case RoomEvent.AFFILIATIONS : | |
break; | |
case RoomEvent.BANNED_ERROR : | |
break; | |
case RoomEvent.CONFIGURE_ROOM : | |
break; | |
case RoomEvent.DECLINED : | |
break; | |
case RoomEvent.GROUP_MESSAGE : | |
// Could also use MessageEvent event of the XMPPConnection. | |
//trace("event.data is Message: " + (event.data is Message) + ", data: " + event.data); | |
addGroupMessage(event.data as Message); | |
break; | |
case RoomEvent.LOCKED_ERROR : | |
break; | |
case RoomEvent.MAX_USERS_ERROR : | |
break; | |
case RoomEvent.NICK_CONFLICT : | |
break; | |
case RoomEvent.PASSWORD_ERROR : | |
break; | |
case RoomEvent.PRIVATE_MESSAGE : | |
break; | |
case RoomEvent.REGISTRATION_REQ_ERROR : | |
break; | |
case RoomEvent.ROOM_JOIN : | |
break; | |
case RoomEvent.ROOM_LEAVE : | |
break; | |
case RoomEvent.SUBJECT_CHANGE : | |
break; | |
case RoomEvent.USER_BANNED : | |
break; | |
case RoomEvent.USER_DEPARTURE : | |
trace("USER_DEPARTURE") | |
break; | |
case RoomEvent.USER_JOIN : | |
trace("USER_JOIN") | |
break; | |
case RoomEvent.USER_KICKED : | |
break; | |
} | |
} | |
private function onRoster(event:RosterEvent):void | |
{ | |
//trace("onRoster. " + event.toString()); | |
switch (event.type) | |
{ | |
case RosterEvent.ROSTER_LOADED : | |
break; | |
case RosterEvent.SUBSCRIPTION_DENIAL : | |
break; | |
case RosterEvent.SUBSCRIPTION_REQUEST : | |
// If the JID is in the roster, accept immediately | |
if (roster.getPresence(event.jid) != null) | |
{ | |
roster.grantSubscription(event.jid, true); | |
} | |
break; | |
case RosterEvent.SUBSCRIPTION_REVOCATION : | |
break; | |
case RosterEvent.USER_ADDED : | |
trace("USER_ADDED: "+event.jid.toString()); | |
break; | |
case RosterEvent.USER_AVAILABLE : | |
break; | |
case RosterEvent.USER_PRESENCE_UPDATED : | |
break; | |
case RosterEvent.USER_REMOVED : | |
break; | |
case RosterEvent.USER_SUBSCRIPTION_UPDATED : | |
break; | |
case RosterEvent.USER_UNAVAILABLE : | |
break; | |
} | |
} | |
private function addGroupMessage(message:Message):void | |
{ | |
var date:Date = new Date(); | |
if (message.time != null) | |
{ | |
date = message.time; | |
} | |
commLog.htmlText += "[" + date.getHours() + ":" + date.getMinutes() + " | " + message.from.resource + "] " + message.body + "\n"; | |
} | |
protected function popuplogin():void | |
{ | |
var loginView:LoginView = new LoginView(); | |
loginView.addEventListener(LoginViewEvent.LOGIN, init) | |
titleWindow = new TitleWindow(); | |
titleWindow.title = "Jabber Login"; | |
titleWindow.width = 730; | |
titleWindow.height = 70; | |
titleWindow.addChild(loginView); | |
PopUpManager.addPopUp(titleWindow, this, true); | |
PopUpManager.centerPopUp(titleWindow); | |
} | |
private function onLogin(e:LoginEvent):void | |
{ | |
trace("onLogin"); | |
PopUpManager.removePopUp(titleWindow); | |
createRoom() | |
rosterGrid.dataProvider = roster; | |
} | |
private function onKeepAliveLoop(event:TimerEvent):void | |
{ | |
if (connection.isLoggedIn()) | |
{ | |
connection.sendKeepAlive(); | |
} | |
} | |
]]> | |
</mx:Script> | |
<mx:DataGrid x="9" y="15" id="rosterGrid" editable="false" enabled="true" height="428" width="449"/> | |
<mx:DataGrid x="11" y="474" id="chatRoster" height="168" width="100%"/> | |
<mx:TextArea x="612" y="258" width="555" height="208" id="commLog" liveScrolling="true"/> | |
</mx:Application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment