class VidyoIo::Util::Token
Constants
- EPOCH_SECONDS
Public Class Methods
generate(username: 'user1', ttl: 3600)
click to toggle source
Creates a token to start a video call
@param [String] username Username to connec to the call @param [Integer] ttl 'Time to live' indicates how long the token will be valid for @return [String] A valid token to start a video call
# File lib/vidyo_io/util/token.rb, line 13 def self.generate(username: 'user1', ttl: 3600) jid = "#{username}@#{Configuration.application_id}\0" timestamp = Time.now.to_i + ttl + EPOCH_SECONDS type = "provision\0" body = "#{type}#{jid}#{timestamp}\0" mac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha384'), Configuration.developer_key, body) mac = BinASCII.hexlify(mac) Base64.strict_encode64("#{body}\0#{mac}".encode('utf-8')) end