This extension provides data models using in communication with Web PubSub Service.
Install the package with NuGet:
dotnet add package Microsoft.Azure.WebPubSub.Common
You must have an Azure subscription and an Azure resource group with a Web PubSub resource. Follow this step-by-step tutorial to create an Azure Web PubSub instance.
Please follow the input binding tutorial to learn about using this extension for building WebPubSubConnection
to create Websockets connection to service with input binding.
Please follow the output binding tutorial to learn about using this extension for publishing Web PubSub messages.
Please follow the trigger binding tutorial to learn about triggering an Azure Function when an event is sent from service upstream.
[FunctionName("WebPubSubInputBindingFunction")]
public static WebPubSubConnection Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
[WebPubSubConnection(Hub = "simplechat", UserId = "{query.userid}")] WebPubSubConnection connection)
{
Console.WriteLine("login");
return connection;
}
[FunctionName("WebPubSubOutputBindingFunction")]
public static async Task RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
[WebPubSub(Hub = "simplechat")] IAsyncCollector<WebPubSubOperation> operation)
{
await operation.AddAsync(new SendToAll
{
Message = BinaryData.FromString("Hello Web PubSub"),
DataType = MessageDataType.Text
});
}
[FunctionName("WebPubSubTriggerFunction")]
public static async Task<MessageResponse> RunAsync(
[WebPubSubTrigger("message", WebPubSubEventType.User)]
ConnectionContext context,
string message,
MessageDataType dataType)
{
Console.WriteLine($"Request from: {context.userId}");
Console.WriteLine($"Request message: {message}");
Console.WriteLine($"Request message DataType: {dataType}");
return new MessageResponse
{
Message = BinaryData.FromString("ack"),
};
}
Please refer to Monitor Azure Functions for troubleshooting guidance.
Read the introduction to Azure Function or creating an Azure Function guide.
See our CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.