Example #1
0
        /// <summary>
        /// Provides help with managing avatars.
        /// </summary>
        /// <param name="Client">XMPP Client</param>
        /// <param name="PepClient">Personal Eventing Protocol Client</param>
        /// <param name="E2E">End-to-End encryption</param>
        public AvatarClient(XmppClient Client, PepClient PepClient, IEndToEndEncryption E2E)
            : base(Client)
        {
            this.pep = PepClient;
            this.e2e = E2E;

            // XEP-0008: IQ-Based Avatars: http://xmpp.org/extensions/xep-0008.html
            Client.RegisterIqGetHandler("query", "jabber:iq:avatar", this.QueryAvatarHandler, false);

            Client.OnStateChanged      += Client_OnStateChanged;
            Client.OnPresence          += Client_OnPresence;
            Client.OnRosterItemRemoved += Client_OnRosterItemRemoved;
            Client.OnRosterItemAdded   += Client_OnRosterItemAdded;
            Client.CustomPresenceXml   += Client_CustomPresenceXml;

            if (this.pep != null)
            {
                this.pep.OnUserAvatarMetaData += Pep_OnUserAvatarMetaData;
            }

            byte[] Bin = Resources.LoadResource(typeof(AvatarClient).Namespace + ".Images.DefaultAvatar.png",
                                                typeof(AvatarClient).GetTypeInfo().Assembly);

            this.defaultAvatar = new Avatar(Client.BareJID.ToLower(), "image/png", Bin, 64, 64);

            Task.Run(() => this.LoadAvatar());
        }
Example #2
0
        /// <summary>
        /// Adds the extension to the client.
        /// </summary>
        /// <param name="Instance">Actor instance.</param>
        /// <param name="Client">XMPP Client</param>
        public override Task Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
        {
            PepClient Extension = new PepClient(Client);

            Client.SetTag("PEP", Extension);

            Extension.NonPepItemNotification += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "NonPepItemNotification",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.NonPepItemRetraction += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "NonPepItemRetraction",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.OnUserActivity += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnUserActivity",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.OnUserAvatarMetaData += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnUserAvatarMetaData",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.OnUserLocation += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnUserLocation",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.OnUserMood += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnUserMood",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            Extension.OnUserTune += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnUserTune",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            return(Task.CompletedTask);
        }
Example #3
0
 /// <summary>
 /// Provides help with managing avatars.
 /// </summary>
 /// <param name="Client">XMPP Client</param>
 /// <param name="PepClient">Personal Eventing Protocol Client</param>
 public AvatarClient(XmppClient Client, PepClient PepClient)
     : this(Client, PepClient, null)
 {
 }
        /// <summary>
        /// Executes a node.
        /// </summary>
        /// <param name="Variables">Set of variables for the activity.</param>
        /// <returns>Next node of execution, if different from the default, otherwise null (for default).</returns>
        public override Task <LinkedListNode <IActivityNode> > Execute(Variables Variables)
        {
            if (!Variables.TryGetVariable(this.sensor, out Variable v))
            {
                throw new Exception("Sensor not found: " + this.sensor);
            }

            if (!(v.ValueObject is SensorServer Sensor))
            {
                throw new Exception("Not a sensor server object: " + this.sensor);
            }

            Dictionary <ThingReference, LinkedList <Field> > FieldsByThing = new Dictionary <ThingReference, LinkedList <Field> >();
            ThingReference Ref;

            foreach (FieldNode Field in this.fields)
            {
                Ref = Field.ThingReference;
                if (!FieldsByThing.TryGetValue(Ref, out LinkedList <Field> Fields))
                {
                    Fields             = new LinkedList <Field>();
                    FieldsByThing[Ref] = Fields;
                }

                try
                {
                    Field.AddFields(Fields, Variables);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }

            foreach (KeyValuePair <ThingReference, LinkedList <Field> > P in FieldsByThing)
            {
                LinkedList <Field>     Fields = P.Value;
                LinkedListNode <Field> Loop   = Fields.First;
                LinkedListNode <Field> Next;
                bool Found = false;

                while (Loop != null)
                {
                    Next = Loop.Next;
                    if (Loop.Value.Type.HasFlag(Waher.Things.SensorData.FieldType.Momentary))
                    {
                        Found = true;
                    }
                    else
                    {
                        Fields.Remove(Loop);
                    }

                    Loop = Next;
                }

                if (Found)
                {
                    Sensor.NewMomentaryValues(P.Key, Fields);

                    if (Sensor.Client.TryGetExtension(typeof(PepClient), out IXmppExtension Extension) &&
                        Extension is PepClient PepClient)
                    {
                        PepClient.Publish(new SensorData(Fields), null, null);
                    }
                }
            }

            return(Task.FromResult <LinkedListNode <IActivityNode> >(null));
        }