Skip to content

Commit

Permalink
Merge pull request #256 from dvonthenen/refactor-live-client-part3
Browse files Browse the repository at this point in the history
Implements Logging Strategy
  • Loading branch information
davidvonthenen authored Apr 2, 2024
2 parents c841605 + 63d2be5 commit 7607108
Show file tree
Hide file tree
Showing 69 changed files with 1,715 additions and 770 deletions.
6 changes: 5 additions & 1 deletion Deepgram.Microphone/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace Deepgram.Microphone;
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Microphone;

public static class Defaults
{
Expand Down
8 changes: 4 additions & 4 deletions Deepgram.Microphone/Library.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Microphone;

public class Library
{
public static void Initialize()
{
// TODO: logging
Console.WriteLine("Portaudio Version: {0}\n\n", PortAudio.VersionInfo.versionText);
PortAudio.Initialize();
}

public static void Terminate()
{
// TODO: logging
// Terminate PortAudio
PortAudio.Terminate();
}
Expand Down
12 changes: 0 additions & 12 deletions Deepgram.Microphone/Microphone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public bool Start()
_device_index = PortAudio.DefaultInputDevice;
if (_device_index == PortAudio.NoDevice)
{
// TODO: logging
Console.WriteLine("No default input device found");
return false;
}
}
Expand Down Expand Up @@ -100,15 +98,12 @@ private StreamCallbackResult _callback(nint input, nint output, uint frameCount,
// Check if the input is null
if (input == IntPtr.Zero)
{
// TODO: logging
Console.WriteLine("Input is null");
return StreamCallbackResult.Continue;
}

// Check if the exit token is set
if (_exitToken != null && _exitToken.IsCancellationRequested)
{
Console.WriteLine("Exiting!");
return StreamCallbackResult.Abort;
}

Expand All @@ -117,7 +112,6 @@ private StreamCallbackResult _callback(nint input, nint output, uint frameCount,

if (_isMuted)
{
Console.WriteLine("Muted!");
buf = new byte[buf.Length];
}
else
Expand All @@ -126,7 +120,6 @@ private StreamCallbackResult _callback(nint input, nint output, uint frameCount,
}

// Push the data to the callback
Console.WriteLine("Sending buffer!");
_push_callback(buf);

return StreamCallbackResult.Continue;
Expand All @@ -136,23 +129,19 @@ public void Mute()
{
if (_stream != null)
{
// TODO: logging
return;
}

// TODO: logging
_isMuted = true;
}

public void Unmute()
{
if (_stream != null)
{
// TODO: logging
return;
}

// TODO: logging
_isMuted = false;
}

Expand All @@ -161,7 +150,6 @@ public void Stop()
// Check if we have a stream
if (_stream == null)
{
// TODO: logging
return;
}

Expand Down
20 changes: 0 additions & 20 deletions Deepgram.Tests/LoggerExtension/LoggerExtensions.cs

This file was deleted.

28 changes: 14 additions & 14 deletions Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task AnalyzeUrl_Should_Call_PostAsync_Returning_SyncResponse()

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<UrlSource, AnalyzeSchema, SyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<UrlSource>())).DoNotCallBase();
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task AnalyzeUrl_Should_Throw_ArgumentException_If_CallBack_Not_Null

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>())).DoNotCallBase();
Expand All @@ -88,7 +88,7 @@ public async Task AnalyzeUrlCallBack_Should_Call_PostAsync_Returning_SyncRespons

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<UrlSource, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<UrlSource>())).DoNotCallBase();
Expand Down Expand Up @@ -122,7 +122,7 @@ public async Task AnalyzeUrlCallBack_Should_Call_PostAsync_Returning_SyncRespons

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<UrlSource, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<UrlSource>())).DoNotCallBase();
Expand Down Expand Up @@ -152,7 +152,7 @@ public async Task AnalyzeUrlCallBack_Should_Throw_ArgumentException_With_CallBac

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>())).DoNotCallBase();
Expand All @@ -178,7 +178,7 @@ public async Task AnalyzeUrlCallBack_Should_Throw_ArgumentException_With_No_Call

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<AnalyzeSchema, SyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>())).DoNotCallBase();
Expand All @@ -203,7 +203,7 @@ public async Task AnalyzeFile_With_Stream_Should_Call_PostAsync_Returning_SyncRe

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, SyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -234,7 +234,7 @@ public async Task AnalyzeFile_With_Bytes_Should_Call_PostAsync_Returning_SyncRes

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, SyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -264,7 +264,7 @@ public async Task AnalyzeFileCallBack_With_Stream_With_CallBack_Property_Should_

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -294,7 +294,7 @@ public async Task AnalyzeFileCallBack_With_Bytes_With_CallBack_Property_Should_C

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -325,7 +325,7 @@ public async Task AnalyzeFileCallBack_With_Stream_With_CallBack_Parameter_Should

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -359,7 +359,7 @@ public async Task AnalyzeFileCallBack_With_Bytes_With_CallBack_Parameter_Should_

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down Expand Up @@ -393,7 +393,7 @@ public async Task AnalyzeFileCallBack_With_Stream_Throw_ArgumentException_With_C

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand All @@ -419,7 +419,7 @@ public async Task AnalyzeFileCallBack_With_Bytes_Should_Throw_ArgumentException_

// Fake Clients
var httpClient = MockHttpClient.CreateHttpClientWithResult(expectedResponse);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options);
var analyzeClient = Substitute.For<AnalyzeClient>(_apiKey, _options, null);

// Mock methods
analyzeClient.When(x => x.PostAsync<Stream, AnalyzeSchema, AsyncResponse>(Arg.Any<string>(), Arg.Any<AnalyzeSchema>(), Arg.Any<Stream>())).DoNotCallBase();
Expand Down
2 changes: 1 addition & 1 deletion Deepgram.Tests/UnitTests/ClientTests/LiveClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// _options = new DeepgramWsClientOptions(_apiKey, null, null, true);

// _webSocketReceiveResult = new WebSocketReceiveResult(1, WebSocketMessageType.Text, true);
// _liveClient = new LiveClient(_apiKey, _options);
// _liveClient = new LiveClient(_apiKey, _options, null);
// }

// [TearDown]
Expand Down
Loading

0 comments on commit 7607108

Please sign in to comment.