示例#1
0
        public async Task AppendSession(string id, AppendSessionRequest item, string connectionId, string nickName)
        {
            if (!this.Sessions.ContainsKey(id))
            {
                var session = new SessionManager()
                {
                    Id              = id,
                    ContentType     = item.ContentType,
                    FileName        = item.FileName,
                    BroadcasterId   = connectionId,
                    BroadcasterName = nickName
                };

                this.Sessions.Add(id, session);

                var manager      = ListenerManager.GetInstance();
                var notification = new AppendSessionNotification()
                {
                    Id              = id,
                    ContentType     = item.ContentType,
                    FileName        = item.FileName,
                    BroadcasterName = nickName
                };
                await Task.Run(() =>
                {
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <ListenHub>();
                    hubContext.Clients.Group(this.RoomId).AppendSession(notification);
                });
            }
        }
示例#2
0
        //public async Task SwitchActiveSession(SwitchActiveSessionNotification item)
        //{
        //    if (this.Sessions.ContainsKey(item.SessionId))
        //    {
        //        this.CurrentSession = this.Sessions[item.SessionId];

        //        var manager = ListenerManager.GetInstance();
        //        await Task.Run(() =>
        //        {
        //            Parallel.ForEach(this.Listeners, c =>
        //            {
        //                var listener = manager.GetConnectionInfo(c);
        //                if (listener != null)
        //                {
        //                    lock (listener)
        //                    {
        //                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<ListenHub>();
        //                        hubContext.Clients.Group(this.RoomId).SwitchActiveSession(item);
        //                    }
        //                }
        //            });
        //        });
        //    }
        //}
        #endregion

        public async Task UpdateSessionInfo(UpdateSessionInfoRequest item)
        {
            if (this.Sessions.ContainsKey(item.SessionId))
            {
                var session = this.Sessions[item.SessionId];
                session.ContentType = item.ContentType;
                session.FileName    = item.FileName;

                var notification = new AppendSessionNotification()
                {
                    Id              = item.SessionId,
                    ContentType     = item.ContentType,
                    FileName        = item.FileName,
                    BroadcasterName = session.BroadcasterName
                };

                var manager = ListenerManager.GetInstance();
                await Task.Run(() =>
                {
                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <ListenHub>();
                    hubContext.Clients.Group(this.RoomId).UpdateSessionInfo(notification);
                });
            }
        }