Hi guido,
I’‘ve have been trying to add the composing event to some of my code by writing a new MessageEventExtension according to JEP-0022. It works but it’‘s not finished yet and I’‘m still trying to work out if I’'m taking the wright approach.
here’'s an OLD UNFINISHED /b version of my class code…
/*
-
This library is free software; you can redistribute it and/or
-
modify it under the terms of the GNU Lesser General Public
-
License as published by the Free Software Foundation; either
-
version 2.1 of the License, or (at your option) any later version.
-
This library is distributed in the hope that it will be useful,
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-
Lesser General Public License for more details.
-
You should have received a copy of the GNU Lesser General Public
-
License along with this library; if not, write to the Free Software
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import org.jivesoftware.xiff.data.Extension;
import org.jivesoftware.xiff.data.ExtensionClassRegistry;
import org.jivesoftware.xiff.data.IExtension;
import org.jivesoftware.xiff.data.ISerializable;
/**
- This class provides an extension for Message Events.
*/
class org.jivesoftware.xiff.data.messageEvent.messageEventExtension extends Extension implements IExtension,ISerializable
{
// Static class variables to be overridden in subclasses;
public static var NS:String = “jabber:x:event”;
public static var ELEMENT:String = “x”;
private static var staticDepends = ExtensionClassRegistry;
private var messageEvents:Array;
public function messageEventExtension(parent:XMLNode)
{
super(parent);
messageEvents = new Array();
}
/**
*/
public function getNS():String
{
return messageEventExtension.NS;
}
/**
*/
public function getElementName():String
{
return messageEventExtension.ELEMENT;
}
/**
*/
public static function enable():Void
{
ExtensionClassRegistry.register(messageEventExtension);
}
/**
- Serializes the data to XML for sending.
-
@availability Flash Player 7
-
@param parent The parent node that this extension should be serialized into
-
@return An indicator as to whether serialization was successful
*/
public function serialize( parent:XMLNode ):Boolean
{
getNode().removeNode();
var ext_node:XMLNode = XMLFactory.createElement(getElementName());
ext_node.attributes.xmlns = getNS();
var eventNode:XML = new XML();
var eventCount:Number = messageEvents.length;
for(var i=0;i< eventCount;i++){
eventNode.appendChild(eventNode.createElement(messageEvents[ i ]));
}
ext_node.appendChild(eventNode);
parent.appendChild(ext_node);
return true;
}
/**
- Deserializes the Message Event data.
-
@availability Flash Player 7
-
@param node The XML node associated this data
-
@return An indicator as to whether deserialization was successful
*/
public function deserialize( node:XMLNode ):Boolean
{
setNode( node );
messageEvents = new Array();
var children = node.childNodes;
for (var i in children) {
messageEvents.push(children[ i ].toString());
}
return true;
}
public function addEvent(pEventType:String){
switch(pEventType){
case “composing”:
if (!in_array(messageEvents,pEventType)){
messageEvents.push(pEventType);
}
break;
default:
break;
}
}
private function in_array (pArray,obj):Boolean {
for (var i in this) {
if (this[ i ]==obj) return true;
}
return false;
}
}
/code
you can then send the composing event somewhat like this
this piece of code is part of another applicationclass[/i]
// all your other (class) code for making the connection etc… goes here
// don’'t forget to import the extension…
// import org.jivesoftware.xiff.data.messageEvent.messageEventExtension;
public function sendComposing( jid:String):Void{
var tempMessage:Message = new Message( jid, null, “”, “”, Message.CHAT_TYPE );
var mEvent:messageEventExtension = new messageEventExtension(tempMessage.getNode());
mEvent.addEvent(“composing”);
tempMessage.addExtension(mEvent);
// conn is an instance of the connection class
conn.send( tempMessage );
}
/code
Hope this helps
Gepatto