GithubHelp home page GithubHelp logo

isabella232 / azure-functions-signalrservice-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure/azure-functions-signalrservice-extension

0.0 0.0 0.0 959 KB

Azure Functions bindings for SignalR Service

License: MIT License

C# 92.33% Batchfile 0.17% Shell 3.16% PowerShell 2.28% Java 2.05%

azure-functions-signalrservice-extension's Introduction

Azure Functions Bindings for Azure SignalR Service

Build Status

Travis: travis

NuGet Packages

Package Name Target Framework NuGet
Microsoft.Azure.WebJobs.Extensions.SignalRService .NET Standard 2.0 NuGet

Intro

These bindings allow Azure Functions to integrate with Azure SignalR Service.

Supported scenarios

  • Allow clients to serverlessly connect to a SignalR Service hub without requiring an ASP.NET Core backend
  • Use Azure Functions (any language supported by V2) to broadcast messages to all clients connected to a SignalR Service hub.
  • Use Azure Functions (any language supported by V2) to send messages to a single user, or all the users in a group.
  • Use Azure Functions (any language supported by V2) to manage group users like add/remove a single user in a group.
  • Example scenarios include: broadcast messages to a SignalR Service hub on HTTP requests and events from Cosmos DB change feed, Event Hub, Event Grid, etc

Bindings

SignalRConnectionInfo input binding makes it easy to generate the token required for clients to initiate a connection to Azure SignalR Service.

SignalR output binding allows messages to be broadcast to an Azure SignalR Service hub.

Current limitations

  • Cannot invoke methods on a subset of connections.
  • Functions cannot be triggered by client invocation of server methods (clients need to call an HTTP endpoint or post messages to a Event Grid, etc, to trigger a function)

Prerequisites

Usage

Create Azure SignalR Service instance

  1. Create an Azure SignalR Service instance in the Azure Portal. Note the connection string, you'll need this later.

Create Function App with extension

  1. In a new folder, create a new Azure Functions app.
    • func init
  2. Install this Functions extension.
    • func extensions install -p Microsoft.Azure.WebJobs.Extensions.SignalRService -v 1.0.0

Add application setting for SignalR connection string

  1. Create an app setting called AzureSignalRConnectionString with the SignalR connection string.
    • On localhost, use local.settings.json
    • In Azure, use App Settings

Using the SignalRConnectionInfo input binding

In order for a client to connect to SignalR, it needs to obtain the SignalR Service client hub URL and an access token.

  1. Create a new function named negotiate and use the SignalRConnectionInfo input binding to obtain the connection information and return it. Take a look at this sample.
  2. Client connects to the negotiate function as it's a normal SignalR hub. See this file for a sample usage.

Binding schema:

{
  "type": "signalRConnectionInfo",
  "name": "connectionInfo",
  "hubName": "<hub_name>",
  "connectionStringSetting": "<setting_name>", // Defaults to AzureSignalRConnectionString
  "direction": "in"
}

Using the SignalR output binding

The SignalR output binding can be used to broadcast messages to all clients connected a hub. Take a look at this sample:

Binding schema:

{
  "type": "signalR",
  "name": "signalRMessages", // name of the output binding
  "hubName": "<hub_name>",
  "connectionStringSetting": "<setting_name>", // Defaults to AzureSignalRConnectionString
  "direction": "out"
}

To send one or more messages, set the output binding to an array of objects:

module.exports = function (context, req) {
  context.bindings.signalRMessages = [{
    "target": "newMessage", // name of the client method to invoke
    "arguments": [
      req.body // arguments to pass to client method
    ]
  }];
  context.done();
};

Contributing

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 https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

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.

azure-functions-signalrservice-extension's People

Contributors

anthonychu avatar brandonh-msft avatar brunhil avatar chenkennt avatar danielwertheim avatar devlead avatar dfinke avatar jialinxin avatar tehmas avatar wanlwanl avatar y-sindo avatar zackliu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.