Querying Calls

For many video calling, livestream or audio rooms apps you'll want to show:

  • Upcoming calls
  • Calls that are currently live
  • Popular livestreams/audio rooms with a link to the recording

The SDK makes it easy to query calls

Example Queries

Calls that are about to start

// Filter calls that will start in 3 hours and include me
var filters = new List<IFieldFilterRule>
{
    CallFilter.StartsAt.LessThanOrEquals(DateTime.Now.AddHours(3)),
    CallFilter.Members.EqualsTo(_client.LocalUser)
};

// Order them by how soon they start
var result = await _client.QueryCallsAsync(filters, CallSort.OrderByAscending(CallSortField.StartsAt), limit: 25);

Calls filters on a custom property

// Filter calls by custom property. For example you can attach a "tag" property to a call and get calls that contain any of the provided tags
var filters = new List<IFieldFilterRule>
{
    CallFilter.Custom("tag").In("xbox", "ps", "switch"),
};

// Order them by how soon they start
var sort = CallSort.OrderByAscending(CallSortField.StartsAt);

var result = await _client.QueryCallsAsync(filters, sort, limit: 25);

Pagination The query response is paginated and the maximum count of items is defined by the limit parameter. Use the prev and next parameters from the last response as parameters for requesting the next page.

var filters = new List<IFieldFilterRule>
{
    CallFilter.CreatedAt.GreaterThan(DateTime.Now.AddHours(-24))
};

var result = await _client.QueryCallsAsync(filters, CallSort.OrderByDescending(CallSortField.CreatedAt), limit: 25);

// queried calls, depending on how many calls satisfy the filter this can be only a subset or a single "page" of results
var calls = result.Calls;

// In order to get the next "page" of results, use this token as a "next" argument in the QueryCallsAsync method
var next = result.Next;

// In order to get the previous "page" of results, use this token as a "prev" argument in the QueryCallsAsync method
var prev = result.Prev;

Fields for Query Calls

You can filter with CallFilter on the following fields:

Filter fieldDescription
CallFilter.TypeThe call type. Typically default, livestream etc
CallFilter.IdThe id for this call
CallFilter.CidThe cid for this call. IE default:123
CallFilter.CreatedByUserIdThe user id who created the call
CallFilter.CreatedAtWhen the call was created
CallFilter.UpdatedAtWhen the call was updated
CallFilter.StartsAtWhen the call starts at
CallFilter.EndedAtWhen the call ended
CallFilter.BackstageIf the call is in backstage mode or not
CallFilter.MembersCheck if you are a member of this call
CallFilter.Custom()Query your own custom data by field name

Sorting is done with CallSort and one of the CallSortField values:

Sort fieldDescription
CallSortField.StartsAtWhen the call starts at
CallSortField.CreatedAtWhen the call was created
CallSortField.UpdatedAtWhen the call was updated
CallSortField.TypeThe call type
CallSortField.IdThe id for this call
CallSortField.CidThe cid for this call

Watching queried calls

Pass watch: true and the SDK will keep the returned calls updated as events arrive. This allows you to show a live preview of who's in the call.

var result = await _client.QueryCallsAsync(filters, sort, limit: 25, watch: true);