client

package
v0.0.0-...-3deab84 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceModelJC120  = 1
	DeviceModelJC170  = 2
	DeviceModelJC200  = 3
	DeviceModelJC400  = 4
	DeviceModelJC400P = 5
	DeviceModelJC400D = 6
	DeviceModelJC450  = 7
)
View Source
const (
	RedisServerFlagIDKey = "jimi.iothub.flagid"
	RedisRequestIDKey    = "jimi.iothub.requestid"
)
View Source
const (
	HttpFLVLiveLinkFormat    = "{{FlvAddress}}/{{Prefix}}/{{channel}}/{{IMEI}}.flv"
	HttpFLVHistoryLinkFormat = "{{FlvAddress}}/{{channel}}/{{IMEI}}.history.flv"
	HttpFLVReplayLinkFormat  = "{{FlvAddress}}/{{Prefix}}/{{IMEI}}.flv"
	RtmpLiveLinkFormat       = "{{RtmpAddress}}/{{Prefix}}/{{channel}}/{{IMEI}}"
)

Variables

View Source
var (
	ErrUnsupportedRequest = errors.New("request not supported by device model")
	ErrEmptyCmdContent    = errors.New("command content is empty")
)
View Source
var DeviceModelNames = map[DeviceModel]string{
	DeviceModelJC120:  "JC120",
	DeviceModelJC170:  "JC170",
	DeviceModelJC200:  "JC200",
	DeviceModelJC400:  "JC400",
	DeviceModelJC400P: "JC400P",
	DeviceModelJC400D: "JC400D",
	DeviceModelJC450:  "JC450",
}
View Source
var DeviceModelValues = map[string]DeviceModel{
	"JC120":  DeviceModelJC120,
	"JC170":  DeviceModelJC170,
	"JC200":  DeviceModelJC200,
	"JC400":  DeviceModelJC400,
	"JC400P": DeviceModelJC400P,
	"JC400D": DeviceModelJC400D,
	"JC450":  DeviceModelJC450,
}
View Source
var (
	ErrNilConfig = errors.New("config should not be nil")
)

Functions

func GenerateFLVHistoryLink(secure bool, endpoint string, channel int, imei string) (string, error)

GenerateFLVHistoryLink generates flv history video link Example: http://120.78.224.93:8881/3/868120303960873.history.flv

func GenerateFLVLiveLink(secure bool, endpoint, prefix string, channel int, imei string) (string, error)

GenerateFLVLiveLink generates flv live video link Example: http://example.com:8881/live/0/86271111111111.flv

func GenerateFLVReplayLink(secure bool, endpoint string, prefix string, imei string) (string, error)

GenerateFLVReplayLink generates flv history video link for replay list Example: http://example.com:8881/live/868120303960873.flv

func GenerateRtmpLiveLink(secure bool, endpoint, prefix string, channel int, imei string) (string, error)

GenerateRtmpLiveLink generates rtmp video link Example: rtmp://example.com:1936/live/0/86271111111111

Types

type AVResourceListCmdContent

type AVResourceListCmdContent struct {
	Channel       uint8                   `json:"channel"`
	BeginTime     string                  `json:"beginTime"`
	EndTime       string                  `json:"endTime"`
	AlarmFlag     uint64                  `json:"alarmFlag"`
	ResourceType  ResourcesType           `json:"resourceType"`
	CodeType      ResourceListCodeType    `json:"codeType"`
	StorageType   ResourceListStorageType `json:"storageType"`
	InstructionID string                  `json:"instructionID"`
}
type DeviceConfigLinks struct {
	RtmpAddress    string
	HttpUploadLink string
}

type DeviceModel

type DeviceModel uint8

type ForwardRewind

type ForwardRewind string
const (
	ForwardRewindInvalid ForwardRewind = "0"
	ForwardRewindX1      ForwardRewind = "1"
	ForwardRewindX2      ForwardRewind = "2"
	ForwardRewindX4      ForwardRewind = "3"
	ForwardRewindX8      ForwardRewind = "4"
	ForwardRewindX16     ForwardRewind = "5"
)

type InstructRequest

