Esempio n. 1
0
 protected override void OnMessage(MessageEventArgs e)
 {
     if (e.Data.Contains("subscribe"))
     {
         string substr             = e.Data.Substring(e.Data.IndexOf("\"name\":\"") + 8);
         WSCache.ClientConfig conf = new WSCache.ClientConfig();
         conf.name = substr.Substring(0, substr.IndexOf("\""));
         string camCnt = substr.Substring(substr.IndexOf("\"cameras\":") + 10);
         for (int i = 0; i < int.Parse(camCnt.Substring(0, camCnt.IndexOf("}"))); i++)
         {
             conf.cameras.Add(ID + "_" + (i + 1));
         }
         WSCache.Instance.clients.Add(ID, conf);
         Sessions.Broadcast(e.Data);
     }
     else if (e.Data.Contains("getCameras"))
     {
         Send(JsonConvert.SerializeObject(WSCache.Instance.clients));
     }
     else
     {
         foreach (string id in Sessions.ActiveIDs)
         {
             if (!id.Equals(ID))
             {
                 Sessions.SendTo(e.Data, id);
             }
         }
     }
     base.OnMessage(e);
 }
Esempio n. 2
0
        protected override void OnMessage(MessageEventArgs e)
        {
            if (e.Data.Contains("subscribe"))
            {
                string substr             = e.Data.Substring(e.Data.IndexOf("\"name\":\"") + 8);
                WSCache.ClientConfig conf = new WSCache.ClientConfig();
                conf.name = substr.Substring(0, substr.IndexOf("\""));
                string camCnt = substr.Substring(substr.IndexOf("\"cameras\":") + 10);
                for (int i = 0; i < int.Parse(camCnt.Substring(0, camCnt.IndexOf("}"))); i++)
                {
                    conf.cameras.Add(ID + "_" + (i + 1));
                }
                WSCache.Instance.clients.Add(ID, conf);
                Sessions.Broadcast(e.Data);
            }
            else if (e.Data.Contains("getCameras"))
            {
                Send(JsonConvert.SerializeObject(WSCache.Instance.clients));
            }
            else
            {
                var msg = e.Data == "BALUS"
                ? "I've been balused already..."
                : "I'm not available now.";

                Send(msg);
            }
            //else
            //{
            //    foreach (string id in Sessions.ActiveIDs)
            //    {
            //        if (!id.Equals(ID))
            //        {
            //            Sessions.SendTo(e.Data, id);
            //        }
            //    }
            //}
            base.OnMessage(e);
        }