Real-Time Cricket Score Chrome Extension using Azure Functions and SignalR


In this article, I will discuss how to show real-time cricket score notification from chrome extension using serverless Azure Functions and Azure SignalR.

I have used free API service to get the live cricket score updates. The purpose of this article is to show the power of serverless architecture using azure functions and broadcasting to connected clients in real-time using Azure SignalR. The demo source code I attached to this article is for the personal educational purpose only and not production use.


Register Cricket Services API

As a first step, to consume the API Service from, register the account with the details to get the API Key. They allow 100 free hits per day for the testing purpose.


Creating Azure SignalR Service

Log into your Azure Portal ( and create a new resource of type SignalR Service. After the service is created, copy the connection string from the Keys section.


Creating Azure Function App

  • Visual Studio 2017 Latest Version
  • Azure Portal Account
Launch the Visual Studio and Create a New Azure Function Project

Select the Azure Function v2 Preview and the Http trigger template.

For this demo, we will be creating two azure functions.
  • NegotiateFunction (HttpTrigger)
    • This function will get the JWT token for the client so that SignalR client can connect to Azure Signalr Service Hub.
  • BroadcastFunction (TimerTrigger)
    • This function runs every 1 min (configurable) and calls the CricAPI Service to get the latest score for defined match id and broadcast it to all connected clients.
In order to use Azure SignalR Service in Azure Functions, I have used Anthony Chu “AzureAdvocates.WebJobs.Extensions.SignalRService” library.


public static class NegotiateFunction
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req,
[SignalRConnectionInfo(HubName = "broadcasthub")]SignalRConnectionInfo info, ILogger log)
return info != null
? (ActionResult)new OkObjectResult(info)
: new NotFoundObjectResult("Failed to load SignalR Info.");


public static class BroadcastFunction
private static HttpClient httpClient = new HttpClient();

public static async void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer,
[SignalR(HubName = "broadcasthub")]IAsyncCollector<signalrmessage> signalRMessages, ILogger log)
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

//TODO: API key should be stored in Azure Key Vault .
//For Demo purpose, i hard coded the value here.
var values = new Dictionary<string string="">
//Hard coded Cricket Match Unique ID. You can change the Match id based on ongoing matchers
{"apikey", "_API_KEY_HERE"},{"unique_id", "1119553"}

using (var response = httpClient.PostAsJsonAsync(new Uri(""), values).Result)
var resultObj = response.Content.ReadAsStringAsync().Result;
dynamic result = JsonConvert.DeserializeObject(resultObj);

await signalRMessages.AddAsync(new SignalRMessage()
Target = "broadcastData",
Arguments = new object[] { result.score }
We have to create Appsettings Key called AzureSignalRConnectionString in order to connect to Azure SignalR Service from our Azure Functions. We will have to add the settings in local.settings.json for local testing and add it into Application Settings in Azure after we deploy it.


"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"AzureSignalRConnectionString": "Endpoint=;AccessKey="
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"

We are now done with the coding for the Azure functions, we can start testing it locally first before deploying into Azure Portal. In the local.settings.json, we have defined the localhttpport 7071 and allowed cross domains request by putting CORS : *

Run the Application by pressing F5 which will create the host and deploy the functions in localhost.

As you see above, Azure Functions are now hosted in local, we can run the negotiate function using the following URL which will return the JWT Token to connect to SignalR Service.
Now that it worked in localhost, we can deploy the Azure Functions into Azure Portal.

Publishing Azure Function App

In Visual Studio, Right click on the solution and Select the Publish option from the Menu.
Check the Run from ZIP checkbox and click the Publish button.
Click on the Create button to create the Azure hosting plan, storage account under your Azure subscription.
After the account is created, by clicking the publish button any time will ship the files into the portal and deploy the Azure Functions.
You can log in to Azure Portal to check the deployed Azure Functions.
We also need to add the AzureSignalRConnectionString key in Application Settings.
We have completed publishing Azure Functions in the Portal. Let us now create a chrome extension signalr client to receive the cricket score in real time. The timer trigger broadcast function will run every minute and push the cricket score to all connected clients.

Creating Chrome Extension

const apiBaseUrl = '<a href=""></a>';

const hubName = 'broadcasthub';

getConnectionInfo().then(info =&gt; {

const options = {

accessTokenFactory: () =&gt; info.accessKey


const connection = new signalR.HubConnectionBuilder()

.withUrl(info.endpoint, options)



connection.on('broadcastData', (message) =&gt; {

new Notification(message, {

icon: '48.png',

body: message



connection.onclose(() =&gt; console.log('disconnected'));



.then(() =&gt; console.log('connected!'))



function getConnectionInfo() {


.then(resp =&gt;;


In the manifest.json, we defined the list of scripts to load (axios, signalr and signalrclient).


"name": "Real Time Cricket Score Demo",

"version": "1.0",


"Real time Cricket Score Update from Serverless Azure Functions pop up on the desktop.",

"icons": {"16": "16.png", "48": "48.png", "128": "128.png"},

"permissions": [




"<a href="http://">http://</a>*/*",

"<a href="https://">https://</a>*/*"


"background": {

"persistent": true,

"scripts": ["axios.min.js","signalr.js","signalrclient.js"] },

"manifest_version": 2,

"web_accessible_resources": [



To install the chrome extension in your local machine, launch Chrome and open the extensions from the menu. Click the load unpacked extension and select the folder that chrome extension is placed.
After the extension is installed, the broadcast azure function will execute based on the schedule and broadcast the latest score to the newly connected client as below.


With the few lines of code, we have created the serverless azure functions, which will fetch the data from the API endpoint and broadcast the messages to all connected clients in real time using Azure SignalR. In this article, I have hardcoded the API key in the program but ideally, it should be stored in Azure Key Vault and read it from there. I hope this article helps you get started with Azure Functions. I have uploaded the entire source code in my github repository.

Happy Coding!


2 thoughts on “Real-Time Cricket Score Chrome Extension using Azure Functions and SignalR

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s