linking

package
v7.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 10 Imported by: 0

README

Linking Cloud Server-Side Library for Go

Features

  • 设备管理

    • 添加新的设备: AddDevice(appid string, dev *Device)
    • 查询设备详细信息: QueryDevice(appid, device string)
    • 查询所有设备的列表: ListDevice(appid, prefix, marker string, limit int, online bool)
    • 查询设备的在线记录: ListDeviceHistoryactivity(appid, dev string, start, end int, marker string, limit int)
    • 更新设备配置: UpdateDevice(appid, device string, ops []PatchOperation)
    • 删除指定的设备: DeleteDevice(appid, device string)
  • 设备密钥管理

    • 新增设备密钥: AddDeviceKey(appid, device string)
    • 查询设备密钥: QueryDeviceKey(appid, device string)
    • 删除设备密钥: DeleteDeviceKey(appid, device, dak string)
    • 禁用、启用设备的密钥:UpdateDeviceKeyState(appid, device, dak string, state int)
    • 克隆设备: CloneDeviceKey(appid, fromdevice, todevice string, cleanSelfKeys, deleteDevice bool, deviceAccessKey string)
    • 通过设备 acceskey 查询设备 appid 和 device name: QueryAppidDeviceNameByAccessKey(dak string)
  • Vod

    • 视频片段查询: Segments(appid, device string, start, end int, marker string, limit int)
    • 视频片段进行收藏: Saveas(appid, device string, start, end int, fname, format string)
  • Dtoken

    • 视频回放/缩略图查询/倍速播放/延时直播/视频片段查询 Token 生成: VodToken(appid, device string, deadline int64)
    • 在线记录查询/设备查询 Token 生成: StatusToken(appid, device string, deadline int64)

Contents

Usage

Configuration
package main

import (
	// ...
	"github.com/qiniu/api.v7/v7/auth"
	"github.com/qiniu/api.v7/v7/linking"
)

var (
	AccessKey = "<QINIU ACCESS KEY>" // 替换成自己 Qiniu 账号的 AccessKey.
	SecretKey = "<QINIU SECRET KEY>" // 替换成自己 Qiniu 账号的 SecretKey.
	Appid   = "<Appid>"    // App 必须事先创建.
)

func main() {
	// ...
	mac := auth.New(testAccessKey, testSecretKey)
	manager := linking.NewManager(mac, nil)
	// ...
}
URL
Add Device
manager.AddDevice(Appid, dev)
Query Device
dev2, err := manager.QueryDevice(Appid, device)
List Device
devices, marker, err = manager.ListDevice(Appid, "sdk-testListDevice", "", 1000, false)
List Device history activity
segs, marker, err := manager.ListDeviceHistoryactivity(Appid, device, int(start), int(end), "", 1000)
Update Device
ops := []PatchOperation{
		PatchOperation{Op: "replace", Key: "segmentExpireDays", Value: 30},
	}
dev3, err := manager.UpdateDevice(Appid, device, ops)
Delete Device
manager.DeleteDevice(Appid, device)
Device Key
Add Device Key
manager.AddDeviceKey(Appid, device)
Query Deivce Key
keys, err := manager.QueryDeviceKey(Appid, device)
Delete Device Key
err := manager.DeleteDeviceKey(Appid, device, dak)
Update Device Key State
err = manager.UpdateDeviceKeyState(Appid, device, dak, 1)
Clone Device Key
keys, err := manager.CloneDeviceKey(Appid, device1, device2, false, false, dak1)
Query Appid Device By Device Key
appid, device, err := manager.QueryAppidDeviceNameByAccessKey(dak)
Vod
Get Segments
end := time.Now().Unix()
start := time.Now().Add(-time.Hour).Unix()
segs, marker, err := manager.Segments(Appid, device, int(start), int(end), "", 1000)
Saveas
end := time.Now().Unix()
start := time.Now().Add(-time.Hour).Unix()
saveasReply, _ := manager.Saveas(Appid, device, int(start), int(end), "testSaveas.mp4", "mp4")
Dtoken
Get Vod Token
token, err := manager.VodToken(Appid, device, time.Now().Add(time.Hour*5).Unix())
fmt.Println(token)
Get Status Token
time.Sleep(time.Second)
token, err := manager.VodToken(Appid, device, time.Now().Add(time.Hour*5).Unix())
noError(t, err)
fmt.Println(token)

