aliyun-live-go-sdk/

directory
v1.5.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: MIT, Apache-2.0

README

aliyun-live-go-sdk Build Status Coverage Status

阿里云直播 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推流地址
    // RTMP 推流地址
    // 如果开启了直播流鉴权,签名失效后,会重新生成新的有效的推流地址
    stream.RtmpPublishUrl()
  • RTMP 直播播放地址
    url:=stream.RtmpLiveUrls()
  • HLS 直播播放地址
    url:=stream.HlsLiveUrls()
  • FLV 直播播放地址
    url:=stream.HttpFlvLiveUrls()
  • 获取在线人数
    num:=stream.OnlineUserNum()
  • 是否在线
    isOnline:=stream.Online()
  • 是否被禁止
    isBlocked:=stream.Blocked()

录制(待完成)

贡献参与者

License

采用 Apache License, Version 2.0许可证授权原则。

参考文献

参考项目: https://github.com/denverdino/aliyungo

Directories

Path Synopsis
client 包 核心代码包,请求相关代码, 如:client request response 其中也包括整个sdk的一下基本信息 @author cbping
client 包 核心代码包,请求相关代码, 如:client request response 其中也包括整个sdk的一下基本信息 @author cbping
device
cdn
cdn CDN服务Api @author cbping
cdn CDN服务Api @author cbping
live
阿里云直播API 文档信息:https://help.aliyun.com/document_detail/27191.html?spm=0.0.0.0.60u2Ny @author cbping
阿里云直播API 文档信息:https://help.aliyun.com/document_detail/27191.html?spm=0.0.0.0.60u2Ny @author cbping

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL