Skip to content

geeklok/pili-sdk-ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pili Streaming Cloud server-side library for Ruby

Features

  • URL
    • RTMP推流地址: rtmp_publish_url(domain, hub, stream_key, mac, expire_after_seconds)
    • RTMP直播地址: rtmp_play_url(domain, hub, stream_key)
    • HLS直播地址: hls_play_url(domain, hub, stream_key)
    • HDL直播地址: hdl_play_url(domain, hub, stream_key)
    • 截图直播地址: snapshot_play_url(domain, hub, stream_key)
  • Hub
    • 创建流: hub.create(stream_key)
    • 获得流: hub.stream(stream_key)
    • 列出流: hub.list(...)
    • 列出正在直播的流: hub.list_live(...)
  • Stream
    • 流信息: stream.info()
    • 禁用流: stream.disable()
    • 启用流: stream.enable()
    • 查询直播状态: stream.live_status()
    • 保存直播回放: stream.save(...)
    • 查询直播历史: stream.history_activity(...)

Contents

Installation

Add this line to your application's Gemfile:

gem 'piliv2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install piliv2

Usage

Configuration

require "piliv2"

access_key = "<QINIU ACCESS KEY>" # 替换成自己 Qiniu 账号的 AccessKey.
secret_key = "<QINIU SECRET KEY>" # 替换成自己 Qiniu 账号的 SecretKey.
hub_name   = "<PILI HUB NAME>"    # Hub 必须事先存在.

mac = Pili::Mac.new(access_key, secret_key)
client = Pili::Client.new(mac)
hub = client.hub(hub_name)

URL

Generate RTMP publish URL

url = Pili.rtmp_publish_url("publish-rtmp.test.com", "PiliSDKTest", "streamkey", mac, 60)
puts(url)
# rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=

Generate RTMP play URL

url = Pili.rtmp_play_url("live-rtmp.test.com", "PiliSDKTest", "streamkey")
puts(url)
# rtmp://live-rtmp.test.com/PiliSDKTest/streamkey

Generate HLS play URL

url = Pili.hls_play_url("live-hls.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-hls.test.com/PiliSDKTest/streamkey.m3u8

Generate HDL play URL

url = Pili.hdl_play_url("live-hdl.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-hdl.test.com/PiliSDKTest/streamkey.flv

Generate Snapshot play URL

url = Pili.snapshot_play_url("live-snapshot.test.com", "PiliSDKTest", "streamkey")
puts(url)
# http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg

Hub

Instantiate a Pili Hub object

mac = Pili::Mac.new(access_key, secret_key)
client = Pili::Client.new(mac)
hub = client.hub("PiliSDKTest")

Create a new Stream

stream = hub.create("streamkey")
puts(stream.info.to_json)
# {"hub":"PiliSDKTest","key":"streamkey","disabled":false}

Get a Stream

stream = hub.stream("streamkey")
puts(stream.info.to_json)
# {"hub":"PiliSDKTest","key":"streamkey","disabled":false}

List Streams

keys, marker = hub.list(:prefix=>"str", :limit=>10)
puts keys.to_s, marker
# [<keys...>], <marker>

List live Streams

keys, marker = hub.list_live(:prefix=>"str", :limit=>10)
puts keys.to_s, marker
# [<keys...>], <marker>

Stream

Get Stream info

stream = hub.stream(key)
puts(stream.info.to_json)
# {"hub": "PiliSDKTest", "key": "streamkey", "disabled": false}

Disable a Stream

stream = hub.stream("streamkey")
puts("before disable: #{stream.info.to_json}")

stream.disable()

stream = hub.stream("streamkey")
puts("after disable: #{stream.info.to_json}")
# before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}
# after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}

Enable a Stream

stream = hub.stream("streamkey")
puts("before enable: #{stream.info.to_json}")

stream.enable()

stream = hub.get("streamkey")
puts("after enable: #{stream.info.to_json}")
# before disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":true}
# after disable: {"hub":"PiliSDKTest","key":"streamkey","disabled":false}

Get Stream live status

status = stream.live_status()
puts(status.to_json)
# {"startAt":1463022236,"clientIP":"222.73.202.226","bps":248,"fps":{"audio":45,"vedio":28,"data":0}}

Get Stream history activity

activity = stream.history_activity()
puts(activity.to_json)
# [{"start":1463022236,"end":1463022518}]

Save Stream live playback

fname = stream.save()
puts(fname)
# recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.m3u8

About

Pili Streaming Cloud server-side library for Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%