public void SendAudioDataMessageUserMuted()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2, 1, true));

            var s = GetSourceFromRequest(c, cl);

            var result = client.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, result.SourceResult);
            client.AssertNoMessage();

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (c,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = s.Id,
                TargetType = TargetType.Channel,
                TargetIds  = new [] { 1 }
            }));

            cl.AssertNoMessage();
            client.AssertNoMessage();
        }
        public void ClientAudioSourceStateChangedDifferentChannel()
        {
            var u = UserInfoTests.GetTestUser(2, 2, false);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, u);

            var s = manager.Create("Name", u, new AudioCodecArgs());

            handler.ClientAudioSourceStateChangeMessage(new MessageEventArgs <ClientAudioSourceStateChangeMessage> (c,
                                                                                                                    new ClientAudioSourceStateChangeMessage {
                SourceId = s.Id, Starting = true
            }));

            cl.AssertNoMessage();

            var change = client.DequeueAndAssertMessage <AudioSourceStateChangeMessage>();

            Assert.AreEqual(s.Id, change.SourceId);
            Assert.AreEqual(true, change.Starting);
        }
        public void SendAudioDataMessageToUser()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            var u = UserInfoTests.GetTestUser(2, 2, false);

            userManager.Join(c, u);

            var s      = GetSourceFromRequest();
            var result = cl.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, result.SourceResult);
            cl.AssertNoMessage();

            permissions.EnablePermissions(user.UserId, PermissionName.SendAudio);

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = s.Id,
                TargetType = TargetType.User,
                TargetIds  = new [] { u.UserId }
            }));

            client.AssertNoMessage();
            Assert.AreEqual(s.Id, cl.DequeueAndAssertMessage <ServerAudioDataMessage>().SourceId);
        }
        public void RequestSourceListFromViewer()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.RequestSource);
            var audioArgs = AudioCodecArgsTests.GetTestArgs();

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server,
                                                                                      new RequestSourceMessage("Name", audioArgs)));

            var result = client.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result.SourceResult);

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server,
                                                                                      new RequestSourceMessage("Name2", audioArgs)));

            var result2 = client.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result2.SourceResult);
            client.AssertNoMessage();

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2));

            handler.RequestSourceListMessage(new MessageEventArgs <RequestSourceListMessage> (c, new RequestSourceListMessage()));
            var list = cl.DequeueAndAssertMessage <SourceListMessage>();

            Assert.AreEqual(2, list.Sources.Count());
            Assert.Contains(result.Source, list.Sources.ToList());
            Assert.Contains(result2.Source, list.Sources.ToList());
            cl.AssertNoMessage();
        }
        public void SendAudioDataMessageToCurrentChannelWithoutPermission()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2, 1, false));

            var s      = GetSourceFromRequest();
            var result = cl.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, result.SourceResult);
            cl.AssertNoMessage();

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = s.Id,
                TargetType = TargetType.Channel,
                TargetIds  = new [] { user.CurrentChannelId }
            }));

            cl.AssertNoMessage();
            Assert.AreEqual(GablarskiMessageType.ClientAudioData, client.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage);
        }
示例#6
0
        public void Setup()
        {
            manager     = new ServerUserManager();
            permissions = new MockPermissionsProvider();
            channels    = new LobbyChannelProvider();

            MockServerContext mcontext;

            context = mcontext = new MockServerContext
            {
                ChannelsProvider    = channels,
                PermissionsProvider = permissions,
                UserManager         = new ServerUserManager(),
                Settings            = new ServerSettings {
                    Name = "Test Server"
                }
            };

            mcontext.Users    = new ServerUserHandler(context, manager);
            mcontext.Channels = handler = new ServerChannelHandler(context);

            user = UserInfoTests.GetTestUser(1, 1, false);

            provider = new MockConnectionProvider(GablarskiProtocol.Instance);
            mcontext.AddConnectionProvider(provider);
            mcontext.Start();

            var connections = provider.GetConnections(GablarskiProtocol.Instance);

            client = new ConnectionBuffer(connections.Item1);
            server = connections.Item2;

            manager.Connect(server);
            manager.Join(server, user);
        }
示例#7
0
        public void UserUpdatedMessage()
        {
            var msg = new UserUpdatedMessage(UserInfoTests.GetTestUser());

            UserInfoTests.AssertUserInfosMatch(UserInfoTests.GetTestUser(), msg.User);

            msg = msg.AssertLengthMatches();
            UserInfoTests.AssertUserInfosMatch(UserInfoTests.GetTestUser(), msg.User);
        }
