Changelog on v3.4.1
SDK URL
https://app.straas.net/sdk/3.4.1/player-sdk.js
Improvements
The player now shows the proper error message and triggers the "onError" event when encountering network-related errors.
For example, if the backend server responses the HTTP error with status code "429", it will prompt the end-user to try again later for overloading of the server right now.
The schema of the parameter of the "onError" event passed to the player constructor has the following form:
{
"target": <object> "The player instance triggering the event"
"data": {
"code": <number> Reference: https://developer.mozilla.org/en-US/docs/Web/API/MediaError
"straasErrorCode": <string> "The constant string code represents the error state"
"message": <string> "The default user-friendly error message"
}
}
Example:
async function initPlayer() {
const response = await window.fetch('https://demo.straas.net/api/apptoken')
if (!response.ok) {
throw new Error('Get app token failed')
}
const data = await response.json()
window['StraaSOnInit'] = function () {
const StraaS = window.StraaS
const Player = StraaS.Player
const playerInstance = new Player('#player', {
type: Player.Type.VIDEO,
id: 'iqFDrEw7',
accountId: 'demo.straas.io-test',
appToken: data.token,
events: {
onError: function playerError(e) {
if ( e.data.straasErrorCode === "CMS_API_REQUEST_TOO_MANY_REQUESTS" ) {
// do something like retry
}
}
}
})
}
}
initPlayer()