public void StartingAndStoppingServerWillTriggerEventMultipleTimes() { _voiceWrapper.Setup(e => e.StartNativeServer()).Returns(true); var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); var startInvokeAmount = 0; server.OnServerStarted += () => startInvokeAmount++; var stopInvokeAmount = 0; server.OnServerStopping += () => stopInvokeAmount++; for (var i = 0; i < 5; i++) { Assert.DoesNotThrow(() => { server.Start(); server.Stop(); }); } Assert.AreEqual(5, startInvokeAmount); Assert.AreEqual(5, stopInvokeAmount); }
public void ConstructorWillThrowExceptionsWhenAParameterIsNull() { Assert.Throws <ArgumentNullException>(() => { var server = new VoiceServer <IFakeVoiceClient, byte>(null, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123", 1, 1, 6), _voiceWrapper.Object); }); }
public void StartingVoiceServerMultipleWillTriggerEventOnlyIfServerIsNotStarted() { _voiceWrapper.Setup(e => e.StartNativeServer()).Returns(true); var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); var invokeAmount = 0; server.OnServerStarted += () => invokeAmount++; void ServerStart() { server.Start(); } for (var i = 0; i < 5; i++) { if (i == 0) { Assert.DoesNotThrow(ServerStart); } else { Assert.Throws <VoiceServerAlreadyStartedException>(ServerStart); } } Assert.AreEqual(1, invokeAmount); }
public Resource() { _server = new VoiceServer(1234, API); _server.OnTokenGenerated += _server_OnTokenGenerated; _server.OnVoicePlayerConnected += _server_OnVoicePlayerConnected; _server.OnVoicePlayerDisconnected += _server_OnVoicePlayerDisconnected; }
/// <summary> /// Updates the voice server and sends the data to the Lavalink Node if the voice state /// is also provided. /// </summary> /// <param name="voiceServer">the voice server data</param> /// <returns>a task that represents the asynchronous operation</returns> /// <exception cref="InvalidOperationException">thrown if the player is destroyed</exception> internal Task UpdateAsync(VoiceServer voiceServer) { EnsureNotDestroyed(); _voiceServer = voiceServer; return(UpdateAsync()); }
/// <inheritdoc/> /// <exception cref="ObjectDisposedException">thrown if the instance is disposed</exception> private Task OnVoiceServerUpdated(VoiceServerUpdateEventArgs voiceServer) { EnsureNotDisposed(); var args = new VoiceServer(voiceServer.Guild.Id, voiceServer.GetVoiceToken(), voiceServer.Endpoint); return(VoiceServerUpdated.InvokeAsync(this, args)); }
public void StartVoiceServer(int voicePort, string voiceServerPassword, string voiceAdminUser, string voiceAdminPassword, bool voiceRecordChannel, DateTime time, bool isReplay, double replaySpeed) { voiceServer = new VoiceServer(simModelFile, ref simCore.distributor, time, isReplay, replaySpeed); voiceServerThread = new Thread(new ThreadStart(voiceServer.StartVoiceServer)); voiceServerThread.Name = "DDD VoiceServer"; voiceServerThread.SetApartmentState(ApartmentState.MTA); voiceServerThread.Start(); }
public void StoppingServerWithoutStartingItFirstWillThrowAnException() { var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); Assert.Throws <VoiceServerNotStartedException>(() => { server.Stop(); }); }
public async Task <IHttpActionResult> Join(JoinChannelBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ChannelDataRepository repository = new ChannelDataRepository(); var channelModel = await repository.FindAsync(model.ChannelName); if (channelModel == null) { return(GetErrorResult(new IdentityResult("Channel not exists"))); } var channel = ChannelsInfo.GetChannelInfo(channelModel.Name); if (channel != null) { channel.Members.Add(model.User); return(Ok(Convert.ToInt32(channel.Port))); } int initPort = 5000; VoiceServer newVoiceServer = new VoiceServer(); while (initPort < 65000) { try { newVoiceServer.Start(initPort); ChannelsInfo.ListOfSockets.Add(initPort.ToString(), newVoiceServer); ChannelsInfo.AddChannel(channelModel, initPort.ToString()); ChannelsInfo.AddMember(channelModel.Name, model.User); break; } catch (Exception e) { ChannelsInfo.ListOfSockets.Remove(initPort.ToString()); initPort++; } } using (UserDataRepository db = new UserDataRepository()) { var user = db.FindByName(model.User); if (!user.RecenltyVisitedRooms.Split(',').Contains(model.ChannelName)) { db.UpdateVisitedChannels(model.User, model.ChannelName); } } return(Ok(initPort)); }
/// <summary> /// Asynchronously triggered when the player has connected to a voice channel. /// </summary> /// <param name="voiceServer">the voice server connected to</param> /// <param name="voiceState">the voice state</param> /// <returns>a task that represents the asynchronous operation</returns> public async override Task OnConnectedAsync(VoiceServer voiceServer, VoiceState voiceState) { // check if a volume has been stored if (_volumes.TryGetValue(GuildId, out var volume) && Volume != volume) { // here the volume is restored await SetVolumeAsync(volume); } await base.OnConnectedAsync(voiceServer, voiceState); }
public void ConstructorWithInvalidHostnameWillThrowInvalidHostnameException() { var invalidhostnames = new [] { "ä#äää", "" }; foreach (var invalidhostname in invalidhostnames) { Assert.Throws <ArgumentException>(() => { var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration(invalidhostname, 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); }); } }
public MyDataComunication CloseCommunication() { IsRecording = false; WaveIn.StopRecording(); WaveOut.Stop(); Capture.Stop(); ImageClient.CloseConnection(); ImageServer.CloseConnection(); VoiceClient.CloseConnection(); VoiceServer.CloseConnection(); return(this); }
public SimEngine() { simCore = new SimCore(); logPlayer = null; coordinator = null; simModelFile = null; serverPortNumber = null; replayLogger = null; textChatServer = null; whiteboardServer = null; voiceServer = null; //handshakeManager = null; viewManager = null; }
private void ReceiveAndPlaySound() { var bufferProvider = new BufferedWaveProvider(new WaveFormat(8000, 16, 1)); WaveOut = new WaveOut(); WaveOut.Init(bufferProvider); WaveOut.Play(); VoiceServer.AcceptClients((bytes) => { bufferProvider.AddSamples(bytes, 0, bytes.Length); }); Task.Run(async() => await VoiceServer.ProcessClientTask); }
public void StoppingVoiceServerWillSetStartedPropertyToFalseAndTriggerEvent() { _voiceWrapper.Setup(e => e.StartNativeServer()).Returns(true); var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); var invokeAmount = 0; server.OnServerStopping += () => invokeAmount++; server.Start(); server.Stop(); Assert.AreEqual(1, invokeAmount); Assert.AreEqual(false, server.Started); }
public void VoiceServerVariablesAreCorrectlySetOnConstruction() { var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("voice.domaindummy.com", 33567, "Identit3y7rrV3RYNiC3EEEEEwgeA=", 987, "verySecurePassword", 2f, 1f, 12d), _voiceWrapper.Object); var config = server.Configuration; Assert.AreEqual(config.Hostname, "voice.domaindummy.com"); Assert.AreEqual(config.Port, 33567); Assert.AreEqual(config.TeamspeakServerId, "Identit3y7rrV3RYNiC3EEEEEwgeA="); Assert.AreEqual(config.TeamspeakChannelId, 987); Assert.AreEqual(config.TeamspeakChannelPassword, "verySecurePassword"); Assert.AreEqual(config.GlobalRollOffScale, 2f); Assert.AreEqual(config.GlobalDistanceFactor, 1f); Assert.AreEqual(config.GlobalMaxDistance, 12d); }
public void RegisterEventWillCallRegisterEventAndAddsInstanceToGarbageCollection() { var invokeAmount = 0; var givenNumber = 0; void Callback(int e) { givenNumber = e; invokeAmount++; } var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"), _voiceWrapper.Object); server.RegisterEvent(Callback, 5); Assert.AreEqual(invokeAmount, 1); Assert.AreEqual(givenNumber, 5); }
public void StartingVoiceServerWillSetStartedPropertyToTrueAndTriggerEvent() { var configuration = new VoiceServerConfiguration("localhost", 23332, "Identit3y7rrV3RYNiC3MnupTwgeA=", 130, "123"); _voiceWrapper.Setup(e => e.StartNativeServer()).Returns(true); _voiceWrapper.Setup(e => e.CreateNativeServer(configuration)); var server = new VoiceServer <IFakeVoiceClient, byte>(_voiceClientFactory.Object, configuration, _voiceWrapper.Object); var invokeAmount = 0; server.OnServerStarted += () => invokeAmount++; server.Start(); _voiceWrapper.Verify(e => e.StartNativeServer(), Times.Once); _voiceWrapper.Verify(e => e.CreateNativeServer(configuration), Times.Once); Assert.AreEqual(1, invokeAmount); Assert.AreEqual(true, server.Started); }
/// <summary> /// Asynchronously triggered when the player has connected to a voice channel. /// </summary> /// <param name="voiceServer">the voice server connected to</param> /// <param name="voiceState">the voice state</param> /// <returns>a task that represents the asynchronous operation</returns> public virtual Task OnConnectedAsync(VoiceServer voiceServer, VoiceState voiceState) => Task.CompletedTask;
private Task OnVoiceServerUpdated(SocketVoiceServer voiceServer) { var args = new VoiceServer(voiceServer.Guild.Id, voiceServer.Token, voiceServer.Endpoint); return(VoiceServerUpdated.InvokeAsync(this, args)); }
/// <summary> /// Initializes a new instance of the <see cref="VoiceServerUpdateEvent"/> class. /// </summary> /// <param name="voiceServer">the voice server</param> public VoiceServerUpdateEvent(VoiceServer voiceServer) : this(voiceServer.Token, voiceServer.GuildId, voiceServer.Endpoint) { }
/// <inheritdoc/> /// <exception cref="ObjectDisposedException">thrown if the instance is disposed</exception> protected Task OnVoiceServerUpdated(DiscordClient _, VoiceServerUpdateEventArgs voiceServer) { var args = new VoiceServer(voiceServer.Guild.Id, voiceServer.GetVoiceToken(), voiceServer.Endpoint); return(VoiceServerUpdated.InvokeAsync(this, args)); }