I'm using Microsoft.AspNetCore.SignalR.IHubClients
to obtain an IClientProxy
to call methods on connected clients.
The received messages are processed client-side using an implementation of the TryParseMessage
method on Microsoft.AspNetCore.SignalR.Protocol.IHubProtocol
interface.
I've adapted the default implementations of IHubProtocol
to include some additional processing of any headers sent with the message e.g. to flow relevant context from the hub to the connected clients.
public bool TryParseMessage(ref ReadOnlySequence<byte> input, IInvocationBinder binder, out HubMessage message)
{
if (!_innerProtocol.TryParseMessage(ref input, binder, out message))
{
return false;
}
if (message is HubInvocationMessage invocationMessage)
{
IDictionary<string, string> headers = invocationMessage.Headers;
// Do something with headers
}
return true;
}
I can't find any way to populate those message headers, however, when invoking client methods from the hub (at least not with IClientProxy
because IHubProtocol.WriteMessage
does not seem to be invoked by the library with that approach). Access to the headers hub-side seems to be quite private, so is there any way to solve this?