> For the complete documentation index, see [llms.txt](https://dev-stagecast.gitbook.io/moments-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev-stagecast.gitbook.io/moments-sdk/documentation/api-reference.md).

# API Reference

List of functions and variables exposed by the Stagecast object, the entry point to the MDK library.

{% hint style="info" %}
In case you want to code right away, you can check out the [tutorial section](/moments-sdk/tutorials/my-first-moment.md) and come back here later.
{% endhint %}

## Introduction

The **`Stagecast`** object is library entry point and comes with some getter function that allows to access the Moment context data. The context data is grouped in the [general getters](/moments-sdk/documentation/api-reference.md#general-getters) section.

You can also get directly to the sub sections:&#x20;

* [The **`connection`** object](/moments-sdk/documentation/api-reference/connection.md)
* [The **`ws`** object](/moments-sdk/documentation/api-reference/websockets.md)
* [The **`analytics`** object](/moments-sdk/documentation/api-reference/analytics.md)
* [The **`quiz`** object ](/moments-sdk/documentation/api-reference/quiz.md)
* [The **`prize`** object](/moments-sdk/documentation/api-reference/prize.md)

## General Getters

Your HTML-based application will get its running context from the Moment. The moment is derived from a MomentClass which belongs to a specific Event.

### `getEventId(): string`

```javascript
const eventId = SDK.getEventId();
console.log(eventId); // prints "1234-5678-90123-4567"
```

Returns the current event id. The id is a UUIDv4.&#x20;

### `getUserId(): string`

```javascript
const userEmail = SDK.getUserId();
console.log(userEmail); // prints "user@stagecast.io"
```

Returns the User identification which most of the times is the email.

### `getMomentId(): string`

```javascript
const momentId = SDK.getMomentId();
console.log(momentId); // prints "12345-45677-ABCDE-12345"
```

Returns the Moment id as a string. The id is a UUIDv4.&#x20;

### `getMomentClassId(): string`

```javascript
const momentClassId = SDK.getMomentClassId();
console.log(momentClassId); // prints "12345-45677-ABCDE-12345"
```

Returns the MomentClass id. The id is a UUIDv4.&#x20;

### `isActive(): boolean`

Tells whether the Moment is active or not, ie. whether the moment has been stopped by the event organizer from the launchpad. It can be used to render different views, for example:&#x20;

```javascript
if (SDK.isActive()) {
  renderMainPage();
} else {
  renderOtherPage();
}
```

Often, this is used to display the moment results. An example could be a poll: as long as `isActive()` returns `true` the user can express a vote. When the moment stops and `isActive()` return `false`, the application could display the poll results or just the user vote.

### `getCoordinates(): [lat, long]`

This function returns the user coordinates as an array of string where the first entry is the latitude and the second is the longitude. The coordinates can be used to activate some functionality depending on the user's location.

In case the wrapper mobile app, or the wrapper website can't get this values, the default `['0', '0']` is returned.

## The `bannerInjector` object

### `injectAdvertisementBanner(selectors: string[])`

The function injects the **`credits`** text and the **`sponsor logos`** specified in the Moment Class configuration window in the organizer dashboard.&#x20;

If your moment doesn't support branding, you will have to specify that in the [MANIFEST.json](/moments-sdk/documentation/the-project-setup.md#moment-manifest).&#x20;

**Params**:

1. **`selectors`**: list of CSS3 selectors in which the advertisement images will be injected.

{% tabs %}
{% tab title="index.html" %}

```markup
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Test</title>
  </head>
  <body>
    <div id="sponsorsAnchor1"></div>
  </body>
  <!-- Js Scripts Import -->
  <script src="https://stagecast.se/media/lib/mdk/stagecast.min.js"></script>
  <script src="./main.js"></stript>
</html>
```

{% endtab %}

{% tab title="main.js" %}

```javascript
const SDK = new Stagecast();
SDK.onConfigReceived(renderAds.bind(this)); 


renderAds() {
  const res = SDK
    .bannerInjector
    .injectAdvertisementBanner([
      '#sponsorsAnchor1' 
    ]);
  console.log(res); // prints: true
}

```

{% endtab %}

{% tab title="rendered index.html" %}

```markup
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Test</title>
  </head>
  <body>
    <div id="sponsorsAnchor1">
      <div class="scSponsorsBanner">
        <h3 class="scSponsorsCredits">The moment is presented by:</h3>
        <div class="scSponsorsList">
          <img src="link/to/content/1" />
          <img src="link/to/content/2" />
          ...
        </div>
      </div>
    </div>
  </body>
  <!-- Js Scripts Import -->
  <script src="https://stagecast.se/media/lib/mdk/stagecast.min.js"></script>
  <script src="./main.js"></stript>
</html>
```

{% endtab %}
{% endtabs %}