视频播放相关 api 编程模型说明: 如用户请求视频相关api(例如:https://developer.qiniu.com/linking/api/5650/playback)时进行业务服务器中转,会造成访问路径比较长, 因此建议服务端只进行dtoken的签算并提供给播放端,播放端直接请求视频播放相关的API,提升播放体验。 具体下token签算参考 https://developer.qiniu.com/linking/api/5680/the-signature-in-the-url WeChatWorkScreenshot_c6c3e265-5ca3-48d9-8cc5-c40343506eeb

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIHTTPScheme = "http://"

APIHTTPScheme 指定了在请求 API 服务器时使用的 HTTP 模式.

View Source
var APIHost = "linking.qiniuapi.com/v1"

APIHost 指定了 API 服务器的地址

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Channelid int    `json:"channelid"`
	Comment   string `json:"comment"`
}

type DevResponse

type DevResponse struct {
	ErrorCode int             `json:"errorCode,omitempty"`
	Error     string          `json:"error,omitempty"`
	Value     json.RawMessage `json:"value,omitempty"`
}

type Device

type Device struct {
	Device   string `json:"device"`
	LoginAt  int64  `json:"loginAt,omitempty"`  // 查询条件 online 为 true 时才会出现该字段
	RemoteIp string `json:"remoteIp,omitempty"` // 查询条件 online 为 true 时才会出现该字段
	// 0 不录制
	// -1 永久
	// -2 继承app配置
	SegmentExpireDays int `json:"segmentExpireDays,has,omitempty"`

	// -1 继承app配置
	// 0 遵循设备端配置
	// 1 强制持续上传
	// 2 强制关闭上传
	UploadMode int `json:"uploadMode,has,omitempty"`

	State int `json:"state,omitempty"`

	ActivedAt int64 `json:"activedAt,omitempty"`
	CreatedAt int64 `json:"createdAt,omitempty"`
	UpdatedAt int64 `json:"updatedAt,omitempty"`

	// 1 免费使用
	// 0 正常收费
	LicenseMode int `json:"licenseMode,omitempty"`

	// meta data
	Meta []byte `json:"meta,omitempty"`

	// device type 0:normal type, 1:gateway
	Type int `json:"type"`
	// max channel of gateway [1,64]
	MaxChannel int       `json:"maxChannel,omitempty"`
	Channels   []Channel `json:"channels,omitempty"`
}

type DeviceAccessToken

type DeviceAccessToken struct {
	Appid     string      `json:"appid"`     // appId
	Device    string      `json:"device"`    // device name
	DeadLine  int64       `json:"deadline"`  // 该token的有效期截止时间
	Random    int64       `json:"random"`    // 随机数,保证DEVICE ACCESS TOKEN全局唯一
	Statement []Statement `json:"statement"` // 针对那种功能进行授权
}

设备访问凭证

type DeviceHistoryItem

type DeviceHistoryItem struct {
	LoginAt      int64  `json:"loginAt"`
	LogoutAt     int64  `json:"logoutAt"`
	RemoteIp     string `json:"remoteIp,omitempty"`
	LogoutReason string `json:"logoutReason,omitempty"`
}

----------------------------------------------------------------------------- 历史记录

type DeviceKey

type DeviceKey struct {
	AccessKey string `json:"accessKey"` // 设备的 accessKey
	SecretKey string `json:"secretKey"` // 设备的 secretkey
	State     int    `json:"state"`     // 密钥对状态,1表示被禁用,0表示已启用
	CreatedAt int64  `json:"createdAt"` // 创建时间
}

设备密钥管理

type LiveRequest

type LiveRequest struct {
	Appid      string `json:"appid"`
	DeviceName string `json:"deviceName"`
	PublishIP  string `json:"publishIP"`
	PlayIP     string `json:"playIP"`
}

type LiveResponse

type LiveResponse struct {
	PublishUrl string   `json:"publishUrl"`
	PlayUrls   PlayUrls `json:"playUrls"`
}

type M

type M map[string]interface{}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 代表一个 linking 用户的客户端

func NewManager

func NewManager(mac *auth.Credentials, tr http.RoundTripper) *Manager

New 初始化 Client.

func (*Manager) AddDevice

func (manager *Manager) AddDevice(appid string, dev *Device) (*Device, error)

在指定的应用下添加新的设备

func (*Manager) AddDeviceKey

func (manager *Manager) AddDeviceKey(appid, device string) ([]DeviceKey, error)

新增设备的密钥,每个设备最多有两对密钥

func (*Manager) CloneDeviceKey

func (manager *Manager) CloneDeviceKey(appid, fromdevice, todevice string, cleanSelfKeys, deleteDevice bool, deviceAccessKey string) ([]DeviceKey, error)

