Smack Message 擴充屬性

來源:互聯網
上載者:User

標籤:style   http   os   io   ar   art   問題   cti   sp   

由於XMPP不支援群聊很多本地化的服務,

針對Openfire開發外掛程式解決問題:

Message 擴充:

Message videoMsg = new Message();
VideoChatRTP videoXml = new VideoChatRTP();
//擴充類型
videoXml.setVideoType(VideoMediaType.REQUEST);
//請求類型
videoXml.setAddress(address);
//地址
videoMsg.setTo(receive);
videoMsg.addExtension(videoXml);
//message擴充

XMPPConnection conn = BaseService.getInstance().getConnection();
conn.sendPacket(videoMsg);

擴充類必須繼承PacketExtension

以下是段簡單的執行個體:

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();
}
}

擴充類型監聽方法:

ProviderManager.getInstance().addExtensionProvider(VideoChatRTP.NAME, VideoChatRTP.NAME_SPACE, new VideoChatReceive());

擴充類型處理類(實現PacketExtensionProvider介面):

public class VideoChatReceive implements PacketExtensionProvider {

/**
* 處理視頻擴充類型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));
//字串轉枚舉
videoRtp.setAddress(ipAddress);
return videoRtp;
}
}


Smack Message 擴充屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.