Example #1
0
 public static void subscribeClient(KSPEvents ev, String client, String subEventID)
 {
     if (!subscribedSubEvents.ContainsKey(ev))
     {
         subscribedSubEvents.Add(ev, new Dictionary<String, List<String>>());
     }
     if (!subscribedSubEvents[ev].ContainsKey(client))
     {
         subscribedSubEvents[ev].Add(client, new List<String>());
     }
     subscribedSubEvents[ev][client].Add(subEventID);
     subscribeClient(ev, client);
 }
Example #2
0
        public static void unsubscribeClient(KSPEvents ev, String wsClient, String subEventID)
        {
            if (subscribedSubEvents.ContainsKey(ev))
            {
                if (subscribedSubEvents[ev].ContainsKey(wsClient))
                {
                    if (subscribedSubEvents[ev][wsClient].Contains(subEventID))
                    {
                        subscribedSubEvents[ev][wsClient].Remove(subEventID);
                    }

                    if (subscribedSubEvents[ev][wsClient].Count == 0)
                    {
                        unsubscribeClient(ev, wsClient);
                    }
                }
            }
        }
Example #3
0
        public static void dispatchEvent(WebSocketHandler ws, KSPEvents ev, String eventData, String subEventID)
        {
            if (!_cachedEvents.ContainsKey(ev)) _cachedEvents.Add(ev, new Dictionary<String, String>());

            if (!_cachedEvents[ev].ContainsKey(subEventID)) _cachedEvents[ev].Add(subEventID, eventData);
            else _cachedEvents[ev][subEventID] = eventData;

            getSubscribers(ev).ForEach((WSClient client) =>
            {
                if (subscribedSubEvents[ev].ContainsKey(client.ID))
                {
                    if (subscribedSubEvents[ev][client.ID].Contains(subEventID))
                    {
                        ws.SendTo(client.ID, eventData);
                    }
                }
            });
        }
Example #4
0
 public static String getLastEvent(KSPEvents ev, String subID)
 {
     KSPAlternateController.print("Test2");
     if (_cachedEvents.ContainsKey(ev))
     {
         if (_cachedEvents[ev].ContainsKey(subID))
         {
             KSPAlternateController.print("Test");
             return _cachedEvents[ev][subID];
         }
     }
     return "";
 }
Example #5
0
 public static void unsubscribeClient(KSPEvents ev, String wsClient)
 {
     if (subscribedEvents.ContainsKey(ev)) {
         subscribedEvents[ev].Remove(wsClient);
     }
 }
Example #6
0
 public static void subscribeClient(KSPEvents ev, String wsClient)
 {
     if (!subscribedEvents.ContainsKey(ev))
     {
         subscribedEvents[ev] = new List<String>();
     }
     subscribedEvents[ev].Add(wsClient);
 }
Example #7
0
        public static List<WSClient> getSubscribers(KSPEvents ev)
        {
            List<WSClient> clients = new List<WSClient>();
            if (subscribedEvents.ContainsKey(ev))
            {
                List<String> subscribers = subscribedEvents[ev];
                for (int i = 0; i < subscribers.Count; i++)
                {
                    WSClient client = WSClient.getClient(subscribers[i]);
                    if (client != null) { clients.Add(client); }
                    else
                    {
                        subscribedEvents[ev].Remove(subscribers[i]);
                    }
                }
            }

            return clients;
        }
Example #8
0
 public static String getLastEvent(KSPEvents ev)
 {
     KSPAlternateController.print("Test3");
     if (_cachedEvents.ContainsKey(ev))
     {
         KSPAlternateController.print("Test4");
         return _cachedEvents[ev];
     }
     return "";
 }
Example #9
0
        public static void dispatchEvent(WebSocketHandler ws, KSPEvents ev, String eventData)
        {
            if (!_cachedEvents.ContainsKey(ev)) _cachedEvents.Add(ev, eventData);
            else _cachedEvents[ev] = eventData;

            getSubscribers(ev).ForEach((WSClient client) => {
                ws.SendTo(client.ID, eventData);
            });
        }