某个设备的密钥克隆给新的设备,不用重新对设备进行烧录新的密钥

func (*Manager) DeleteDevice

func (manager *Manager) DeleteDevice(appid, device string) error

删除指定的设备,删除后将不可恢复

func (*Manager) DeleteDeviceKey

func (manager *Manager) DeleteDeviceKey(appid, device, dak string) error

删除设备的密钥

func (*Manager) ListDevice

func (manager *Manager) ListDevice(appid, prefix, marker string, limit int, online, status bool, deviceType int, batch string) ([]Device, string, error)

查询指定应用下所有设备的列表

func (*Manager) ListDeviceHistoryactivity

func (manager *Manager) ListDeviceHistoryactivity(appid, dev string, start, end int, marker string, limit int) ([]DeviceHistoryItem, string, error)

查询指定时间段内设备的在线记录

func (*Manager) QueryAppidDeviceNameByAccessKey

func (manager *Manager) QueryAppidDeviceNameByAccessKey(dak string) (string, string, error)

func (*Manager) QueryDevice

func (manager *Manager) QueryDevice(appid, device string) (*Device, error)

查询指定设备的详细信息

func (*Manager) QueryDeviceKey

func (manager *Manager) QueryDeviceKey(appid, device string) ([]DeviceKey, error)

查询指定设备的密钥

func (*Manager) RPC

func (manager *Manager) RPC(appid, device string, req *RpcRequest) (*RpcResponse, error)

func (*Manager) Saveas

func (manager *Manager) Saveas(appid, device string, start, end int, fname, format string) (*SaveasReply, error)

指定的视频片段进行收藏,保存在云存储上

func (*Manager) Segments

func (manager *Manager) Segments(appid, device string, start, end int, marker string, limit int) ([]Segment, string, error)

视频片段查询

func (*Manager) StartLive

func (manager *Manager) StartLive(req *LiveRequest) (*LiveResponse, error)

指定的视频片段进行收藏,保存在云存储上

func (*Manager) Stat

func (manager *Manager) Stat(req *StatReq) ([]M, error)

func (*Manager) StatusToken

func (manager *Manager) StatusToken(appid, device string, deadline int64) (string, error)

在线记录查询/设备查询 Token

func (*Manager) Token

func (manager *Manager) Token(appid, device string, deadline int64, actions []Statement) (string, error)

func (*Manager) UpdateDevice

func (manager *Manager) UpdateDevice(appid, device string, ops []PatchOperation) (*Device, error)

更新设备配置信息的操作

func (*Manager) UpdateDeviceKeyState

func (manager *Manager) UpdateDeviceKeyState(appid, device, dak string, state int) error

禁用、启用设备的密钥

func (*Manager) VodToken

func (manager *Manager) VodToken(appid, device string, deadline int64) (string, error)

视频回放/缩略图查询/倍速播放/延时直播/视频片段查询 Token

type PatchOperation

type PatchOperation struct {
	Op    string      `json:"op"`    // 更该或删除某个属性,replace:更改,delete:删除
	Key   string      `json:"key"`   // 要修改或删除的属性
	Value interface{} `json:"value"` // 要修改或删除属性的值
}

type PlayUrls

type PlayUrls struct {
	Rtmp string `json:"rtmp"`
	Hls  string `json:"hls"`
	Flv  string `json:"flv"`
}

type RpcRequest

type RpcRequest struct {
	Action   int             `json:"action"`
	Params   json.RawMessage `json:"params,omitempty"`
	Timeout  int             `json:"timeout,omitempty"`
	Response bool            `json:"response,omitempty"`
}

----------------------------------------------------------------------------- mqtt rpc

type RpcResponse

type RpcResponse struct {
	Id   string      `json:"id"`
	Resp DevResponse `json:"response"`
}

type SaveasReply

type SaveasReply struct {
	Fname       string `json:"fname"`
	PersistenId string `json:"persistentId,omitempty"`
	Duration    int    `json:"duration"` // ms
}

type Segment

type Segment struct {
	From  int    `json:"from"`
	To    int    `json:"to"`
	Frame string `json:"frame"`
}

type StatReq

type StatReq struct {
	Start  int    `form:"start"`
	End    int    `form:"end"`
	Group  string `form:"g"`
	Select string `form:"select"`
}

查询活跃设备信息

type Statement

type Statement struct {
	Action string `json:"action"`
}

Jump to

Keyboard shortcuts

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