Events and State WebSocket API: Authentication, Events Documentation, Events Testing

I have a couple of questions regarding the Events and State WebSocket API:

- Authentication: it is stated that we need to send a bearer token in the header of the WebSocket connection (or by using the authenticate command) to authenticate and be able to receive events.

Does the VMS keep track of the expiration date of the token? if so what happens when the token expires? does it just close the connection? if I get a new token before the original token expires is there a way to send it to the VMS and keep the connection alive?

- Events Documentation :

it is stated here that the content of `data` depends on the type of event is there any documentation for how the data looks like for each event type? In our case, we have the events from the WebSocket sent from to Kafka message bus where it is consumed and possibly transformed to be sent to a big data platform so we need to know the structure of the events we support to be able to apply those transformations

- Events Testing: As I stated above we take the events from the WebSocket and send them to Kafka and from there possibly apply transformations but we need to test this so is there a way to trigger events manually from the VMS?

I have been consulting Milestone Development and can share the following answer.

--

Authentication:

Please note that although the documentation implies so the ‘Authenticate’ command is not yet supported.

The token provided is only validated when the connection is established, and thus the connection will not be interrupted because the token expires.

The connection will however most likely be interrupted eventually due to other reasons, so the connection will not be kept indefinite. E.g. the API gateway is by default recycled every 27 hours, which will cause a disconnect, and require a new connection with a new token.

It is not possible to provide a new token to an existing connection.

Content of data:

The content of the data depends on the event type, and there are quite some variants..

There are some event types that has a fixed format, where the most common are

Analytics Events and Access Control Events

The structures are not yet documented properly but they are the following structures serialized as json:

public class AnalyticsData: AnalyticsDataWithoutSnapshots
{
	/// <summary>
	/// Images related to the analytics event.
	/// If the <see cref="EventsAndState.State.Source"/> is a camera and recording is enabled, it is not necessary to attach a snapshot from that camera at the time of the analytics event.
	/// </summary>
	public virtual AnalyticsSnapshot[] Snapshots { get; set; }
}
 
public class AnalyticsDataWithoutSnapshots
{
	/// <summary>
				  /// The description of the analytics event.
				  /// </summary>
	public virtual string Description { get; set; }
 
	/// <summary>
	/// The start time of the analytics event, if it takes place over a period of time.
	/// </summary>
	public virtual DateTime? StartTime { get; set; }
 
	/// <summary>
	/// The end time of the analytics event, if it takes place over a period of time.
	/// </summary>
	public virtual DateTime? EndTime { get; set; }
 
	/// <summary>
	/// The location of the analytics event (this will typically be the same as the camera's location).
	/// </summary>
	public virtual string Location { get; set; }
 
	/// <summary>
	/// The count value, if the analytics event contains a counting value. Default is 0 (no count).
	/// </summary>
	public virtual uint Count { get; set; }
 
	/// <summary>
	/// Information about the rule(s) that triggered the analytics event.
	/// </summary>
	public virtual AnalyticsRule[] Rules { get; set; }
 
	/// <summary>
	/// The detected object(s) in the scene.
	/// </summary>
	public virtual AnalyticsObject[] Objects { get; set; }
 
	/// <summary>
	/// Array of references to other entities in the system, e.g. cameras.
	/// Every entry must be set to a valid REST resource string. 
	/// E.g. if the entity is a camera the format will be `cameras/{id}` or simply `{id}`
	/// </summary>
	/// <example>[ "cameras/e028f597-c64b-4f27-bb8d-08f5cd768e1c", "cameras/cd865c62-4962-4861-b109-5f4f1172f09e" ]</example>
	public virtual string[] References { get; set; }
 
	/// <summary>
	/// The analytics vendor including any custom data.
	/// </summary>
	public virtual AnalyticsVendor Vendor { get; set; }
}
 
 
/// <summary>
/// Data of an access control event.
/// </summary>
public class AccessControlData
{
	/// <summary>
	/// The ID of the access control system.
	/// </summary>
	public Guid? System { get; set; }
 
	/// <summary>
	/// The event ID in the access control system.
	/// </summary>
	public string Id { get; set; }
 
	/// <summary>
	/// The ID of the event type in the access control system.
	/// </summary>
	public Guid? EventType { get; set; }
 
	/// <summary>
	/// The ID of the source in the access control system.
	/// </summary>
	public Guid? Source { get; set; }
 
	/// <summary>
	/// The ID of the source type in the access control system.
	/// </summary>
	public Guid? SourceType { get; set; }
 
	/// <summary>
	/// ID's of the related access control credential holders.
	/// </summary>
	public string[] CredentialHolders { get; set; }
 
	/// <summary>
	/// ID's of the related access control elements.
	/// </summary>
	public Guid[] Elements { get; set; }
 
	/// <summary>
	/// ID's of the event categories.
	/// </summary>
	public Guid[] Categories { get; set; }
 
	/// <summary>
	/// List of the related surveillance items.
	/// Every entry must be set to a valid REST resource string. 
	/// If the source device is camera the format will be `cameras/{id}` or simply `{id}`
	/// </summary>
	/// <example>cameras/e028f597-c64b-4f27-bb8d-08f5cd768e1c</example>
	public string[] SurveillanceItems { get; set; }
 
	/// <summary>
	/// Reason of the event.
	/// </summary>
	public string Reason { get; set; }
 
	/// <summary>
	/// Additional access control properties.
	/// </summary>
	public Dictionary<string, string> Properties { get; set; }
}

For other event types, the format may differ. In that case, the best (only) option is to make the ‘interesting’ event happen and capture the data received.

I have heard from the developers. The remark about data types not being exposed in the documentation, has actually proven not to be right. Again I am copying the information I have received.

--

I started researching why AnalyticsData and AccessControlData are not exposed in the documentation, while REST API client is generated properly.

And it seems I wasn’t right. The data schema is there. But should be clicked on different place.

Not on the Red box but on the Orange one:

And then the data schema is expanded:

And from the yellow box can be switched between AnalyticsData and AccessControlData.

In addition, yaml file with the whole description could be downloaded (including those two types in it).

Download button is on top of the page:

Great, thank you very much

A follow-up question I cannot find the schemas for predefined events present here :

https://doc.milestonesys.com/latest/en-US/standard_features/sf_mc/sf_ui/mc_eventsoverview_rulesandevents.htm

where can I find them?

Hi Osama,

I don’t believe these events have specific data schema. In other words (if I’m not mistaken) they should have empty “data” field (and “datatype” set to “none”).