type InstructRequest struct {
	DeviceIMEI   string             `url:"deviceImei,required"`
	ServerFlagID int64              `url:"serverFlagId,required"`
	ProNo        ProNumber          `url:"proNo,required"`
	Platform     RequestPlatform    `url:"platform,required"`
	RequestID    int64              `url:"requestId,required"`
	CmdContent   string             `url:"cmdContent,required"`
	CmdType      RequestCommandType `url:"cmdType"`
	Language     string             `url:"language"`
	Sync         bool               `url:"sync"`
	OfflineFlag  bool               `url:"offlineFlag"`
	Timeout      int                `url:"timeOut"`
	Token        string             `url:"token"`
}

type IotHubClient

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

func NewIotHubClient

func NewIotHubClient(config *IotHubConfig) (*IotHubClient, error)

func (*IotHubClient) Client

func (cli *IotHubClient) Client() *resty.Client

Client returns the client.

func (*IotHubClient) Config

func (cli *IotHubClient) Config(canModify bool) *IotHubConfig

Config returns the client config.

func (*IotHubClient) DeviceInstructionRequest

func (cli *IotHubClient) DeviceInstructionRequest(ctx context.Context, imei string, command string) (*InstructRequest, error)

func (*IotHubClient) EndpointURL

func (cli *IotHubClient) EndpointURL() *url.URL

EndpointURL returns the URL of the endpoint.

func (cli *IotHubClient) GenerateDeviceConfigLinks(rtmpPrefix string) *DeviceConfigLinks
func (cli *IotHubClient) GenerateFLVHistoryLink(secure bool, channel int, imei string) (string, error)
func (cli *IotHubClient) GenerateFLVReplayLink(secure bool, prefix string, imei string) (string, error)
func (cli *IotHubClient) GenerateFlvLiveLink(secure bool, prefix string, channel int, imei string) (string, error)
func (cli *IotHubClient) GenerateRtmpLiveLink(secure bool, prefix string, channel int, imei string) (string, error)
func (cli *IotHubClient) GenerateVideoLinks(secure bool, prefix string, channel int, imei string) (*VideoLinks, error)

func (*IotHubClient) GetEndpointHost

func (cli *IotHubClient) GetEndpointHost() string

func (*IotHubClient) HistoryPlaybackControlRequest

func (cli *IotHubClient) HistoryPlaybackControlRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *PlaybackControlCmdContent) (*InstructRequest, error)

func (*IotHubClient) HistoryVideoPlaybackRequest

func (cli *IotHubClient) HistoryVideoPlaybackRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *PlaybackCmdContent) (*InstructRequest, error)

func (*IotHubClient) ListAVResourcesRequest

func (cli *IotHubClient) ListAVResourcesRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *AVResourceListCmdContent) (*InstructRequest, error)

func (*IotHubClient) RealTimeAVControlRequest

func (cli *IotHubClient) RealTimeAVControlRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *RealTimeControlCmdContent) (*InstructRequest, error)

func (*IotHubClient) RealTimeAVRequest

func (cli *IotHubClient) RealTimeAVRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *RealTimeCmdContent) (*InstructRequest, error)

func (*IotHubClient) SendDeviceInstruction

func (cli *IotHubClient) SendDeviceInstruction(ctx context.Context, request *InstructRequest) (*Response, error)

func (*IotHubClient) Stop

func (cli *IotHubClient) Stop()

type IotHubConfig

type IotHubConfig struct {
	EndPoint                string `env:"IOTHUB_ENDPOINT,notEmpty"`
	Proxy                   string `env:"CLIENT_PROXY"`
	Token                   string `env:"IOTHUB_TOKEN" envDefault:"123456"`
	JimiGatewayPort         string `env:"JIMI_GATEWAY_PORT" envDefault:"21100"`
	JTGatewayPort           string `env:"JT_GATEWAY_PORT" envDefault:"21122"`
	FileStoragePort         string `env:"FILE_STORAGE_PORT" envDefault:"23010"`
	HttpFlvMediaServerPort  string `env:"FLV_HTTP_PORT" envDefault:"8881"`
	HttpsFlvMediaServerPort string `env:"FLV_HTTPS_PORT" envDefault:"8890"`
	RtmpMediaServerPort     string `env:"RTMP_PORT" envDefault:"1936"`
	LiveVideoPort           string `env:"LIVE_VIDEO_PORT" envDefault:"10002"`
	HistoryVideoPort        string `env:"HISTORY_VIDEO_PORT" envDefault:"10003"`
	APIPort                 string `env:"API_PORT" envDefault:"9080"`
	InstructionServicePort  string `env:"INSTRUCTION_SERVICE_PORT" envDefault:"10088"`
	RedisAddress            string `env:"IOTHUB_REDIS_ADDRESS"`
	RedisPassword           string `env:"IOTHUB_REDIS_PASSWORD"`
	RedisDB                 int    `env:"IOTHUB_REDIS_DB" envDefault:"0"`
}

