对于会话恢复,我遵循xep-0198(XMPP框架中的流管理)。它只能工作300秒。如果用户未打开聊天应用程序超过300秒,即使我增加了超时间隔,连接也会自动丢失。
我对yml文件进行了以下操作:
listen:
-
port: 5222
module: ejabberd_c2s
resend_on_timeout: if_offline
stream_management: true
resume_timeout: 10000
max_resume_timeout: 10000
在代码中:( Swift)登录app
xmppStreamManagement = XMPPStreamManagement(storage: XMPPStreamManagementMemoryStorage(), dispatchQueue: DispatchQueue.main)
xmppStreamManagement?.autoResume = true
xmppStreamManagement?.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppStreamManagement?.activate(stream)
认证后:
xmppStreamManagement?.enable(withResumption: true, maxTimeout: 10000)
func canResumeStream() -> Bool{
return true
}
func xmppStreamManagement(_ sender: XMPPStreamManagement!, wasEnabled enabled: DDXMLElement!){
print("enabled")
}
func xmppStreamManagement(_ sender: XMPPStreamManagement!, wasNotEnabled failed: DDXMLElement!){
print("not enabled")
}
func supportsStreamManagement() -> Bool{
return true
}
我从服务器得到以下结果:
<enabled xmlns="urn:xmpp:sm:3" resume="true" max="10000" id="g2gCbQAAABY1NzQ5MzQwOTgwNjk2OTY4NTcxMjE4aANiAAAF0WIACjagYRg="/>
但是如果我让用户闲置超过5分钟,会话就会过期。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
您可以使用XMPPPingModule(XEP-0199:XMPP Ping)来保持会话的活跃。
示例:
let xmppPing = XMPPPing()
xmppPing?.respondsToQueries = true
xmppPing?.activate(stream)
let xmppAutoPing = XMPPAutoPing()
xmppAutoPing?.pingInterval = (yourTimeInterval) * 60
xmppAutoPing?.pingTimeout = pingTimeOutTime
xmppAutoPing?.activate(stream)