示例#1
0
        // Extend the timestamp for all messages from clients.
        public async void HandleMessage(MqttApplicationMessageInterceptorContext context)
        {
            Console.WriteLine("Broker: New message");

            //if(clientManagers[context.ClientId] == null)
            if (context.ClientId.EndsWith("_fake"))
            {
                return;
            }

            Console.WriteLine("### BROKER: RECEIVED APPLICATION MESSAGE ###");
            Console.WriteLine($"+ Topic = {context.ApplicationMessage.Topic}");
            Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(context.ApplicationMessage.Payload)}");
            Console.WriteLine($"+ QoS = {context.ApplicationMessage.QualityOfServiceLevel}");
            Console.WriteLine($"+ Retain = {context.ApplicationMessage.Retain}");
            Console.WriteLine();

            context.AcceptPublish = false;

            //If intercept on save msg
            if (clientManagers[context.ClientId].intercept)
            {
                MQTTProxyMessage tmp = new MQTTProxyMessage(context.ApplicationMessage, context.ClientId, MessageState.Intercepted);
                db.messageList.Add(tmp);
                wss.SendMessage(tmp);
            }
            //if intercept off forward
            else
            {
                ForwardMessage(context);
            }
        }
示例#2
0
 public void SendMessage(MQTTProxyMessage msg)
 {
     Console.WriteLine("Sending UI update");
     try {
         wss.WebSocketServices.Hosts.First().Sessions.Broadcast(JsonConvert.SerializeObject(msg));
     }catch (Exception e) {
         Console.WriteLine("No Websocket connected" + e);
     }
 }
示例#3
0
 /// <summary>
 /// For CopyMessage
 /// </summary>
 /// <param name="other"></param>
 public MQTTProxyMessage(MQTTProxyMessage other) : this()
 {
     this.ClientId = other.ClientId;
     //for deep copy
     this.Payload = new byte[other.Payload.Length];
     Array.Copy(other.Payload, this.Payload, this.Payload.Length);
     this.QoS       = other.QoS;
     this.RetainMsg = other.RetainMsg;
     this.Topic     = other.Topic;
 }