@api.video/private-video-session
Version:
api.video private video session
189 lines (134 loc) • 5.5 kB
Markdown
[](https://twitter.com/intent/follow?screen_name=api_video)
[](https://github.com/apivideo/api.video-typescript-private-video-session)
[](https://community.api.video)

<h1 align="center">Private video session</h1>
[api.video](https://api.video) is the video infrastructure for product builders. Lightning fast
video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in
your app.
# Table of contents
- [Table of contents](#table-of-contents)
- [Project description](#project-description)
- [Getting started](#getting-started)
- [Installation](#installation)
- [Method #1: requirejs](#method-1-requirejs)
- [Method #2: typescript](#method-2-typescript)
- [Method #3: imple include in a javascript project](#method-3-imple-include-in-a-javascript-project)
- [Code sample](#code-sample)
- [Documentation](#documentation)
- [Instanciation options](#instanciation-options)
- [Instanciation with videoId \& token](#instanciation-with-videoid--token)
- [Instanciation with private asset url](#instanciation-with-private-asset-url)
- [Custom domains](#custom-domains)
- [Methods](#methods)
- [`getSession(): Promise<string>`](#getsession-promisestring)
- [`getThumbnailUrl(): Promise<string>`](#getthumbnailurl-promisestring)
- [`getPlayerUrl(): Promise<string>`](#getplayerurl-promisestring)
- [`getMp4Url(): Promise<string>`](#getmp4url-promisestring)
- [`getHlsUrl(): Promise<string>`](#gethlsurl-promisestring)
- [Sample application](#sample-application)
- [FAQ](#faq)
# Project description
This library aims to simplify the assets links retrieval of api.video private videos.
# Getting started
## Installation
### Method #1: requirejs
If you use requirejs you can add the module as a dependency to your project with
```sh
$ npm install --save @api.video/private-video-session
```
You can then use the module in your script:
```javascript
var { PrivateVideoSession } = require("@api.video/private-video-session");
var privateSession = new PrivateVideoSession({
...options, // see below for available options
});
```
### Method #2: typescript
If you use Typescript you can add the SDK as a dependency to your project with
```sh
$ npm install --save @api.video/private-video-session
```
You can then use the SDK in your script:
```typescript
import { PrivateVideoSession } from "@api.video/private-video-session";
const privateSession = new PrivateVideoSession({
...options, // see below for available options
});
```
### Method #3: imple include in a javascript project
Include the SDK in your HTML file like so:
```html
<head>
...
<script
src="https://unpkg.com/@api.video/private-video-session"
defer
></script>
</head>
<script type="text/javascript">
var privateSession = new PrivateVideoSession(
...options // see below for available options
});
</script>
```
## Code sample
```javascript
(async () => {
const privateSession = new PrivateVideoSession({
videoId: 'viMgTc1KULkXrjFfDCTBtLs',
token: 'aafe99ed-3d96-44a4-beac-eca06439467c'
});
const thumbnailUrl = await privateSession.getThumbnailUrl();
console.log(thumbnailUrl);
const playerUrl = await privateSession.getPlayerUrl();
console.log(playerUrl);
)();
```
# Documentation
## Instanciation options
The private video session can be instanciated with either a videoId & a private token, or directly with a private asset url:
### Instanciation with videoId & token
```javascript
const privateSession = new PrivateVideoSession({
videoId: "viMgTc1KULkXrjFfDCTBtLs",
token: "aafe99ed-3d96-44a4-beac-eca06439467c",
});
```
### Instanciation with private asset url
```javascript
const privateSession = new PrivateVideoSession({
assetUrl:
"https://embed.api.video/vod/viMgTc1KULkXrjFfDCTBtLs?token=aafe99ed-3d96-44a4-beac-eca06439467c",
});
```
### Custom domains
If you've configured [custom domains](https://docs.api.video/delivery-analytics/using-custom-domains) for your account, it's necessary to use the `domains` parameter when instantiating.
Here's a quick example on how to do it:
```javascript
const privateSession = new PrivateVideoSession({
assetUrl:
"https://embed.mydomain.com/vod/viMgTc1KULkXrjFfDCTBtLs?token=aafe99ed-3d96-44a4-beac-eca06439467c",
domains: {
embed: "embed.mydomain.com",
vod: "vod.mydomain.com",
live: "live.mydomain.com",
},
});
```
## Methods
### `getSession(): Promise<string>`
> Get the private video session token
### `getThumbnailUrl(): Promise<string>`
> Get the thumbnail url of the private video
### `getPlayerUrl(): Promise<string>`
> Get the player url of the private video
### `getMp4Url(): Promise<string>`
> Get the mp4 url of the private video
### `getHlsUrl(): Promise<string>`
> Get the hls url of the private video
# Sample application
See the [sample page](./tree/main/sample/) for a working example.
# FAQ
If you have any questions, ask us in the [community](https://community.api.video). Or
use [issues](https://github.com/apivideo/api.video-typescript-private-video-session/issues)..