StomioSDK Class
The StomioSDK class is the primary class of the Stomio WebSDK. An instance is created when importing the library, and it is exported, providing access to the instance.
Methods
init
Initializes the StomioSDK instance and creates a session in Stomio.
Params:
- project
(string, required): project SDK token. Obtain it from theDev Infosection of your project in your Stomio account. - user
(string, optional): user security token. Returns: void
createWidget
Creates an instance of the StomioWidget class.
Params:
- verticalPosition
(string, optional):'top'|'bottom'. Default'bottom' - horizontalPosition
(string, optional):'left'|'right'. Default'right' - mode
(string, optional):'manual'|'floatingButton'. Default'floatingButton'Returns:StomioWidgetinstance
Other Topics
User Security Token
To prevent malicious third parties from sending data to Stomio on behalf of your users, implement a small server-side function that creates a token signed by your Secret Key.
In your backend:
const jwt = require('jsonwebtoken')
const SECRET_KEY = 'SECRET_KEY' // replace with your secret key
function createUserSecurityToken() {
const userData = {
email: 'USER_EMAIL', // replace with your user email
}
return jwt.sign(userData, SECRET_KEY, { algorithm: 'HS256' })
}
In your web application:
await stomio.init({
project: 'PROJECT_TOKEN',
user: userSecurityToken
})
User Security Token Backend Examples
Node.js
npm install jsonwebtoken
const jwt = require('jsonwebtoken')
const SECRET_KEY = 'SECRET_KEY'
function createUserSecurityToken() {
const userData = { email: 'USER_EMAIL' }
return jwt.sign(userData, SECRET_KEY, { algorithm: 'HS256' })
}
Python
pip install pyjwt
import jwt
SECRET_KEY = 'SECRET_KEY'
def create_user_security_token():
user_data = { 'email': 'USER_EMAIL' }
return jwt.encode(user_data, SECRET_KEY, algorithm='HS256')
Ruby
gem install jwt
require 'jwt'
SecretKey = 'SECRET_KEY'
def createUserSecurityToken()
userData = { email: 'USER_EMAIL' }
JWT.encode(userData, SecretKey, 'HS256')
end
Java
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.Jwts;
import java.util.HashMap;
public class UserSecurityTokenFactory {
private static final String SecretKey = "SECRET_KEY";
public static String createToken() throws Exception {
HashMap<String, Object> userData = new HashMap<>();
userData.put("email", "USER_EMAIL");
return Jwts.builder()
.setClaims(userData)
.signWith(SignatureAlgorithm.HS256, SecretKey.getBytes("UTF-8"))
.compact();
}
}
PHP
composer require firebase/php-jwt
use \Firebase\JWT\JWT;
const SecurityKey = 'SECRET_KEY';
function createUserSecurityToken() {
$userData = ['email' => 'USER_EMAIL'];
return JWT::encode($userData, SecurityKey, 'HS256');
}
StomioWidget Class
The StomioWidget class manages the Stomio Widget. An instance is created by calling stomio.createWidget().
Methods
open: Opens the Stomio Widget.
close: Closes the Stomio Widget.
toggle: Opens or closes the Stomio Widget.