Krishna Mohan, the link you have given clearly points this out:
“generateEmbedToken() is a function you need to implement, it calls the application Back End and returns the Embed Token”
So, the actual responsibility of generating the access/embed token lies with the backend/server and it’s not exposed in the JavaScript SDK as far as i know. This links also reiterates this part that the backend application needs to generate the token.
For everyone’s convenience, i have created a github gist of the backend code that generates the token and also checks for token validity. If the existing token is valid, it returns the same otherwise it generates a new token. This is better than the JavaScript code you shared as it’s not really checking the token validity but only the time since the last token was generated. Here’s the gist link:
https://gist.github.com/ramandeep-singh-1983/0350b22130884ecefdb54f41a92ba232