Real Time Data

LymeTemplate API's RealTime endpoint provides the front end with data that changes in real time throughout the app.

Sample Response from API

Below is an example of response provided by this endpoint:

{
    "versionInfo": {
        "version": "1.0.0.23",
        "lastUpdated": "2024-11-17T19:38:40.1321539Z"
    },
    "notificationCounts": [
        {
            "name": "UsersOnline",
            "value": 1
        }
    ],
    "motd": null,
    "minClientVersion": "1.0.0.23"
}

Data Description

A description of the data is as follows:

Name Description
versionInfo Contains data about the app version to prompt for reloading of an updated app if configured in Other Settings page of the Admin Area.
versionInfo:version The version number of the application. The version number is automatically generated by the TeamCity Build Configuration
versionInfo:lastUpdateed The date that the API was last built.
notificationCounts Notification counts is a key/value paired set of data that display numeric notification badges in the app's Nav Menu.
motd The Message of the Day data that should be displayed when applicable.
minClientVersion This value is maintained by the Other Settings page and is intended to prompt users to reload their application if client updates get pushed out via a automated deployment. If this value is greater than the value that is in the versionInfo:version value, then the user will be prompted to reload.

Pushing Real Time Data via SignalR

By default, the Angular front-end is configured to poll the API at a regular interval to pick up data updates. However, sometimes there is a need to push this data out in a quicker manner. To do this, LymeTemplate uses Microsoft's SignalR technology to push a signal to the client app to invoke an immediate refresh of this endpoint.

In the API project, there is a Hubs/RealTimeHub.cs file which listens for signals from the the API and client app.

Below is an example on how the Vaporware controller uses the hub to send signals to the client from the WebApi:

using LymeTemplateApi.Data;
using LymeTemplateApi.Hubs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace LymeTemplateApi.Controllers;

[ApiController]
[Route("[controller]")]
[AllowAnonymous]
public class VaporwareController(IConfiguration configuration, IHubContext<RealTimeHub> hubContext)
    : ControllerBase
{
    [Route("TestSignalR")]
    [HttpGet]
    public async Task<ActionResult<string>> TestSignalR()
    {
        await hubContext.Clients.All.SendAsync("ReceiveRealTimeUpdate");
        return Ok();
    }
}