Events-stream Service

This service relays what's happening in the live event.

  • The event-stream service informs clients about what's happening in the event four times a second in discrete 250-millisecond intervals.
  • Each interval contains a list of events that occurred.
  • You should query the events service every 250ms to get all events that have happened.

To do so, follow our guide on how to sync your client's clock with Reactive's servers and make requests at the correct intervals.

Each route requires that requests authenticate with a Reactive JWT Token. Refer to our authentication documentation for how to get and use a Reactive JWT Token.

Get events

Gets the events that have occurred in an interval.

Request:

GET https://events-stream.reactive.live/api/v1/events-streams/:stream_id?interval=:interval

Parameters:

Name Type Required Description
stream_id string Yes The id of the stream you'd like to register as a viewer for
interval integer Yes The 250 millisecond interval for which you want to get events.

Example command:

curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpcCI6IjEwNC4xNjIuOTcuMjgiLCJhdWQiOiI2OTM1MzU3YS04ZDcxLTQ1ZjItOWEwZi1kZGFlZDcwNWI0M2EiLCJzdWIiOiJBQjM1NDU3YS04ZDcxLTQ1ZjItQkUyRi1kZGFlZDcwNWI0M2EiLCJpc3MiOiJSZWFjdGl2ZSIsImlhdCI6MTYzNDkzNTQ5NCwiZXhwIjoxNjM0OTM2MDk0LCJqdGkiOiIwNzRlNDA0MS02MDg0LTQyOTItOTk2MC1jMTBlNWE1YzAwMjgifQ.o-pkrvzbTSVlzGixknSQvX1cwH1UIpx3R_fzmMpn3R8" \
    https://events-stream.reactive.live/api/v1/events-streams/76f449ec-3ea0-4002-addf-50ff1b51afaf?interval=1663278794500

Response:

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
  "interval": 1663278794500,
  "events": [
    { 
      "type": "view-count",
      "data": {
        "value": 2134,
        "formatted": "2.1K"
      }
    },
    {
      "type": "chats",
      "data": {
        "messages": [],
        "questions": [],
        "greetings": [],
        "cheers": [],
        "purchases": [],
        "hearts": 13,
        "discounts": 0
      },
      { 
        "type": "quiz",
        "data": {
          "id": "6935357a-8d71-45f2-9a0f-ddaed705b43a",
          "streamId": "1127787a-8d71-45f2-9a0f-ddaed703e4b6z",
          "created": 16000,
          "duration": 10000,
          "closeInterval": 17000,
          "question": "What is the most consumed manufactured drink in the world?",
          "choices": {
            "Coffee": {
              "count": 0,
              "percentage": 0
            },
            "Tea": {
              "count": 0,
              "percentage": 0
            },
            "Soda": {
              "count": 0,
              "percentage": 0
            }
          }
        }
      },
      { 
        "type": "quiz-results",
        "data": {
          "id": "6935357a-8d71-45f2-9a0f-ddaed705b43a",
          "streamId": "1127787a-8d71-45f2-9a0f-ddaed703e4b6z",
          "created": 16000,
          "duration": 10000,
          "closeInterval": 17000,
          "question": "What is the most consumed manufactured drink in the world?",
          "answer": "Tea",
          "choices": {
            "Coffee": {
              "count": 2123,
              "percentage": 1
            },
            "Tea": {
              "count": 55156,
              "percentage": 33
            },
            "Soda": {
              "count": 107721,
              "percentage": 65
            }
          }
        }
      },
      {
        "type": "quiz-winners",
        "data": {
          "count": 1232
        }
      }
    }
  ]
}

The response will include all events within the past 250-millisecond interval. Update your UI based on these events to show changes in the view count, new chats from other viewers, and other events.