Skip to content

Commit

Permalink
Merge pull request #32 from THEOplayer/feature/adscript
Browse files Browse the repository at this point in the history
AdScript Connector
  • Loading branch information
wjoosen authored Aug 8, 2024
2 parents 00d14d5 + 55f4e35 commit 350647f
Show file tree
Hide file tree
Showing 23 changed files with 1,250 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-zoos-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@theoplayer/adscript-connector-web": minor
---

Initial release.
1 change: 1 addition & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/web-connectors.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ Using the available connectors allows you to augment the features delivered thro

## Available Connectors

| Connector | npm package | Source code |
|:----------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------|
| CMCD | [![@theoplayer/cmcd-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fcmcd-connector-web?label=%40theoplayer%2Fcmcd-connector-web)](https://npmjs.com/package/@theoplayer/cmcd-connector-web) | [cmcd](https://github.com/THEOplayer/web-connectors/tree/main/cmcd) |
| Comscore | [![@theoplayer/comscore-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fcomscore-connector-web?label=%40theoplayer%2Fcomscore-connector-web)](https://npmjs.com/package/@theoplayer/comscore-connector-web) | [comscore](https://github.com/THEOplayer/web-connectors/tree/main/comscore) |
| Conviva | [![@theoplayer/conviva-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fconviva-connector-web?label=%40theoplayer%2Fconviva-connector-web)](https://npmjs.com/package/@theoplayer/conviva-connector-web) | [conviva](https://github.com/THEOplayer/web-connectors/tree/main/conviva) |
| Nielsen | [![@theoplayer/nielsen-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fnielsen-connector-web?label=%40theoplayer%2Fnielsen-connector-web)](https://npmjs.com/package/@theoplayer/nielsen-connector-web) | [nielsen](https://github.com/THEOplayer/web-connectors/tree/main/nielsen) |
| Yospace | [![@theoplayer/yospace-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fyospace-connector-web?label=%40theoplayer%2Fyospace-connector-web)](https://npmjs.com/package/@theoplayer/yospace-connector-web) | [yospace](https://github.com/THEOplayer/web-connectors/tree/main/yospace) |
| Connector | npm package | Source code |
|:----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------|
| AdScript | [![@theoplayer/adscript-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fadscript-connector-web?label=%40theoplayer%2Fadscript-connector-web)](https://npmjs.com/package/@theoplayer/adscript-connector-web) | [adscript](https://github.com/THEOplayer/web-connectors/tree/main/adscript) |
| CMCD | [![@theoplayer/cmcd-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fcmcd-connector-web?label=%40theoplayer%2Fcmcd-connector-web)](https://npmjs.com/package/@theoplayer/cmcd-connector-web) | [cmcd](https://github.com/THEOplayer/web-connectors/tree/main/cmcd) |
| Comscore | [![@theoplayer/comscore-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fcomscore-connector-web?label=%40theoplayer%2Fcomscore-connector-web)](https://npmjs.com/package/@theoplayer/comscore-connector-web) | [comscore](https://github.com/THEOplayer/web-connectors/tree/main/comscore) |
| Conviva | [![@theoplayer/conviva-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fconviva-connector-web?label=%40theoplayer%2Fconviva-connector-web)](https://npmjs.com/package/@theoplayer/conviva-connector-web) | [conviva](https://github.com/THEOplayer/web-connectors/tree/main/conviva) |
| Nielsen | [![@theoplayer/nielsen-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fnielsen-connector-web?label=%40theoplayer%2Fnielsen-connector-web)](https://npmjs.com/package/@theoplayer/nielsen-connector-web) | [nielsen](https://github.com/THEOplayer/web-connectors/tree/main/nielsen) |
| Yospace | [![@theoplayer/yospace-connector-web](https://img.shields.io/npm/v/%40theoplayer%2Fyospace-connector-web?label=%40theoplayer%2Fyospace-connector-web)](https://npmjs.com/package/@theoplayer/yospace-connector-web) | [yospace](https://github.com/THEOplayer/web-connectors/tree/main/yospace) |

## License

Expand Down
10 changes: 10 additions & 0 deletions adscript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Node artifact files
node_modules/
lib/
dist/

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db
100 changes: 100 additions & 0 deletions adscript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# adscript-connector-web

The AdScript connector provides an AdScript integration for THEOplayer.

## Installation

Install using your favorite package manager for Node (such as `npm` or `yarn`):

### npm

```bash
npm install @theoplayer/adscript-connector-web
```

### yarn

```bash
yarn add @theoplayer/adscript-connector-web
```

## Usage

First you need to add the AdScript connector to your app :

* Add as a regular script

```html

<script type="text/javascript" src="path/to/adscript-connector.umd.js"></script>
<script type="text/javascript">
const player = new THEOplayer.Player(element, configuration);
// Define your configuration for the connector:
const adScriptConfig = {
implementationId: 'your-implementation-id', // Replace this!
metadata: {
"assetid": "v0000001",
"type": "content",
"program": "Big Buck Bunny",
"title": "Sample Video - Extended",
"length": "635",
"crossId": "000 111 22222",
"livestream": "0",
"channelId": "",
"attribute": "1"
},
debug: false
}
// Create the AdScriptConnector:
const adScriptConnector = new THEOplayerAdScriptConnector.AdScriptConnector(player, adScriptConfig);
</script>
```

* Add as an ES2015 module

```html

<script type="module">
import {AdScriptConnector} from "@theoplayer/adscript-connector-web";
const player = new THEOplayer.Player(element, configuration);
// Define your configuration for the connector:
const adScriptConfig = {
implementationId: 'your-implementation-id', // Replace this!
metadata: {
"assetid": "v0000001",
"type": "content",
"program": "Big Buck Bunny",
"title": "Sample Video - Extended",
"length": "635",
"crossId": "000 111 22222",
"livestream": "0",
"channelId": "",
"attribute": "1"
},
debug: false
}
// Create the AdScriptConnector:
const adScriptConnector = new AdScriptConnector(player, adScriptConfig);
</script>
```

## Updating metadata

If the metadata has changed during playback, you can update it with:

```javascript
adScriptConnector.updateMetadata(newMetadata);
```

## Updating userInfo

If the user info has changed during playback, you can update it with:

```javascript
adScriptConnector.updateUser(i12n);
```
47 changes: 47 additions & 0 deletions adscript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@theoplayer/adscript-connector-web",
"version": "0.0.1",
"description": "A connector implementing AdScript with THEOplayer",
"main": "dist/adscript-connector.umd.js",
"module": "dist/adscript-connector.esm.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/adscript-connector.esm.js",
"require": "./dist/adscript-connector.umd.js"
},
"./dist/*": "./dist/*",
"./package": "./package.json",
"./package.json": "./package.json"
},
"scripts": {
"clean": "rimraf lib dist",
"bundle": "rollup -c rollup.config.mjs",
"watch": "npm run bundle -- --watch",
"build": "npm run clean && npm run bundle",
"serve": "http-server ./.. -o /adscript/test/pages/main_esm.html",
"test": "echo \"No tests yet\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/THEOplayer/web-connectors.git",
"directory": "adscript"
},
"author": "THEO Technologies NV",
"license": "MIT",
"bugs": {
"url": "https://github.com/THEOplayer/web-connectors/issues"
},
"homepage": "https://github.com/THEOplayer/web-connectors/tree/main/adscript#readme",
"files": [
"dist/",
"CHANGELOG.md",
"README.md",
"LICENSE.md",
"package.json"
],
"peerDependencies": {
"theoplayer": "^7.0.0"
}
}
15 changes: 15 additions & 0 deletions adscript/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from "node:fs";
import {getSharedBuildConfiguration} from "../tools/build.mjs";


const {version} = JSON.parse(fs.readFileSync("./package.json", "utf8"));

const fileName = "adscript-connector";
const globalName = "THEOplayerAdScriptConnector";

const banner = `
/**
* THEOplayer AdScript Web Connector v${version}
*/`.trim();

export default getSharedBuildConfiguration({fileName, globalName, banner});
57 changes: 57 additions & 0 deletions adscript/src/adscript/AdScript.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export type JHMTApiProtocol = 'https:' | 'http:' | 'file:';

interface I12n {
i1: string;
i2: string;
i3: string;
i4: string;
i5: string;
}

export type MainVideoContentType = 'content';
export type EmbeddedContentType = 'preroll' | 'midroll' | 'postroll';
export type StaticContentType = 'static';

interface StaticContentMetadata {
assetid: string;
type: StaticContentType;
sec1: string;
sec2: string;
sec3: string;
sec4: string;
ref: string;
}

export interface PlayerState {
muted: number;
volume: number;
triggeredByUser: number;
normalSpeed: number;
fullscreen: number;
visibility: number;
width: number;
height: number;
}

interface JHMTArray extends Array<any> {
i12n: I12n;
contentMetadata: ContentMetadata;
playerState: PlayerState;
push: (item: any) => number; // Type of the push function
}

declare global {
interface Window {
JHMT: JHMTArray;
JHMTApi: typeof JHMTApi;
JHMTApiProtocol: JHMTApiProtocol;
}
}

export interface JHMTApi {
setI12n(i12n: I12n);

setContentMetadata(contentMetadata: ContentMetadata);

setPlayerState(playerState: PlayerState);
}
2 changes: 2 additions & 0 deletions adscript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AdScriptConnector } from './integration/AdScriptConnector';
export * from './integration/AdScriptConfiguration';
62 changes: 62 additions & 0 deletions adscript/src/integration/AdScriptConfiguration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { Ad } from 'theoplayer';

/**
* The main content information settings.
* For more information, see the [main content information settings](https://adscript.admosphere.cz/en_adScript_browser.html) section in the AdScript documentation.
*/
export interface MainVideoContentMetadata {
assetid: string;
type: 'content';
program: string;
title: string;
length: string;
crossId: string;
livestream: string;
channelId: string;
attributes: string;
}

/**
* The embedded content metadata, about the currently playing ad.
*/
export interface EmbeddedContentMetadata {
assetid: string;
type: 'preroll' | 'midroll' | 'postroll';
length: string;
title: string;
asmea: string;
attributes: string;
}

/**
* The configuration for the AdScript Connector.
*/
export interface AdScriptConfiguration {
/**
* Integration ID you received from your Nielsen representative.
*/
implementationId: string;

/**
* The initial main content information settings.
* Metadata of the main video content needs to be set before the first measured event occurs.
* For more information, see the [main content information settings](https://adscript.admosphere.cz/en_adScript_browser.html) section in the AdScript documentation.
*/
metadata: MainVideoContentMetadata;

/**
* Additional information about the logged-in user (customerID, deviceID, profileID) from the client´s database.
* For more information, see the [Additional Information Settings](https://adscript.admosphere.cz/en_adScript_browser.html) section.
*/
i12n?: { [key: string]: string };

/**
* An optional advertisement processor to receive metadata about the Ad.
*/
adProcessor?: (ad: Ad) => EmbeddedContentMetadata;

/**
* Whether the connector should log all actions.
*/
debug?: boolean;
}
Loading

0 comments on commit 350647f

Please sign in to comment.