Skip to content

Commit

Permalink
Add a new thread for message sending due to web socket requirements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil authored Apr 10, 2023
1 parent b1b2cde commit 0e5ea44
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 129 deletions.
30 changes: 30 additions & 0 deletions c-sharp/MessageHandlers/MessageHandlerInitClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Paranext.DataProvider.Messages;

namespace Paranext.DataProvider.MessageHandlers;

/// <summary>
/// Handler for "Response" messages
/// </summary>
internal class MessageHandlerInitClient : IMessageHandler
{
Action<int> _clientIdCallback;

public MessageHandlerInitClient(Action<int> clientIdCallback)
{
_clientIdCallback = clientIdCallback;
}

public IEnumerable<Message> HandleMessage(Message message)
{
if (message == null)
throw new ArgumentNullException(nameof(message));

if (message.Type != MessageType.InitClient)
throw new ArgumentException("Incorrect message type", nameof(message));

var initClientMsg = (MessageInitClient)message;
int clientId = initClientMsg.ConnectorInfo.ClientId;
_clientIdCallback(clientId);
yield return new MessageClientConnect(clientId);
}
}
Loading

0 comments on commit 0e5ea44

Please sign in to comment.