func ReadIotHubEnvironments

func ReadIotHubEnvironments() (*IotHubConfig, error)

type JimiIotHub

type JimiIotHub interface {
	Stop()
	EndpointURL() *url.URL
	GetEndpointHost() string
	Client() *resty.Client
	Config(canModify bool) *IotHubConfig

	SendDeviceInstruction(ctx context.Context, request *InstructRequest) (*Response, error)

	DeviceInstructionRequest(ctx context.Context, imei string, command string) (*InstructRequest, error)
	RealTimeAVRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *RealTimeCmdContent) (*InstructRequest, error)
	RealTimeAVControlRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *RealTimeControlCmdContent) (*InstructRequest, error)
	ListAVResourcesRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *AVResourceListCmdContent) (*InstructRequest, error)
	HistoryVideoPlaybackRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *PlaybackCmdContent) (*InstructRequest, error)
	HistoryPlaybackControlRequest(ctx context.Context, imei string, deviceModel DeviceModel, cmdContent *PlaybackControlCmdContent) (*InstructRequest, error)

	GenerateDeviceConfigLinks(rtmpPrefix string) *DeviceConfigLinks
	GenerateRtmpLiveLink(secure bool, prefix string, channel int, imei string) (string, error)
	GenerateFlvLiveLink(secure bool, prefix string, channel int, imei string) (string, error)
	GenerateFLVReplayLink(secure bool, prefix string, imei string) (string, error)
	GenerateFLVHistoryLink(secure bool, channel int, imei string) (string, error)
	GenerateVideoLinks(secure bool, prefix string, channel int, imei string) (*VideoLinks, error)
}

type PlayMethod

type PlayMethod string
const (
	PlayNormal         PlayMethod = "0"
	PlayFastForward    PlayMethod = "1"
	PlayKeyframeRewind PlayMethod = "2"
	PlayKeyframe       PlayMethod = "3"
	PlaySingleFrame    PlayMethod = "4"
)

type PlaybackCmdContent

type PlaybackCmdContent struct {
	ServerAddress string               `json:"serverAddress"`
	TCPPort       string               `json:"tcpPort"`
	UDPPort       string               `json:"udpPort"`
	Channel       string               `json:"channel"`
	ResourceType  PlaybackResourceType `json:"resourceType"`
	CodeType      PlaybackCodeType     `json:"codeType"`
	StorageType   PlaybackStorageType  `json:"storageType"`
	PlayMethod    PlayMethod           `json:"playMethod"`
	ForwardRewind ForwardRewind        `json:"forwardRewind"`
	BeginTime     string               `json:"beginTime"`
	EndTime       string               `json:"endTime"`
	InstructionID string               `json:"instructionID"`
}

type PlaybackCodeType

type PlaybackCodeType string
const (
	PlaybackAllStream  PlaybackCodeType = "0"
	PlaybackMainStream PlaybackCodeType = "1"
	PlaybackSubStream  PlaybackCodeType = "2"
)

type PlaybackControl

type PlaybackControl byte
const (
	PlaybackStart       PlaybackControl = 0
	PlaybackPause       PlaybackControl = 1
	PlaybackEnd         PlaybackControl = 2
	PlaybackFastForward PlaybackControl = 3
	PlaybackKeyframe    PlaybackControl = 4
	PlaybackDrag        PlaybackControl = 5
)

type PlaybackControlCmdContent

