Smack message extended attributes

Source: Internet
Author: User

XMPP does not support group chat with many localized services,

Solve the problem by developing plug-ins for openfire:

Message extension:

Message videomsg = new message ();
Videochatrtp videoxml = new videochatrtp ();
// Extension type
Videoxml. setvideotype (videomediatype. request );
// Request type
Videoxml. setaddress (Address );
// Address
Videomsg. setto (receive );
Videomsg. addextension (videoxml );
// Message Extension

Xmppconnection conn = baseservice. getinstance (). getconnection ();
Conn. sendpacket (videomsg );

The extension class must inherit packetextension.

The following is a simple example:

Public class videochatrtp implements packetextension {
Private videomediatype videotype;
Private string address;
Public String getaddress (){
Return address;
}
Public void setaddress (string address ){
This. Address = address;
}
Public videomediatype getvideotype (){
Return videotype;
}
Public void setvideotype (videomediatype videotype ){
This. videotype = videotype;
}
Public static final string name = "Jingle ";
Public static final string name_space = "com: Roger: video ";
Public videochatrtp (){
Super ();
}
@ Override
Public String getelementname (){
Return name;
}
@ Override
Public String getnamespace (){
Return name_space;
}
@ Override
Public String toxml (){
Stringbuffer sb = new stringbuffer ();
SB. append ("<jingle"). append ("xmlns = \" "). append (name_space). append (" \ "> ");
SB. append ("<type>"). append (videotype). append ("</type> ");
SB. append ("<IPaddress>"). append (Address). append ("</IPaddress> ");
SB. append ("</jingle> ");
Return sb. tostring ();
}
}

Method for listening to extended types:

Providermanager. getinstance (). addextensionprovider (videochatrtp. Name, videochatrtp. name_space, new videochatreceive ());

Extended type processing class (which implements the packetextensionprovider Interface ):

Public class videochatreceive implements packetextensionprovider {

/**
* Processing video extended message
* @ Author bin. Xiao
* @ Since 2013-04-12
**/
@ Override
Public packetextension parseextension (xmlpullparser parser)
Throws exception {
Boolean done = false;
String requesttype = "asdasd ";
String IPaddress = "asdasd ";
While (! Done ){
Int eventtype = parser. Next ();

String name = parser. getname ();
// XML Tab
If (eventtype = xmlpullparser. start_tag ){
If (name. Equals ("type ")){
Requesttype = parser. nexttext ();
}
If (name. Equals ("IPaddress ")){
IPaddress = parser. nexttext ();
}
}
If (eventtype = xmlpullparser. end_tag ){
If (name. Equals ("Jingle ")){
Done = true;
}
}
}
Videochatrtp videortp = new videochatrtp ();
Videortp. setvideotype (videomediatype. valueof (requesttype ));
// String to Enumeration
Videortp. setaddress (IPaddress );
Return videortp;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.