1.离线消息
openfire本身是支持离线消息的,不需要进行额外处理,可以用spark测试下
使用smack,其实他提供了相应的方法
Class OfflineMessageManager
可以看下描述
The
OfflineMessageManager helps manage offline messages even before the
user has sent an available presence. When a user asks for his offline
messages before sending an available presence then the server will not
send a flood with all the offline messages when the user becomes online.
The server will not send a flood with all the offline messages to the
session that made the offline messages request or to any other session
used by the user that becomes online.
英文退化了点,汗,大意就是,必须在发送在线信息之前去获取离线消息
刚开始没看这个,结果在上线之后,去取,结果。。。。离线消息数量总是为零,囧
首先,连接,状态要设为离线
- ConnectionConfiguration connConfig = new ConnectionConfiguration(serverDomain);
-
- connConfig.setSendPresence(false);
-
- connection = new XMPPConnection(connConfig);
- connection.connect();
然后,登陆
connection.login(userName, pwd);
接着,拿离线消息
- OfflineMessageManager offlineManager = new OfflineMessageManager(
- Client.getConnection());
- try {
- Iterator it = offlineManager
- .getMessages();
-
- System.out.println(offlineManager.supportsFlexibleRetrieval());
- System.out.println("离线消息数量: " + offlineManager.getMessageCount());
-
-
- Map> offlineMsgs = new HashMap>();
-
- while (it.hasNext()) {
- org.jivesoftware.smack.packet.Message message = it.next();
- System.out
- .println("收到离线消息, Received from 【" + message.getFrom()
- + "】 message: " + message.getBody());
- String fromUser = message.getFrom().split("/")[0];
-
- if(offlineMsgs.containsKey(fromUser))
- {
- offlineMsgs.get(fromUser).add(message);
- }else{
- ArrayList temp = new ArrayList();
- temp.add(message);
- offlineMsgs.put(fromUser, temp);
- }
- }
-
-
- Set keys = offlineMsgs.keySet();
- Iterator offIt = keys.iterator();
- while(offIt.hasNext())
- {
- String key = offIt.next();
- ArrayList ms = offlineMsgs.get(key);
- TelFrame tel = new TelFrame(key);
- ChatFrameThread cft = new ChatFrameThread(key, null);
- cft.setTel(tel);
- cft.start();
- for (int i = 0; i < ms.size(); i++) {
- tel.messageReceiveHandler(ms.get(i));
- }
- }
-
-
- offlineManager.deleteMessages();
- } catch (Exception e) {
- e.printStackTrace();
- }
记得最后要把离线消息删除,即通知服务器删除离线消息
offlineManager.deleteMessages();
否则,下次上了消息还存在
接着,上线
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
2.离线文件
这个我没实现,汗
主要思想:开发openfire插件,拦截离线文件,将文件存到服务器上,同时在数据库里开一张表,存储文件信息
当用户上线时,查表,若是有,根据路径,拿了发送
当然,大家可以谷歌下是否有相应的插件,时间紧迫,我倒是没找着
到这里,大概就这些了,对了,还扩展了个视频音频聊天,不过使用的是JMF,点对点的,本来打算使用jingle的,结果连API文档都没找到,晕死
阅读(5969) | 评论(0) | 转发(0) |