Update bidirectional chat sample for isolated worker
Update bidirectional chat sample for isolated worker
This commit is contained in:
Коммит
c440114dc8
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
|
||||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.2.2" />
|
||||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
|
||||
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.5.2" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32126.317
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetIsolated-BidirectionChat", "DotnetIsolated-BidirectionChat.csproj", "{48A53B73-9F2C-446A-A67F-04BB68453B66}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{48A53B73-9F2C-446A-A67F-04BB68453B66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48A53B73-9F2C-446A-A67F-04BB68453B66}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48A53B73-9F2C-446A-A67F-04BB68453B66}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48A53B73-9F2C-446A-A67F-04BB68453B66}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {17F67B90-252B-49A0-AEAB-FBB32143204B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -40,17 +40,25 @@ namespace IsolatedModel_BidirectionChat
|
|||
_logger.LogInformation($"{invocationContext.ConnectionId} has connected");
|
||||
return new SignalRMessageAction("newConnection")
|
||||
{
|
||||
Arguments = new object[] { new NewConnection(invocationContext.ConnectionId, auth) }
|
||||
Arguments = new object[] { new NewConnection(invocationContext.ConnectionId, auth) },
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
[Function("Broadcast")]
|
||||
[SignalROutput(HubName = "Hub")]
|
||||
public SignalRMessageAction Broadcast([SignalRTrigger("Hub", "messages", "Broadcast", "message")] SignalRInvocationContext invocationContext, string message)
|
||||
public SignalRMessageAction Broadcast(
|
||||
[SignalREndpointsInput("Hub")] SignalREndpoint[] endpoints,
|
||||
[SignalRNegotiationInput("Hub", "AzureSignalRConnectionString")] SignalRNegotiationContext negotiationContext,
|
||||
[SignalRTrigger("Hub", "messages", "Broadcast", "message")] SignalRInvocationContext invocationContext, string message)
|
||||
{
|
||||
_logger.LogInformation($"{negotiationContext.Endpoints[0].Endpoint}");
|
||||
_logger.LogInformation($"{negotiationContext.Endpoints[0].ConnectionInfo.AccessToken}");
|
||||
_logger.LogInformation($"{negotiationContext.Endpoints[1].Endpoint}");
|
||||
return new SignalRMessageAction("newMessage")
|
||||
{
|
||||
Arguments = new object[] { new NewMessage(invocationContext, message) }
|
||||
Arguments = new object[] { new NewMessage(invocationContext, message) },
|
||||
Endpoints = endpoints
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.Extensions.SignalRService
|
||||
{
|
||||
internal class HttpHeaderDictionaryConverter : JsonConverter<IDictionary<string, StringValues>>
|
||||
{
|
||||
public override IDictionary<string, StringValues> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var dict = JsonSerializer.Deserialize<IDictionary<string, string>>(ref reader, options);
|
||||
return dict.ToDictionary(pair => pair.Key,
|
||||
pair => pair.Value == null ? default : new StringValues(pair.Value.Split(',')));
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, IDictionary<string, StringValues> value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains necessary information for a SignalR client to connect to SignalR Service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class will be available by extensions in the next release.
|
||||
/// </remarks>
|
||||
public sealed class SignalRConnectionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The URL for a client to connect to SignalR Service.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The access token for a client to connect to SignalR service.
|
||||
/// </summary>
|
||||
public string AccessToken { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// An action to manage a group.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class will be available by extensions in the next release.
|
||||
/// </remarks>
|
||||
public sealed class SignalRGroupAction
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes an instance of a <see cref="SignalRGroupAction"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionType">The action type.</param>
|
||||
public SignalRGroupAction(SignalRGroupActionType actionType)
|
||||
{
|
||||
Action = actionType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets this field if you want to add a connection to a group or remove it from a group.
|
||||
/// </summary>
|
||||
public string? ConnectionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets this field if you want to add a user to a group or remove it from a group/all groups.
|
||||
/// </summary>
|
||||
public string? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The group to manage. Leave it null if you want to remove a user from all groups.
|
||||
/// </summary>
|
||||
public string? GroupName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The group action type.
|
||||
/// </summary>
|
||||
public SignalRGroupActionType Action { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of a group action.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class will be available by extensions in the next release.
|
||||
/// </remarks>
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum SignalRGroupActionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a user or a connection to a group.
|
||||
/// </summary>
|
||||
Add,
|
||||
/// <summary>
|
||||
/// Removes a user or a connection to a group.
|
||||
/// </summary>
|
||||
Remove,
|
||||
/// <summary>
|
||||
/// Remove a user from all the groups.
|
||||
/// </summary>
|
||||
RemoveAll
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Azure.Functions.Worker.Extensions.SignalRService;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// The context for a SignalR invocation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class will be available by extensions in the next release.
|
||||
/// </remarks>
|
||||
public sealed class SignalRInvocationContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The arguments of the invocation.
|
||||
/// </summary>
|
||||
public object[]? Arguments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The error message of connections disconnected event.
|
||||
/// Only connections disconnected event can have this property, and it can be empty if the connection is closed with no error.
|
||||
/// </summary>
|
||||
public string? Error { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The category of the invocation.
|
||||
/// </summary>
|
||||
public SignalRInvocationCategory Category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// For <see cref="SignalRInvocationCategory.Connections"/> category, only "connected" and "disconnected" are used.
|
||||
/// For <see cref="SignalRInvocationCategory.Messages"/> category, the event is the target in invocation message sent from clients.
|
||||
/// </summary>
|
||||
public string Event { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The hub the invocation belongs to.
|
||||
/// </summary>
|
||||
public string Hub { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The connection ID of the client which triggers the invocation.
|
||||
/// </summary>
|
||||
public string ConnectionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user ID of the client which triggers the invocation.
|
||||
/// </summary>
|
||||
public string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The headers of request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you use Newtonsoft.Json object serializer, you have to take care of the JSON deserialization yourself.
|
||||
/// </remarks>
|
||||
[JsonConverter(typeof(HttpHeaderDictionaryConverter))]
|
||||
public IDictionary<string, StringValues> Headers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The query of the request when client connect to the service.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you use Newtonsoft.Json object serializer, you have to take care of the JSON deserialization yourself.
|
||||
/// </remarks>
|
||||
[JsonConverter(typeof(HttpHeaderDictionaryConverter))]
|
||||
public IDictionary<string, StringValues> Query { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The claims of the client.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If you use Newtonsoft.Json object serializer, you have to take care of the JSON deserialization yourself.
|
||||
/// </remarks>
|
||||
[JsonConverter(typeof(HttpHeaderDictionaryConverter))]
|
||||
public IDictionary<string, StringValues> Claims { get; set; }
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum SignalRInvocationCategory
|
||||
{
|
||||
Connections,
|
||||
Messages
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// An action to send a message to SignalR clients.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The class will be available by extensions in the next release.
|
||||
/// </remarks>
|
||||
public sealed class SignalRMessageAction
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="SignalRMessageAction"/>.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Throws if the target is null.</exception>
|
||||
public SignalRMessageAction(string target)
|
||||
{
|
||||
Target = target ?? throw new ArgumentNullException(nameof(target));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="SignalRMessageAction"/>.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Throws if the target is null.</exception>
|
||||
public SignalRMessageAction(string target, object[]? arguments) : this(target)
|
||||
{
|
||||
Arguments = arguments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The connection ID to send to. Sets this field if you want to send a message to a single connection.
|
||||
/// </summary>
|
||||
public string? ConnectionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user ID to send to. Sets this field if you want to send a message to a single user.
|
||||
/// </summary>
|
||||
public string? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The group to send to. Sets this field if you want to send a message to a group.
|
||||
/// </summary>
|
||||
public string? GroupName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required. The target to send to.
|
||||
/// </summary>
|
||||
public string Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The arguments to send.
|
||||
/// </summary>
|
||||
public object[]? Arguments { get; set; }
|
||||
}
|
||||
}
|
|
@ -6,6 +6,9 @@
|
|||
"isEnabled": true,
|
||||
"excludedTypes": "Request"
|
||||
}
|
||||
},
|
||||
"logLevel": {
|
||||
"default": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче