Class: Wowza::SecureToken::Params
- Inherits:
-
Object
- Object
- Wowza::SecureToken::Params
- Defined in:
- lib/wowza/secure_token.rb
Overview
Wraps a params hash in the sorting and hashing logic necessary to generate a Wowza secure token
Instance Method Summary collapse
-
#initialize(opts) ⇒ Params
constructor
Create the wrapper required symbol keys for: - stream - secret - client_ip - prefix - starttime (Integer) - endtime (Integer) - playstart (Integer) - playduration (Integer).
-
#to_token ⇒ Object
The sorted token string for the wrapped params.
-
#to_token_hash(digest_alg = Digest::SHA256) ⇒ Object
A URL-safe B64 encoded hash.
- #to_url_with_token_hash(host, port, stream_type) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Params
Create the wrapper required symbol keys for:
-
stream
-
secret
-
client_ip
-
prefix
-
starttime (Integer)
-
endtime (Integer)
-
playstart (Integer)
-
playduration (Integer)
24 25 26 27 28 29 30 |
# File 'lib/wowza/secure_token.rb', line 24 def initialize(opts) @prefix = opts.delete(:prefix) @stream = opts.delete(:stream) @client_ip = opts.delete(:client_ip) @secret = opts.delete(:secret) @params = opts end |
Instance Method Details
#to_token ⇒ Object
Returns the sorted token string for the wrapped params.
33 34 35 36 |
# File 'lib/wowza/secure_token.rb', line 33 def to_token query_string = params_to_sorted_query_string(prefix_params(@params).merge(@client_ip => nil, @secret => nil)) "#{@stream}?#{query_string}" end |
#to_token_hash(digest_alg = Digest::SHA256) ⇒ Object
Returns a URL-safe B64 encoded hash.
40 41 42 |
# File 'lib/wowza/secure_token.rb', line 40 def to_token_hash(digest_alg = Digest::SHA256) Base64.urlsafe_encode64(digest_alg.digest(to_token)) end |
#to_url_with_token_hash(host, port, stream_type) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wowza/secure_token.rb', line 44 def to_url_with_token_hash(host, port, stream_type) query_string = params_to_sorted_query_string(prefix_params(@params)) case stream_type when 'hls', 'hls-ssl' (stream_type == 'hls' ? 'http' : 'https') + "://#{host}:#{port}/#{@stream}/playlist.m3u8?#{query_string}&#{@prefix}hash=#{self.to_token_hash}" when 'mpeg-dash', 'mpeg-dash-ssl' (stream_type == 'mpeg-dash' ? 'http' : 'https') + "://#{host}:#{port}/#{@stream}/manifest.mpd?#{query_string}&#{@prefix}hash=#{self.to_token_hash}" when 'rtmp', 'rtmps' "#{stream_type}://#{host}:#{port}/#{@stream}?#{query_string}&#{@prefix}hash=#{self.to_token_hash}" else raise "Unsupported stream_type: #{stream_type}" end end |