示例#8
0
        public void InvalidBeginCapture()
        {
            var engine = new AudioEngine();

            engine.Attach(this.provider, this.source, new AudioEngineCaptureOptions());
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(null, new ChannelInfo(1)));
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(this.source, (ChannelInfo)null));
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(this.source, (IEnumerable <IChannelInfo>)null));
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(null, UserInfoTests.GetTestUser()));
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(this.source, (IUserInfo)null));
            Assert.Throws <ArgumentNullException> (() => engine.BeginCapture(this.source, (IEnumerable <IUserInfo>)null));
        }
示例#9
0
        public void UserLoggedIn()
        {
            var msg = new UserJoinedMessage(UserInfoTests.GetTestUser());

            msg.WritePayload(serverContext, writer);
            long length = stream.Position;

            stream.Position = 0;

            msg = new UserJoinedMessage();
            msg.ReadPayload(clientContext, reader);
            Assert.AreEqual(length, stream.Position);
            UserInfoTests.AssertUserInfosMatch(UserInfoTests.GetTestUser(), msg.UserInfo);
        }
示例#10
0
        public void Setup()
        {
            permissions = new MockPermissionsProvider();

            LobbyChannelProvider channels = new LobbyChannelProvider();

            channels.SaveChannel(new ChannelInfo
            {
                Name = "Channel 2"
            });

            this.provider = new MockConnectionProvider(GablarskiProtocol.Instance);
            this.provider.Start(MessageTypes.All);

            userManager = new ServerUserManager();
            MockServerContext c;

            context = c = new MockServerContext(provider)
            {
                Settings = new ServerSettings
                {
                    Name = "Server",
                    DefaultAudioBitrate = defaultBitrate,
                    MaximumAudioBitrate = maxBitrate,
                    MinimumAudioBitrate = minBitrate
                },

                UserManager         = userManager,
                PermissionsProvider = permissions,
                ChannelsProvider    = channels
            };
            c.Users = new ServerUserHandler(context, userManager);

            manager = new ServerSourceManager(context);
            handler = new ServerSourceHandler(context, manager);

            user = UserInfoTests.GetTestUser(1, 1, false);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);

            client = new ConnectionBuffer(cs.Item1);
            server = cs.Item2;

            userManager.Connect(server);
            userManager.Join(server, user);
        }
示例#11
0
        public void SetPermissionsNotConnected()
        {
            permissions.UpdatedSupported = true;

            var u = UserInfoTests.GetTestUser();

            permissions.EnablePermissions(u.UserId, PermissionName.ModifyPermissions);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = new ConnectionBuffer(cs.Item1);

            cs.Item2.DisconnectAsync().Wait();

            handler.OnSetPermissionsMessage(new MessageEventArgs <SetPermissionsMessage> (c,
                                                                                          new SetPermissionsMessage(u, new Permission[0])));

            c.AssertNoMessage();
        }
示例#12
0
        public void SendAudioDataMessageUnknownSource()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2, 1, false));

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = 1,
                TargetType = TargetType.Channel,
                TargetIds  = new [] { 1 }
            }));

            cl.AssertNoMessage();
            client.AssertNoMessage();
        }
示例#13
0
        public void ClientAudioSourceStateChangedUserMuted()
        {
            var u = UserInfoTests.GetTestUser(2, 1, true);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, u);

            var s = manager.Create("Name", u, new AudioCodecArgs());

            handler.ClientAudioSourceStateChangeMessage(new MessageEventArgs <ClientAudioSourceStateChangeMessage> (c,
                                                                                                                    new ClientAudioSourceStateChangeMessage {
                SourceId = s.Id, Starting = true
            }));

            client.AssertNoMessage();
            cl.AssertNoMessage();
        }
示例#14
0
        public void SendAudioDataMessageToMultipleUsersWithoutPermission()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            var u1 = UserInfoTests.GetTestUser(2, 1, false);

            userManager.Join(c, u1);

            var cs2 = provider.GetConnections(GablarskiProtocol.Instance);
            var c2  = cs2.Item2;
            var cl2 = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c2);
            var u2 = UserInfoTests.GetTestUser(3, 1, false);

            userManager.Join(c2, u2);

            var s      = GetSourceFromRequest();
            var result = cl.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, result.SourceResult);
            cl.AssertNoMessage();

            permissions.EnablePermissions(user.UserId, PermissionName.SendAudio);

            handler.OnClientAudioDataMessage(new MessageEventArgs <ClientAudioDataMessage> (server,
                                                                                            new ClientAudioDataMessage
            {
                Data       = new [] { new byte[512] },
                SourceId   = s.Id,
                TargetType = TargetType.User,
                TargetIds  = new [] { u1.UserId, u2.UserId }
            }));

            cl.AssertNoMessage();
            Assert.AreEqual(GablarskiMessageType.ClientAudioData, client.DequeueAndAssertMessage <PermissionDeniedMessage>().DeniedMessage);
        }
