This video (narrated in Ukrainian by Borys our backend architect engineer) demonstrates integrating Ethora chat with your existing backend.
Endpoint request examples are shown.
Javascript code sample:
const jwt = require("jsonwebtoken")
// example of secret
const secret = 'YOUR_APP_SECRET'
const appId = 'YOUR_APP_ID'
const craeteServerToken = function() {
return jwt.sign({data: {appId, type: 'server'}}, secret, {
// expiresIn: 60000,
algorithm: 'HS256'
})
}
function createClientToken(userId) {
return jwt.sign(
// jwt payload should include current userId & appId
{data: {type: 'client', userId: userId, appId: appId}},
// only backend should know secret
secret,
// token options
{
expiresIn: 480,
algorithm: 'HS256'
})
}
console.log("server token ", craeteServerToken())
console.log("client token ", createClientToken("mock4"))
Also attached below is a Postman file demonstrating server token and client token generation.