aliyun-live-go-sdk
阿里云直播 golang SDK
快速开始
package main
import (
"gitee.com/wuzheng0709/backend-gopkg/infrastructure/pkg/live/aliyun-live-go-sdk/client"
"gitee.com/wuzheng0709/backend-gopkg/infrastructure/pkg/live/aliyun-live-go-sdk/device/live"
"gitee.com/wuzheng0709/backend-gopkg/infrastructure/pkg/live/aliyun-live-go-sdk/util"
"time"
"fmt"
)
const (
AccessKeyId = "<Yours' Id>"
AccessKeySecret = "<...>"
)
func main() {
cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
live := live.NewLive(cert, "<Yours' CDN>", "app-name",nil).SetDebug(true)
resp := make(map[string]interface{})
live.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
}
构建安装
go get:
go get go-micro/lib/util/live/aliyun-live-go-sdk
文档
Example
直播(Live)
方法名以"WithApp"结尾代表可以更改请求中 "应用名字(AppName)",否则按默认的(初始化时设置的AppName)。
如果为空,代表忽略参数AppName
cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
liveM := live.NewLive(cert, DomainName, AppName, nil).SetDebug(true)
resp := make(map[string]interface{})
liveM.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
// @appname 应用名 为空时,忽略此参数
resp := make(map[string]interface{})
liveM.StreamsPublishListWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(resp)
resp = make(map[string]interface{})
err = liveM.StreamsBlockList(&resp)
fmt.Println(err, resp)
resp1 := live.OnlineInfoResponse{}
err := liveM.StreamOnlineUserNum("video-name", &resp1)
fmt.Println(err, resp1)
// @appname 应用名 为空时,忽略此参数
resp1 := live.OnlineInfoResponse{}
err := liveM.StreamOnlineUserNumWithApp(AppName,"video-name", &resp1)
fmt.Println(err, resp1)
resp = make(map[string]interface{})
err = liveM.StreamsControlHistory(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
//err = liveM.StreamsControlHistoryWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err = liveM.ForbidLiveStreamWithPublisher("video-name", nil, &resp)
fmt.Println(err, resp)
resp = make(map[string]interface{})
err = liveM.ResumeLiveStreamWithPublisher("video-name", &resp)
fmt.Println(err, resp)
流(Stream)
//如果 streamCert 为空的话,则代表不开启直播流鉴权
cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
streamCert := live.NewStreamCredentials(PrivateKey, live.DefualtStreamTimeout)
liveM := live.NewLive(cert, DomainName, AppName, streamCert)
// GetStream 获取直播流
// @describe 每一次都生成新的流实例,不检查流名的唯一性,并且同一个名字会生成不同的实例的,
// 所以,使用时候,请自行确保流名的唯一性
stream := liveM.GetStream("video-name")
// RTMP 推流地址
// 如果开启了直播流鉴权,签名失效后,会重新生成新的有效的推流地址
stream.RtmpPublishUrl()
url:=stream.RtmpLiveUrls()
url:=stream.HlsLiveUrls()
url:=stream.HttpFlvLiveUrls()
num:=stream.OnlineUserNum()
isOnline:=stream.Online()
isBlocked:=stream.Blocked()
录制(待完成)
贡献参与者
License
采用 Apache License, Version 2.0许可证授权原则。
参考文献
参考项目: https://github.com/denverdino/aliyungo