コード例 #1
0
		private void IQLost(object sender, TimeoutEventArgs e)
		{
			var iq = (IQ)e.Data;
			var session = sessionManager.GetSession(iq.From);
            if (session != null)
            {
                // iChat bug
                if (iq.Id == null || iq.Id.IndexOf("ichat", StringComparison.OrdinalIgnoreCase) < 0)
                {
                    xmppSender.SendTo(session, XmppStanzaError.ToServiceUnavailable(iq));
                }
                else
                {
                    xmppSender.SendTo(session, ToResult(iq));
                }
            }
		}
コード例 #2
0
        private void IdleTimeout(object sndr, TimeoutEventArgs e)
        {
            try
            {
                if (!Id.Equals(e.IdleObject)) return;

                _log.DebugFormat("Close jabber-signalr connection {0} by inactivity timeout.", Id);

                var xmppStream = _xmppServer.StreamManager.GetStream(Id);
                if (xmppStream == null)
                {
                    _log.DebugFormat("Stream already was closed", Id);
                    return;
                }
                var jid = new Jid(xmppStream.User, xmppStream.Domain, SignalRHelper.SIGNALR_RESOURCE);
                _xmppServer.SessionManager.CloseSession(jid);
                _xmppServer.StreamManager.RemoveStream(Id);
                Close();
                var jidSessions = _xmppServer.SessionManager.GetBareJidSessions(jid);
                var sender = (IXmppSender)_xmppServer.GetService(typeof(IXmppSender));
                var presence = new Presence
                {
                    Priority = SignalRHelper.PRIORITY,
                    From = jid,
                    Type = PresenceType.unavailable
                };
                sender.Broadcast(_xmppServer.SessionManager.GetSessions(), presence);
                if (jidSessions.Count > 0)
                {
                    var bestSessions = jidSessions.Where(s => !s.IsSignalRFake).OrderByDescending(s => s.Presence.Priority).ToArray();
                    if (bestSessions.Length > 0 && bestSessions[0].Presence != null)
                    {
                        var bestSession = bestSessions[0];
                        try
                        {
                            signalrServiceClient.SendState(bestSession.Jid.User.ToLowerInvariant(),
                                SignalRHelper.GetState(bestSession.Presence.Show, bestSession.Presence.Type), -1, bestSession.Jid.Server);
                        }
                        catch (Exception ex)
                        {
                            _log.ErrorFormat("Unexpected error, connectionId = {0}, {1}, {2}, {3}", Id,
                                ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : string.Empty);
                        }
                    }
                    else
                    {
                        _log.ErrorFormat("XMPP session Presence is null. Connection {0}", Id);
                    }
                }
                else
                {
                    try
                    {
                        signalrServiceClient.SendState(jid.User.ToLowerInvariant(), SignalRHelper.USER_OFFLINE, -1, jid.Server);
                    }
                    catch (Exception ex)
                    {
                        _log.ErrorFormat("Unexpected error, connectionId = {0}, {1}, {2}, {3}", Id,
                            ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : string.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Unexpected error: {0}", ex);
            }
        }
コード例 #3
0
        private void IdleTimeout(object sender, TimeoutEventArgs e)
        {
            if (!Id.Equals(e.IdleObject)) return;

            log.DebugFormat("Close connection {0} by inactivity timeout.", Id);
            Close();
        }
コード例 #4
0
		private void IQLost(object sender, TimeoutEventArgs e)
		{
			var iq = (IQ)e.Data;
			var session = sessionManager.GetSession(iq.From);
			if (session != null) xmppSender.SendTo(session, XmppStanzaError.ToServiceUnavailable(iq));
		}