Class: Pili::Hub

Inherits:
Object
  • Object
show all
Defined in:
lib/pili/hub.rb

Overview

Hub 表示一个 Hub, 一个 Hub 包含多个 Stream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hub, client) ⇒ Hub

Returns a new instance of Hub.



8
9
10
11
12
# File 'lib/pili/hub.rb', line 8

def initialize(hub, client)
  @hub = hub
  @client = client
  @base_url = "#{Config.api_base_url}/hubs/#{hub}"
end

Instance Attribute Details

#hubObject (readonly)

Returns the value of attribute hub.



6
7
8
# File 'lib/pili/hub.rb', line 6

def hub
  @hub
end

Instance Method Details

#create(stream_key) ⇒ Object

创建一个流对象. 使用一个合法 rtmp_publish_url 发起推流就会自动创建流对象. 一般情况下不需要调用这个 API, 除非是想提前对这一个流做一些特殊配置.



17
18
19
20
# File 'lib/pili/hub.rb', line 17

def create(stream_key)
  @client.rpc.call_with_json("POST", "#{@base_url}/streams", {:key => stream_key})
  Stream.new(@hub, stream_key, @client)
end

#list(opt = {}) ⇒ Object

list 根据 prefix 遍历 Hub 的流列表.

参数:

limit 限定了一次最多可以返回的流个数, 实际返回的流个数可能小于这个 limit 值. marker 是上一次遍历得到的流标. omarker 记录了此次遍历到的游标, 在下次请求时应该带上, 如果 omarker 为 “” 表示已经遍历完所有流.

For example:

marker = ""
while true
  keys, marker = hub.list(:marker=> marker)
  # do something with keys.
  if marker == ""
    break
  end
end


56
57
58
59
# File 'lib/pili/hub.rb', line 56

def list(opt = {})
  opt[:liveonly] = false
  plist(opt)
end

#list_live(opt = {}) ⇒ Object

list 根据 prefix 遍历 Hub 正在播放的流列表.

参数:

limit 限定了一次最多可以返回的流个数, 实际返回的流个数可能小于这个 limit 值. marker 是上一次遍历得到的流标. omarker 记录了此次遍历到的游标, 在下次请求时应该带上, 如果 omarker 为 “” 表示已经遍历完所有流.

For example:

marker = ""
while true
  keys, marker = hub.list_live(:marker=> marker)
  # do something with keys.
  if marker == ""
    break
  end
end


79
80
81
82
# File 'lib/pili/hub.rb', line 79

def list_live(opt = {})
  opt[:liveonly] = true
  plist(opt)
end

#stream(stream_key) ⇒ Object

初始化一个流对象.



23
24
25
# File 'lib/pili/hub.rb', line 23

def stream(stream_key)
  Stream.new(@hub, stream_key, @client)
end

#to_jsonObject



88
89
90
# File 'lib/pili/hub.rb', line 88

def to_json
  {:hub=>@hub}.to_json
end

#to_sObject



84
85
86
# File 'lib/pili/hub.rb', line 84

def to_s
  "#<#{self.class} #{@hub}>"
end