Schedule events for your first virtual channel

birme

Jonas Birmé

Posted on May 16, 2020

Schedule events for your first virtual channel

In this blog we will walk you through how you by using the Consuo Schedule API can create a virtual channel and add events to the schedule.

Pre-requisities

You have already an instance of Consuo up and running and you replace <CHANNELMGR_IP> in this post with the IP-address to where your Consuo Schedule manager is running. For instructions on how to setup and install Consuo you can read the Quick Start guide.

Create channel

We will use the Consuo Schedule API to create a channel. You find the API documentation at http://<CHANNELMGR_IP>:8001/api/docs/. In the examples in this post we will use Node JS but other programming languages can be used as the API is HTTP based. What we will do first is to create a channel.

In this example we use fetch as HTTP client and to create a channel we do an HTTP POST with the following body to the endpoint /channels.

{
  id: "one",
  name: "Channel One"
}
Enter fullscreen mode Exit fullscreen mode

Example code:

const fetch = require('node-fetch');
const API = "http://<CHANNELMGR_IP>:8001";

async function run() {
  const res = await fetch(API + '/channels', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      id: "one",
      name: "Channel One"
    })
  });
  const json = await res.json();
  console.log(json);
}

run();
Enter fullscreen mode Exit fullscreen mode

Now you have a channel created that has the ID one and the name Channel One.

Add an event

Next, let us schedule an event. An event has a start, end and a URI to the video file to be played out. The format of the video file must be HLS as that is what Consuo supports today. The start time of the event is provided as a Unix Timestamp in milliseconds and all timestamps are in UTC timezone.

As an example, we want to create an event that starts on May 16 at 14:00 CET (UTC+02:00).

const start_time = Date.parse("16 May 2020 14:00:00+02:00");
Enter fullscreen mode Exit fullscreen mode

In this example start_time is then 1589630400000. To calculate the end_time we need to add the duration of the video file that we want to schedule. The video file we want to schedule is https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8 and it has a duration of 106 seconds. To calculate the end_time we need to multiply the duration with 1000 as the timestamps are in milliseconds and then we add this to the start_time.

const end_time = start_time + (106 * 1000);
Enter fullscreen mode Exit fullscreen mode

The event we want to schedule then looks as follows:

const event = {
  assetId: "VINN",
  title: "VINN",
  start_time: Date.parse("16 May 2020 14:00:00+02:00"),
  end_time: start_time + (106 * 1000),
  uri: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8",
  duration: 106
};
Enter fullscreen mode Exit fullscreen mode

Then we make an HTTP POST with the above JSON to /channels/one/schedule. The schedule for this channel will now include this:

[
  {
    "assetId": "VINN",
    "eventId": "4c605714-a3db-48e5-a5af-d0ece30246de",
    "id": "VINN",
    "title": "VINN",
    "start_time": 1589630400000,
    "end_time": 1589630506000,
    "start": "2020-05-16T12:00:00.000Z",
    "end": "2020-05-16T12:01:46.000Z",
    "uri": "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8",
    "duration": 106
  }
]
Enter fullscreen mode Exit fullscreen mode

The code example for the above can then look like this:

  const uri = "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8";
  const start_time = Date.parse("16 May 2020 14:00:00+02:00");
  const end_time = start_time + (106 * 1000);
  const event = {
    assetId: 'VINN',
    title: 'VINN',
    start_time: start_time,
    end_time: end_time,
    uri: uri,
    duration: 106
  };
  const res = await fetch(API + '/channels/one/schedule', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(event)
  });
Enter fullscreen mode Exit fullscreen mode

Playing the channel

To start playing the channel that you just created and added events to you need an HLS capable video player. If you just want to test you can use the HTML player at http://player.eyevinn.technology/ and enter the URI http://<ENGINE_IP>:8000/live/master.m3u8?channel=one. The <ENGINE_IP> is the IP to the Consuo Engine service.

💖 💪 🙅 🚩
birme
Jonas Birmé

Posted on May 16, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related