示例#1
0
        public async Task <AuthorizeBroadcasterResponse> Authorize(AuthorizeBroadcasterRequest request)
        {
            var connectionId = Context.ConnectionId;
            var instance     = BroadcasterManager.GetInstance();

            using (var db = new ApplicationDbContext())
            {
                var accessUser = await db.AccessTokens
                                 .FirstOrDefaultAsync(c => c.AccessToken == request.AccessToken && c.User.UserName == request.UserName);

                var room = await db.Rooms
                           .FirstOrDefaultAsync(c => c.Name == request.RoomName && c.BroadcastToken == request.RoomToken);

                if (room == null || accessUser == null)
                {
                    return new AuthorizeBroadcasterResponse()
                           {
                               IsSuccess = false
                           }
                }
                ;

                await instance.RegisterBroadcaster(connectionId, room, accessUser.User);

                return(new AuthorizeBroadcasterResponse()
                {
                    IsSuccess = true
                });
            }
        }
示例#2
0
        //public async Task StartBroadcast()
        //{
        //    var connectionId = Context.ConnectionId;
        //    var instance = BroadcasterManager.GetInstance();
        //    if (!instance.IsBroadcaster(connectionId))
        //        return;

        //    var info = instance.GetConnectionInfo(connectionId);

        //    var roomManager = RoomManager.GetInstance();
        //    var room = roomManager.GetRoomInfo(info.RoomId);
        //    await room.NotifyStartBroadcast();
        //}

        //public async Task StopBroadcast()
        //{
        //    var connectionId = Context.ConnectionId;
        //    var instance = BroadcasterManager.GetInstance();
        //    if (!instance.IsBroadcaster(connectionId))
        //        return;

        //    var info = instance.GetConnectionInfo(connectionId);

        //    var roomManager = RoomManager.GetInstance();
        //    var room = roomManager.GetRoomInfo(info.RoomId);
        //    await room.NotifyStopBroadcast();
        //}

        #endregion

        #region "Session系"

        public async Task <AppendSessionResponse> AppendSession(AppendSessionRequest item)
        {
            var connectionId = Context.ConnectionId;
            var instance     = BroadcasterManager.GetInstance();

            if (!instance.IsBroadcaster(connectionId))
            {
                return new AppendSessionResponse()
                       {
                           IsSuccess = false
                       }
            }
            ;

            var info        = instance.GetConnectionInfo(connectionId);
            var roomManager = RoomManager.GetInstance();
            var room        = roomManager.GetRoomInfo(info.RoomId);
            var id          = Guid.NewGuid().ToString();

            await room.AppendSession(id, item, connectionId, info.Nickname);

            return(new AppendSessionResponse()
            {
                IsSuccess = true, Id = id
            });
        }
示例#3
0
        public override Task OnDisconnected(bool stopCalled)
        {
            var connectionId = Context.ConnectionId;
            var instance     = BroadcasterManager.GetInstance();

            if (instance.IsBroadcaster(connectionId))
            {
                instance.RemoveBroadcaster(connectionId).Wait();
            }

            return(base.OnDisconnected(stopCalled));
        }
示例#4
0
        public async Task UpdateSessionCursor(UpdateCursorRequest item)
        {
            var connectionId = Context.ConnectionId;
            var instance     = BroadcasterManager.GetInstance();

            if (!instance.IsBroadcaster(connectionId))
            {
                return;
            }

            var info        = instance.GetConnectionInfo(connectionId);
            var roomManager = RoomManager.GetInstance();
            var room        = roomManager.GetRoomInfo(info.RoomId);

            if (!room.IsOwnerSession(item.SessionId, connectionId))
            {
                return;
            }

            await room.UpdateSessionCursor(item);
        }