class Pili::Stream

Attributes

hub[R]
title[R]

Public Class Methods

new(hub, title, client) click to toggle source
# File lib/pili/stream.rb, line 38
def initialize(hub, title, client)
  @hub = hub
  @title = title
  
  ekey = Base64.urlsafe_encode64(title)
  @base_url = "#{Config.api_base_url}/hubs/#{hub}/streams/#{ekey}"
  
  @client = client
end

Public Instance Methods

disable() click to toggle source

无限期禁用一个流.

# File lib/pili/stream.rb, line 55
def disable
  disable_till(-1)
end
disable_till(timestamp) click to toggle source

禁用一个流. 参数:

timestamp 解除禁用的时间戳
# File lib/pili/stream.rb, line 62
def disable_till(timestamp)
  @client.rpc.call_with_json("POST", "#{@base_url}/disabled", {:disabledTill=>timestamp})
end
enable() click to toggle source

启用一个流.

# File lib/pili/stream.rb, line 67
def enable
  @client.rpc.call_with_json("POST", "#{@base_url}/disabled", {:disabledTill=>0})
end
history_activity(opt = {}) click to toggle source

查询直播历史.

参数: start, end 是 Unix 时间戳, 限定了查询的时间范围, 0 值表示不限定, 系统会返回所有时间的直播历史.

返回:

{
  "start" => <Integer>,
  "end" => <Integer>
}
# File lib/pili/stream.rb, line 141
def history_activity(opt = {})
  url = "#{@base_url}/historyactivity"
  if !opt.empty?
    url += "?#{URI.encode_www_form opt}"
  end
  ret = @client.rpc.call_with_json("GET", url, nil)
  ret["items"]
end
info() click to toggle source

Info 获得流信息.

# File lib/pili/stream.rb, line 49
def info
  ret = @client.rpc.call_with_json("GET", @base_url, nil)
  StreamInfo.new @hub, @title, ret["disabledTill"], ret["converts"]
end
live_status() click to toggle source

查询直播状态.

返回

{
  "startAt" => <Integer>, # 直播开始的 Unix 时间戳, 0 表示当前没在直播.
  "clientIp" => <String>, #  直播的客户端 IP.
  "bps" => <Integer>, # 直播的码率、帧率信息.
  "fps" => {
    "audio" => <Integer>,
    "video" => <Integer>,
    "data" => <Integer>
  }
}
# File lib/pili/stream.rb, line 85
def live_status
  @client.rpc.call_with_json("GET", "#{@base_url}/live", nil)
end
saveas(opt = {}) click to toggle source

保存直播回放.

参数:

fname: 保存到存储空间的文件名,可选,不指定系统会随机生成
start: 整数,可选,Unix 时间戳,要保存的直播的起始时间,不指定或 0 值表示从第一次直播开始
end: 整数,可选,Unix 时间戳,要保存的直播的结束时间,不指定或 0 值表示当前时间
format: 保存的文件格式,可选,默认为m3u8,如果指定其他格式,则保存动作为异步模式
pipeline: 异步模式时,dora的私有队列,可选,不指定则使用公共队列
notify: 异步模式时,保存成功回调通知地址,可选,不指定则不通知
expireDays: 更改ts文件的过期时间,可选,默认为永久保存 -1表示不更改ts文件的生命周期,正值表示修改ts文件的生命周期为expireDays

返回:

fname: 字符串,表示保存后在存储空间里的文件名。
persistentID: 字符串,持久化异步处理任务ID,异步模式才会返回该字段,通常用不到该字段
# File lib/pili/stream.rb, line 103
def saveas(opt = {})
  ret = @client.rpc.call_with_json("POST", "#{@base_url}/saveas", opt)
  [ret["fname"], ret["persistentID"]]
end
snapshot(opt = {}) click to toggle source

保存直播截图

参数:

fname 保存到存储空间的文件名,可选,不指定系统会随机生成。
time 整数,可选,Unix 时间戳,要保存截图的时间点,不指定则为当前时间。
format 保存的文件格式,可选,默认为jpg。

返回:

fname => <String> # 字符串,表示保存后在存储空间里的文件名。
# File lib/pili/stream.rb, line 117
def snapshot(opt = {})
  ret = @client.rpc.call_with_json("POST", "#{@base_url}/snapshot", opt)
  ret["fname"]
end
to_json() click to toggle source
# File lib/pili/stream.rb, line 154
def to_json
  {:hub=>@hub, :key=>@title}.to_json
end
to_s() click to toggle source
# File lib/pili/stream.rb, line 150
def to_s
  "#<#{self.class} #{@hub}/#{@title}>"
end
update_converts(profiles) click to toggle source

修改流转码配置

参数:

profiles 字符串数组,元素为转码的分辨率如:720p, 480p
# File lib/pili/stream.rb, line 127
def update_converts(profiles)
  ret = @client.rpc.call_with_json("POST", "#{@base_url}/converts", :converts => profiles)
end