type PlaybackControlCmdContent struct {
	Channel       uint8           `json:"channel"` //1-5
	PlayCtrl      PlaybackControl `json:"playCtrl"`
	ForwardRewind PlaybackSpeed   `json:"forwardRewind"`
	BeginTime     string          `json:"beginTime"`
	//Drag position(YYMMDDHHMMSS, when playback control is 5, this field is valid)
	InstructionID string `json:"instructionID"`
}

type PlaybackResourceType

type PlaybackResourceType string
const (
	PlaybackResourceAudioAndVideo PlaybackResourceType = "0"
	PlaybackResourceAudio         PlaybackResourceType = "1"
	PlaybackResourceVideo         PlaybackResourceType = "2"
	PlaybackResourceAudioOrVideo  PlaybackResourceType = "3"
)

type PlaybackSpeed

type PlaybackSpeed uint8
const (
	PlaybackSpeedInvalid PlaybackSpeed = 0
	PlaybackSpeed1x      PlaybackSpeed = 1
	PlaybackSpeed2x      PlaybackSpeed = 2
	PlaybackSpeed4x      PlaybackSpeed = 3
	PlaybackSpeed8x      PlaybackSpeed = 4
	PlaybackSpeed16x     PlaybackSpeed = 5
)

type PlaybackStorageType

type PlaybackStorageType string
const (
	PlaybackStorageAll  PlaybackStorageType = "0"
	PlaybackStorageMain PlaybackStorageType = "1"
	StorageDisaster     PlaybackStorageType = "2"
)

type ProNumber

type ProNumber int
const (
	ProNoOnlineCommand                 ProNumber = 128
	ProNoRealTimeAudioVideoRequest     ProNumber = 37121
	ProNoAudioVideoTransmissionControl ProNumber = 37122
	ProNoRemoteVideoPlaybackRequest    ProNumber = 37377
	ProNoRemoteVideoPlaybackControl    ProNumber = 37378
	ProNoQueryAudioVideoResourceList   ProNumber = 37381
	ProNoFTPFileUploadCommand          ProNumber = 37382
	ProNoFTPFileUploadControl          ProNumber = 37383
	ProNoSetTerminalParameters         ProNumber = 33027
	ProNoQueryTerminalParameters       ProNumber = 33028
	ProNoQuerySpecificParameters       ProNumber = 33030
	ProNoCameraShootImmediately        ProNumber = 34817
	ProNoMultimediaDataRetrieval       ProNumber = 34818
	ProNoMultimediaDataUpload          ProNumber = 34819
	ProNoSingleMultimediaDataUpload    ProNumber = 34821
)

type RealTimeAVDataType

type RealTimeAVDataType string
const (
	AudioVideoDataType              RealTimeAVDataType = "0"
	VideoDataType                   RealTimeAVDataType = "1"
	TwoWayIntercomDataType          RealTimeAVDataType = "2"
	MonitorDataType                 RealTimeAVDataType = "3"
	CenterBroadcastDataType         RealTimeAVDataType = "4"
	TransparentTransmissionDataType RealTimeAVDataType = "5"
)

type RealTimeCmdContent

type RealTimeCmdContent struct {
	DataType       RealTimeAVDataType     `json:"dataType"`
	CodeStreamType RealTimeCodeStreamType `json:"codeStreamType"`
	Channel        string                 `json:"channel"`
	VideoIP        string                 `json:"videoIP"`
	VideoTCPPort   string                 `json:"videoTCPPort"`
	VideoUDPPort   string                 `json:"videoUDPPort"`
}

type RealTimeCodeStreamType

type RealTimeCodeStreamType string
const (
	MainStream RealTimeCodeStreamType = "0"
	SubStream  RealTimeCodeStreamType = "1"
)

type RealTimeControlCmd

type RealTimeControlCmd string
const (
	CmdTurnOffAVTransmission RealTimeControlCmd = "0"
	CmdSwitchStream          RealTimeControlCmd = "1"
	CmdPauseAllStreams       RealTimeControlCmd = "2"
	CmdResumeStream          RealTimeControlCmd = "3"
	CmdTurnOffIntercom       RealTimeControlCmd = "4"
)

type RealTimeControlCmdContent

type RealTimeControlCmdContent struct {
	Channel        int                              `json:"channel"`
	Cmd            RealTimeControlCmd               `json:"cmd"`
	DataType       TurnOffAVType                    `json:"dataType"`
	CodeStreamType RealTimeControllerCodeStreamType `json:"codeStreamType"`
}

