Ejemplo n.º 1
0
        public void Join(string space)
        {
            var principal = (ClaimsPrincipal)this.Context.User;
            var name = principal.Claims.Single(c => c.Type == "urn:github:name").Value;
            var avatar = principal.Claims.Single(c => c.Type == "urn:github:avatar_url").Value;

            Spaces[Context.ConnectionId] = space;
            this.Groups.Add(Context.ConnectionId, space);

            var e = new Event()
            {
                Type = "Exit",
                Name = name,
                Avatar = avatar,
                Message = "Join"
            };

            if (History.ContainsKey(space))
            {
                var list = History[space].ToArray();
                foreach (var ev in list)
                {
                    Clients.Caller.sendEvent(ev);
                }
            }

            Clients.Group(space).sendEvent(e);        
            SaveInHistory(space, e);
        }
Ejemplo n.º 2
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var principal = (ClaimsPrincipal)this.Context.User;
            var name = principal.Claims.Single(c => c.Type == "urn:github:name").Value;
            var avatar = principal.Claims.Single(c => c.Type == "urn:github:avatar_url").Value;

            var e = new Event()
            {
                Type = "Exit",
                Name = name,
                Avatar = avatar,
                Message = "Exit"
            };

            var space = string.Empty;
            Spaces.TryRemove(Context.ConnectionId, out space);
            Clients.Group(space).sendEvent(e);
            SaveInHistory(space, e);
            return base.OnDisconnected(stopCalled);
        }
Ejemplo n.º 3
0
        public void SaveInHistory(string space, Event e)
        {
            if (!History.ContainsKey(space))
            {
                History[space] = new ConcurrentQueue<Event>();
            }

            var queue = History[space];
            queue.Enqueue(e);
            if (queue.Count > 20)
            {
                Event ev;
                queue.TryDequeue(out ev);
            }
        }
Ejemplo n.º 4
0
        public void Send(string message)
        {
            var principal = (ClaimsPrincipal)this.Context.User;
            var name = principal.Claims.Single(c => c.Type == "urn:github:name").Value;
            var avatar = principal.Claims.Single(c => c.Type == "urn:github:avatar_url").Value;

            var e = new Event()
            {
                Type = "Message",
                Name = name,
                Avatar = avatar,
                Message = message
            };

            var space = Spaces[Context.ConnectionId];
            Clients.Group(space).sendEvent(e);

            SaveInHistory(space, e);
        }