Our mission is to make it easier for anyone to customize streaming. Since the beginning of broadpeak.io, we have tried to be committed to providing our users with the best possible tools and resources to build and manage their video streaming platforms.

In that context, we launched a server-side Node.js SDK that gives developers tools to build on broadpeak.io faster.

We know it’s crucial to have well-written and easy-to-navigate API documentation. This library provides additional resources for making developing on top of our platform easier.

What is the scope of the SDK?

The SDK has support for all the broadpeak.io applications you want to use. And, as we are doing with our Postman Collections, we will keep it up to date with new API updates as they are released.

The entire SDK is openly developed and shared on GitHub.

By making this SDK open source, we aim to foster a collaborative environment and encourage the developer community to contribute, share feedback, and help us improve our offerings.

Feel free to check out the SDK code, post issue reports, and even submit pull requests with fixes or new features. Our SDK depends on feedback from our developers, so we love to get messages and pull requests.

Why Node.js first?

Node.js is an open-source, cross-platform JavaScript runtime environment that executes JavaScript code outside the web browser. It was created by Ryan Dahl in 2009. The initial motivation behind its development was to create a more efficient way to handle real-time applications and improve the performance of web servers. Dahl was frustrated with the limitations of the Apache HTTP server, which struggled to handle multiple concurrent connections efficiently.

By combining JavaScript with the Google V8 JavaScript engine, he created a runtime environment that allowed JavaScript code to be executed on the server-side, leading to the birth of Node.js.

Nowadays, Node.js is a popular choice among developers due to its excellent performance, scalability, and ease of use. By leveraging the power of the JavaScript ecosystem, Node.js allows software engineers to create server-side applications using this familiar language, or alternatively (like us) using Typescript.

Being also appreciated among our development team and used quite mainly for our code, it seemed logical to start with that.

Making it works in Node.js

Let’s say you have some VOD and you want to create a virtual channel.

First, create an API key in https://app.broadpeak.io/account-settings/api-keys

Then initialize a node.js app and install the broadpeak.io sdk

$ npm install --save broadpeak.io

Create a index.js file and include the broadpeak.io module:

const { BroadpeakSDK } = require('broadpeak.io');

Create a main function that initializes the sdk with your API key and calls the functions

async function main() {

  const sdk = new BroadpeakSDK("eyJh...");

  await createSourcesAndService(sdk);

  await createSchedule(sdk);

}

Create a variable holding your services and vod catalog.

const catalog = {

  assets: [

    { name: "tearsofsteel", url: "http://origin.broadpeak.io/bpk-vod/voddemo/default/5min/tearsofsteel/index.mpd", duration: 300 },

    { name: "bbb", url: "http://origin.broadpeak.io/bpk-vod/voddemo/default/5min/bbb/index.mpd", duration: 300 }

  ],

  baseLive: { name: "bpkiolive", url: "https://origin.broadpeak.io/bpk-tv/bpkiolive/default/index.mpd" },

  virtualChannel: { name: "my channel" }

}

Then, use the sdk to create the Sources and the Virtual Channel service:

async function createSourcesAndService(sdk) {

  catalog.baseLive = await sdk.Sources.Live.create({

    name: catalog.baseLive.name, url: catalog.baseLive.url

  });

  catalog.virtualChannel = await sdk.Services.VirtualChannel.create({

    name: catalog.virtualChannel.name,

    baseLive: { id: catalog.baseLive.id }

  });

  for (idx in catalog.assets) {

    var assetSource = await sdk.Sources.Asset.create({

      name: catalog.assets[idx].name, url: catalog.assets[idx].url

    });

    catalog.assets[idx].id = assetSource.id;

  }

}

Finally, create slots to schedule the VOD in your Virtual Channel:

async function createSchedule(sdk) {

  var slotTime = new Date(Date.now() + 30000);

  for (idx in catalog.assets) {

    await sdk.Services.VirtualChannel.createSlot(

      catalog.virtualChannel.id,

      { startTime: slotTime.toISOString(), duration: catalog.assets[idx].duration, replacement: { id: catalog.assets[idx].id } }

    );

    slotTime = new Date(slotTime.getTime() + catalog.assets[idx].duration * 1000);

  }

}

Of course this is a very simple example but this allows to demonstrate how you can use the API to add VOD sources and then create a schedule.

Conclusion

This SDK is a first for us, but we plan to keep it up-to-date. It is something we want to see used and alive. We also have in the books a second SDK in Go; stay tuned!

Mathias Guille
https://linkedin.com/in/mathiasguille
Mathias Guille is the Vice President Cloud Platform at Broadpeak. He leads the strategic development of Broadpeak’s cloud platform, including the building of the company’s infrastructure in the cloud and in public datacenters, the design of Broadpeak’s platform on top of the infrastructure and the shaping of the company’s applications to accommodate SaaS offerings.