The chat SDK can be installed from either NPM or Bower, depending on your intended usage.
If you are integrating into a classical JavaScript project and you just want to include a script that exposes some global objects in your page, then use Bower.
If you are using a project that utilises ES6 modules, such as angular2 or ionic2, then use NPM.
Bower
1. Install package from Bower
bower install comapi-sdk-js-chat
2. Include the script
<script src="bower_components/comapi-sdk-js-chat/dist/comapi-chat-client.js"></script>
There is also a minified version comapi-chat-client.min.js
available.
For all subsequent classical snippets, we assume that this script has been included.
3. Access SDK methods
console.log("Comapi version: " + COMAPI_CHAT.ComapiChatClient.version);
NPM
1. Install SDK
npm install @comapi/sdk-js-chat --save
2. Import into your code and access SDK methods
import { ComapiChatClient } from "@comapi/sdk-js-chat"
class MyClass{
public displayVersion(){
console.log(`Comapi version: ${ComapiChatClient.version}`);
}
}
Use of ES6 Promises
ES6 Promises are extensively used within this SDK. Depending on what browsers you are targeting, you might need to include a poly-fill for this. Several of these are available online.