Exemplo n.º 1
0
        public async Task <AuthorizeListenerResponse> Authorize(AuthorizeListenerRequest request)
        {
            var connectionId = Context.ConnectionId;
            var instance     = ListenerManager.GetInstance();

            var tokenManager = TokenManager.GetInstance();
            var roomId       = tokenManager.GetTokenInfo(request.Token);

            if (roomId == null)
            {
                return new AuthorizeListenerResponse()
                       {
                           IsSuccess = false
                       }
            }
            ;

            tokenManager.RemoveToken(request.Token);

            //// Broadcasterも立ち入り禁止になる...
            //using (var db = new ApplicationDbContext())
            //{
            //    var room = await db.Rooms.Where(c => c.Name == roomId).SingleOrDefaultAsync();
            //    if (room == null || !room.IsLive)
            //        return new AuthorizeListenerResponse()
            //        {
            //            IsSuccess = false
            //        };
            //}

            // OKならDBに登録(IsOpening=True)

            var result = await instance.RegisterListener(connectionId, roomId);

            if (result)
            {
                await this.Groups.Add(connectionId, roomId);

                return(new AuthorizeListenerResponse()
                {
                    IsSuccess = true
                });
            }
            else
            {
                return(new AuthorizeListenerResponse()
                {
                    IsSuccess = false
                });
            }
        }
Exemplo n.º 2
0
        public AppendSessionNotification GetSessionInfo(GetSessionRequest request)
        {
            var connectionId = Context.ConnectionId;
            var instance     = ListenerManager.GetInstance();

            if (instance.IsListener(connectionId))
            {
                var info         = instance.GetConnectionInfo(connectionId);
                var roomInstance = RoomManager.GetInstance();
                var room         = roomInstance.GetRoomInfo(info.RoomId);
                return(room?.GetSession(request.Id)?.GetSessionInfo() ?? null);
            }
            return(null);
        }
Exemplo n.º 3
0
        public UpdateCursorRequest GetSessionCursor(GetCursorRequest request)
        {
            var connectionId = Context.ConnectionId;
            var instance     = ListenerManager.GetInstance();

            if (instance.IsListener(connectionId))
            {
                var info         = instance.GetConnectionInfo(connectionId);
                var roomInstance = RoomManager.GetInstance();
                var room         = roomInstance.GetRoomInfo(info.RoomId);
                return(room?.GetSession(request.Id)?.GetCursor() ?? null);
            }
            return(null);
        }
Exemplo n.º 4
0
        public UpdateBroadcastStatusNotification GetRoomStatus()
        {
            var connectionId = Context.ConnectionId;
            var instance     = ListenerManager.GetInstance();

            if (instance.IsListener(connectionId))
            {
                var info         = instance.GetConnectionInfo(connectionId);
                var roomInstance = RoomManager.GetInstance();
                var room         = roomInstance.GetRoomInfo(info.RoomId);
                return(room?.GetRoomStatus() ?? null);
            }
            return(null);
        }
Exemplo n.º 5
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var connectionId = Context.ConnectionId;
            var instance     = ListenerManager.GetInstance();

            if (instance.IsListener(connectionId))
            {
                var result = instance.RemoveListener(connectionId);
                result.Wait();
                if (!result.IsCanceled && result.Result != null)
                {
                    try
                    {
                        this.Groups.Remove(connectionId, result.Result).Wait();
                    }
                    catch (Exception ex)
                    {
                        // Task Cancel Exception
                    }
                }
            }

            return(base.OnDisconnected(stopCalled));
        }