Setup
The are two ways to include LiveMarket SDK in your project - installation through npm
or yarn
or a classic browser <script>
tag. Depending on your setup, you have to make a decision on how you want to incorporate the SDK. The preffered way of using the SDK is with a bundler like webpack or rollup or in a Node.js environment. This is because these environments allow you to get type suggestions for LiveMarket’s entities and in case of bundlers - can remove code that is not used in your project.
Installation
Node / Bundlers
Install the package.
npm install livemarket-sdk
or
yarn add livemarket-sdk
Browser
Include the Livemarket SDK script tag on your page.
Self-hosting
<script src="PATH_TO_LIVEMARKET_SDK/dist/index.umd.min.js"></script>
CDN
<script src="???"></script>
Creating a client
In order to use LiveMarket SDK you first need to create a client.
Node / Bundlers setup
import { Client, FetchClientAdapter } from 'livemarket-sdk';
// const { Client, FetchClientAdapter } = require('livemarket-sdk');
const client = new Client(
token: '###YOUR_CLIENT_TOKEN###',
adapter: new FetchClientAdapter()
);
Browser script tag
const client = new LiveMarket.Client({
token: '###YOUR_CLIENT_TOKEN###',
adapter: new LiveMarket.FetchClientAdapter()
});
Important:
FetchClientAdapter
requires access to the Fetch API. In order to use this adapter in the Node environment, you need to polyfill it with something like node-fetch or isomorphic-unfetch.
Note: If you want to enable live chat for videos, you must also include pusher-js library in client’s options under
pusher
key or include it as a script tag before LiveMarketSDK on your page. You also need to providepusherKey
in client options.
Client options
The client contains a few options you can customize. See Client options.