type RealTimeControllerCodeStreamType

type RealTimeControllerCodeStreamType int
const (
	ControllerMainStream RealTimeControllerCodeStreamType = 0
	ControllerSubStream  RealTimeControllerCodeStreamType = 1
)

type RequestCommandType

type RequestCommandType string
const (
	NormallnsCommandType RequestCommandType = "normallns"
	GeneralCommandType   RequestCommandType = "general"
)

type RequestPlatform

type RequestPlatform string
const (
	RequestPlatformWeb RequestPlatform = "web"
	RequestPlatformApp RequestPlatform = "app"
)

type ResourceListCodeType

type ResourceListCodeType uint8
const (
	CodeTypeAllStream  ResourceListCodeType = 0
	CodeTypeMainStream ResourceListCodeType = 1
	CodeTypeSubStream  ResourceListCodeType = 2
)

type ResourceListStorageType

type ResourceListStorageType uint8
const (
	StorageTypeAllStorage              ResourceListStorageType = 0
	StorageTypeMainStorage             ResourceListStorageType = 1
	StorageTypeDisasterRecoveryStorage ResourceListStorageType = 2
)

type ResourcesType

type ResourcesType uint8
const (
	ResourceAudioAndVideo ResourcesType = 0
	ResourceAudio         ResourcesType = 1
	ResourceVideo         ResourcesType = 2
	ResourceVideoOrAudio  ResourcesType = 3
)

type Response

type Response struct {
	Code int          `json:"code"`
	Msg  string       `json:"msg"`
	Data ResponseData `json:"data"`
}

type ResponseCode

type ResponseCode string
const (
	// ResponseCodeSuccess The command sent successfully and received a return code indicating the device status, such as busy or error.
	ResponseCodeSuccess ResponseCode = "100"

	// ResponseCodeInvalidParameter Invalid parameter.
	ResponseCodeInvalidParameter ResponseCode = "200"

	// ResponseCodeDeviceOffline Device offline.
	ResponseCodeDeviceOffline ResponseCode = "300"

	// ResponseCodeDeviceNotRegistered Device not registered with route table (No mapping between IMEI and gateway ID is found in Redis).
	ResponseCodeDeviceNotRegistered ResponseCode = "301"

	// ResponseCodeDeviceBusy The last command has been sent and no response indicating "device busy" is received.
	ResponseCodeDeviceBusy ResponseCode = "302"

	// ResponseCodeSMSSentSuccessfully SMS sent successfully.
	ResponseCodeSMSSentSuccessfully ResponseCode = "303"

	// ResponseCodeSMSFailed SMS failed.
	ResponseCodeSMSFailed ResponseCode = "304"

	// ResponseCodeNetworkError Network error (Interrupted, etc.).
	ResponseCodeNetworkError ResponseCode = "400"

	// ResponseCodeCodeExecutionException Code execution exception.
	ResponseCodeCodeExecutionException ResponseCode = "500"

	// ResponseCodeRequestTimeout Request timeout.
	ResponseCodeRequestTimeout ResponseCode = "600"
)

type ResponseData

type ResponseData struct {
	Code            ResponseCode `json:"_code"`
	Msg             string       `json:"_msg"`
	Type            string       `json:"_type"`
	Content         string       `json:"_content"`
	ProNo           string       `json:"_proNo"`
	Language        string       `json:"_language,omitempty"`
	IMEI            string       `json:"_imei"`
	RouteClientTime string       `json:"_route_client_time"`
	ServerFlagId    string       `json:"_serverFlagId"`
	GateId          string       `json:"_gateId"`
	RouteServerTime string       `json:"_route_server_time"`
}

type TurnOffAVType

type TurnOffAVType string
const (
	TurnOffBothAudioAndVideo TurnOffAVType = "0"
	TurnOffAudioOnly         TurnOffAVType = "1"
	TurnOffVideoOnly         TurnOffAVType = "2"
)
type VideoLinks struct {
	RtmpLiveLink, FlvLiveLink     string
	FLVHistoryLink, FLVReplayLink string
}

Jump to

Keyboard shortcuts

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