A primer for the Stagecast Moment SDK. This client SDK is to be imported by your custom-made HTML-based Apps to interact with the Stagecast API Service and the Stagecast Messaging Service.
If you want to start coding right away, you can checkout the tutorial section and come back here later.
The basic functionalities are:
Wrap the http calls made towards the Stagecast public API service;
Wrap websocket messages to be sent via Stagecast Messaging Service;
Offer utilities to inject ads/logos and translate page content into different languages;
Provide some basic analytics library to track the user activity;
Support for multiple environments to improve the testing flow both locally and on production. In particular, there are 3 main environments a moment can run:
How To Use the MDK In Your Project
1. Import via CDN Link
Right now, the only supported way to import the Moment SDK, is via direct CDN link.
<!-- Fetch the library code from the Stagecast CDN -->
The constructor accepts an optional configuration object. However, most of the times, a major part of the configuration will be only accessible at runtime. In the latter case, the library can be instantiated without parameters.
3. Register a callback for the onConfigReceived event
A Moment is usually run inside a wrapper Webview or an iframe.
When the Moment gets loaded, the wrapper (ie. the Mobile App or an outer browser window) sends the runtime configuration to the Moment window.
Once the MDK has done instantiating, the onConfigReceivedevent is fired. This event is always called after the window.onload and can be considered as the entry point for your web app.
Of course, you can execute all the logic you want before the configuration is received. Usually the entry point is necessary to execute the runtime configurations that are only available only at last.
A simple hello world Moment may look like the following:
The configuration object schema looks like the following:
environment: the platform environment the Moment is running on (production or staging).
token: the user token to authenticate against the backend API service.
userId: the user email. It is generally used as a key to read and write to the Moment state. Each user has associated a bucket where the moment can save data.
momentClassData: the moment custom data provided at runtime and set by event organizer.
momentClassId: the moment class id. Each moment belongs to a moment class which defines its basic characteristics (name, category, version etc...). A moment can be seen as an instance of a MomentClass.
momentId: the moment id
eventId: the id of the event in which the moment are launched.
coordinates: the user latitude and longitude as provided by the device (if enabled by the user)
isGuest: flag that specifies whether the user is registered to stagecast or it is guest user. You can implement different custom logics based on this flag. However, most users will be guests, as we have dropped user registrations.
isActive: flag that specify whether the moment is currently live or has been stopped.
isMomentActive: same as above, kept for backward compatibility. Soon to be deprecated.
disableLogs: a flag used to disable all the window.console methods.
If the momentClassDatafield is left empty, the Moment SDK will try to fetch the data saved under themomentClassId key. This data is the one set in the moment configuration modal by the event organizer. If the field is not empty, SDK.getMomentData()will return a copy of the object specified in the configuration without calling any external API.
The configuration modal can be accessed via the Stagecast organizer web dashboard.