示例#15
0
        public void JoinChannelAtLimit()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.ChangeChannel);

            Assert.AreEqual(ChannelEditResult.Success, channels.SaveChannel(new ChannelInfo {
                Name = "Channel 2", UserLimit = 1
            }));
            client.DequeueAndAssertMessage <ChannelListMessage>();

            var channel = channels.GetChannels().Single(c => c.Name == "Channel 2");

            context.Users.Move(user, channel);

            var moved = client.DequeueAndAssertMessage <UserChangedChannelMessage>();

            Assert.AreEqual(user.UserId, moved.ChangeInfo.TargetUserId);
            Assert.AreEqual(channel.ChannelId, moved.ChangeInfo.TargetChannelId);
            Assert.AreEqual(channels.DefaultChannel.ChannelId, moved.ChangeInfo.PreviousChannelId);
            Assert.AreEqual(0, moved.ChangeInfo.RequestingUserId);

            var secondUser = UserInfoTests.GetTestUser(2, 1, false);

            var cs           = provider.GetConnections(GablarskiProtocol.Instance);
            var secondClient = new ConnectionBuffer(cs.Item1);

            var secondServer = cs.Item2;

            manager.Connect(secondServer);
            manager.Join(secondServer, secondUser);
            permissions.EnablePermissions(secondUser.UserId, PermissionName.ChangeChannel);

            context.Users.Move(secondServer, secondUser, channel);

            client.AssertNoMessage();

            var result = secondClient.DequeueAndAssertMessage <ChannelChangeResultMessage>();

            Assert.AreEqual(ChannelChangeResult.FailedFull, result.Result);
        }
示例#16
0
        public void RequestMuteWithoutPermission()
        {
            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2));

            var source = GetSourceFromRequest();

            Assert.AreEqual(SourceResult.NewSource, cl.DequeueAndAssertMessage <SourceResultMessage>().SourceResult);
            cl.AssertNoMessage();

            handler.RequestMuteSourceMessage(new MessageEventArgs <RequestMuteSourceMessage> (c,
                                                                                              new RequestMuteSourceMessage(source, true)));

            var denied = cl.DequeueAndAssertMessage <PermissionDeniedMessage>();

            Assert.AreEqual(GablarskiMessageType.RequestMuteSource, denied.DeniedMessage);
            cl.AssertNoMessage();
        }
示例#17
0
        public void UserList()
        {
            List <IUserInfo> users = new List <IUserInfo>
            {
                UserInfoTests.GetTestUser(1),
                UserInfoTests.GetTestUser(2)
            };

            var msg = new UserInfoListMessage(users);

            Assert.AreEqual(1, msg.Users.Count(ui => ui.UserId.Equals(users[0].UserId) && ui.CurrentChannelId.Equals(users[0].CurrentChannelId) && ui.Nickname == users[0].Nickname && ui.IsMuted == users[0].IsMuted));
            Assert.AreEqual(1, msg.Users.Count(ui => ui.UserId.Equals(users[1].UserId) && ui.CurrentChannelId.Equals(users[1].CurrentChannelId) && ui.Nickname == users[1].Nickname && ui.IsMuted == users[1].IsMuted));
            msg.WritePayload(serverContext, writer);
            long length = stream.Position;

            stream.Position = 0;

            msg = new UserInfoListMessage();
            msg.ReadPayload(clientContext, reader);
            Assert.AreEqual(length, stream.Position);
            Assert.AreEqual(1, msg.Users.Count(ui => ui.UserId.Equals(users[0].UserId) && ui.CurrentChannelId.Equals(users[0].CurrentChannelId) && ui.Nickname == users[0].Nickname && ui.IsMuted == users[0].IsMuted));
            Assert.AreEqual(1, msg.Users.Count(ui => ui.UserId.Equals(users[1].UserId) && ui.CurrentChannelId.Equals(users[1].CurrentChannelId) && ui.Nickname == users[1].Nickname && ui.IsMuted == users[1].IsMuted));
        }
示例#18
0
        public void RequestSourceNotification()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.RequestSource);

            var cs = provider.GetConnections(GablarskiProtocol.Instance);
            var c  = cs.Item2;
            var cl = new ConnectionBuffer(cs.Item1);

            userManager.Connect(c);
            userManager.Join(c, UserInfoTests.GetTestUser(2));

            var audioArgs = AudioCodecArgsTests.GetTestArgs();

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server,
                                                                                      new RequestSourceMessage("Name", audioArgs)));

            var sourceAdded = cl.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.NewSource, sourceAdded.SourceResult);
            Assert.AreEqual("Name", sourceAdded.SourceName);
            AudioCodecArgsTests.AssertAreEqual(audioArgs, sourceAdded.Source.CodecSettings);

            cl.AssertNoMessage();
        }