/// <summary> /// 用户出席通知 /// </summary> /// <param name="client"></param> /// <param name="presence"></param> private static void Client_OnPresence(Client client, XmppPresence presence) { Settings settings = Factory.GetSettings("host.json"); var doctorPresentSwitch = settings["DoctorPresentSwitch"]; if (bool.TryParse(doctorPresentSwitch, out bool doctorPresentSwitchRes)) { if (!doctorPresentSwitchRes) { return; } } var userGuid = presence.Sender; var isOnline = presence.Online; Logger.Debug($"用户出席通知{userGuid}({presence.Resource})-{isOnline.ToString()}"); #region 检测出席用户是否是医生 var checkDoctorList = RedisHelper.Get <string>("CloudDoctor:DoctorList"); if (checkDoctorList != null) { var doctorGuids = JsonConvert.DeserializeObject <List <string> >(checkDoctorList); if (!doctorGuids.Contains(userGuid)) { return; } } #endregion new UserPresenceBiz().SetPresenceStatus(userGuid, isOnline); var result = new UserPresenceBiz().GetPresenceStatus(userGuid); if (!result.IsOnline && result.LatestOnlineTime != null) { var model = new OnLineModel() { OnlineGuid = Guid.NewGuid().ToString("N"), DoctorGuid = userGuid, LoginTime = result.LatestOnlineTime.Value, LogoutTime = DateTime.Now, CreatedBy = userGuid, LastUpdatedBy = userGuid, OrgGuid = "" }; model.Duration = (decimal)Math.Round((model.LogoutTime - model.LoginTime).TotalMinutes, 2); var onlineResult = new HospitalManagerBiz().CreateDoctorOnlineRecord(model); if (string.IsNullOrEmpty(onlineResult)) { Logger.Warn($"添加医生“{userGuid}”在线时长记录失败"); } } }
protected override void OnPresenceChanged(XmppPresence Presence) { if (Presence.Status == PresenceStatus.Online || Presence.Status == PresenceStatus.Chat) { this.SubscribeData(-1, ReadoutType.MomentaryValues, new FieldCondition[] { FieldCondition.IfChanged("Temperature", 0.5), FieldCondition.IfChanged("Light", 1), FieldCondition.IfChanged("Motion", 1) }, null, null, new Duration(0, 0, 0, 0, 1, 0), true, this.NewSensorData, null); } }
protected override void OnPresenceChanged(XmppPresence Presence) { if (Presence.Status == PresenceStatus.Online || Presence.Status == PresenceStatus.Chat) { this.SubscribeData(-2, ReadoutType.Identity, new FieldCondition[] { FieldCondition.Report("URL"), FieldCondition.IfChanged("Width", 1), FieldCondition.IfChanged("Height", 1) }, null, null, new Duration(0, 0, 0, 0, 1, 0), true, this.NewCameraData, null); } }
private void doParseStream(string stream) { XmppIQ xStream; try { xStream = XmppIQ.Parse(stream); } catch (Exception) { //MessageBox.Show("Invalid stream :(\n\n" + stream); return; } switch (xStream.Name) { #region PRESENCE case "presence": { XmppPresence presence = new XmppPresence(); string type = xStream.GetAttribute("type"); presence.From = new XmppJid(xStream.GetAttribute("from")); presence.To = new XmppJid(xStream.GetAttribute("to")); // # type == "" if (string.IsNullOrEmpty(type)) { XmppIQ xStatus = xStream.FindDescendant("status"); if (xStatus != null) { presence.MessageStatus = xStatus.Text; } XmppIQ xShow = xStream.FindDescendant("show"); presence.Status = xShow != null?XmppIq.StrToPresence(xShow.Text) : XmppPresenceStatus.Online; XmppIQ xCard = xStream.FindDescendant("x", "vcard-temp:x:update"); if (xCard != null) { XmppIQ xPhoto = xCard.FindDescendant("photo", "vcard-temp:x:update"); if (xPhoto != null) { presence.PhotoHash = xPhoto.Text; } } if (Presence != null) { Presence(this, new XmppPresenceEventArgs(presence)); } } // # type == "unavailable" else if (type == "unavailable") { presence.Status = XmppPresenceStatus.Unavailable; if (Presence != null) { Presence(this, new XmppPresenceEventArgs(presence)); } } // # type == "probe" // probe request from server else if (type == "probe") { SetPresence(statePresence, string.Empty, null); } // # type == "subscribe" // new subscription request else if (type == "subscribe") { if (SubscribeRequest != null) { SubscribeRequest(this, new XmppSubscribeRequestEventArgs(presence.From)); } } // # type == "error" // presence stanza error else if (type == "error") { // @@@ } } break; #endregion #region MESSAGE case "message": { XmppMessage message = new XmppMessage(); message.Type = xStream.GetAttribute("type"); message.From = new XmppJid(xStream.GetAttribute("from")); message.To = new XmppJid(xStream.GetAttribute("to")); Int32.TryParse(xStream.GetAttribute("id"), out message.ID); if (message.Type != "error") { // # user composing new message if (xStream.FindDescendant("composing", "http://jabber.org/protocol/chatstates") != null) { if (ChatNotify != null) { ChatNotify(this, new XmppChatNotifyEventArgs(message.From, string.Empty, XmppChatStatus.NowComposing)); } } // # user stop composing else if (xStream.FindDescendant("paused", "http://jabber.org/protocol/chatstates") != null) { if (ChatNotify != null) { ChatNotify(this, new XmppChatNotifyEventArgs(message.From, string.Empty, XmppChatStatus.StopComposing)); } } // # user is inactive else if (xStream.FindDescendant("inactive", "http://jabber.org/protocol/chatstates") != null) { if (ChatNotify != null) { ChatNotify(this, new XmppChatNotifyEventArgs(message.From, string.Empty, XmppChatStatus.Inactive)); } } // # user has left conversation else if (xStream.FindDescendant("gone", "http://jabber.org/protocol/chatstates") != null) { if (ChatNotify != null) { ChatNotify(this, new XmppChatNotifyEventArgs(message.From, string.Empty, XmppChatStatus.Gone)); } } // # user is active ;) else if (xStream.FindDescendant("active", "http://jabber.org/protocol/chatstates") != null) { if (ChatNotify != null) { ChatNotify(this, new XmppChatNotifyEventArgs(message.From, string.Empty, XmppChatStatus.Active)); } } // # check for new message XmppIQ xBody = xStream.FindDescendant("body"); if (xBody != null) { message.Body = xBody.Text; XmppIQ xThread = xStream.FindDescendant("thread"); if (xThread != null) { message.Thread = xThread.Text; } XmppIQ xSubject = xStream.FindDescendant("subject"); if (xSubject != null) { message.Subject = xSubject.Text; } if (Message != null) { Message(this, new XmppMessageEventArgs(message)); } } } } break; #endregion #region IQ case "iq": { XmppIQ xQuery = null; string type = xStream.GetAttribute("type"); // Roster xQuery = xStream.FindDescendant("query", "jabber:iq:roster"); if (xQuery != null) { List <XmppRosterItem> roster = new List <XmppRosterItem>(); foreach (XmppIQ xItem in xQuery.Children()) { if (xItem.Name != "item") { continue; } string jid = xItem.GetAttribute("jid"); string sub = xItem.GetAttribute("subscription"); string ask = xItem.GetAttribute("ask"); string name = xItem.GetAttribute("name"); string group = xItem.GetAttribute("group"); roster.Add(new XmppRosterItem(jid, sub, name, group, ask)); } if (Roster != null) { Roster(this, new XmppRosterEventArgs(roster, XmppIq.StrToType(type))); } } // Disco xQuery = xStream.FindDescendant("query", "http://jabber.org/protocol/disco#info"); if (xQuery != null) { if (type == "get") { XmppJid from = new XmppJid(xStream.GetAttribute("from")); string id = xStream.GetAttribute("id"); sendStream(new XmppIq().ToStream(Jid, from, XmppIqType.Result, id, Disco.ToStreamResult())); // @@@@@ ottimizza SendIq(...) //SendIq(from, XmppIqType.Result, Disco.ToStreamResult());// @@@@@ ottimizza SendIq(...) } } // vCard xQuery = xStream.FindDescendant("vCard", "vcard-temp"); if (xQuery != null) { if (type == "result") { XmppJid from = new XmppJid(xStream.GetAttribute("from")); XmppVCard vCard = new XmppVCard(from, xQuery); if (VCard != null) { VCard(this, new XmppVCartEventArgs(vCard)); } } } // Ping xQuery = xStream.FindDescendant("ping", "urn:xmpp:ping"); if (xQuery != null) { if (type == "get") { XmppJid from = new XmppJid(xStream.GetAttribute("from")); string id = xStream.GetAttribute("id"); sendStream(new XmppIq().ToStream(Jid, from, XmppIqType.Result, id, string.Empty)); // @@@@@ ottimizza SendIq(...) } } } break; #endregion } Signal(xStream); }
public void UpdatePresence(XmppPresence presence) { Presence = presence; PresenceUpdated = DateTime.Now; RefreshPresence(); }