engine

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 29 Imported by: 0

README

ion-sdk-go

this is ion golang sdk for ion-sfu Feature:

  • Join a session
    • Join with config(NoPublish/NoSubscribe/Relay)
  • Subscribe from session
    • OnTrack(user-defined)
  • Publish file to session
    • webm
      • vp8+opus
      • vp9+opus
    • mp4(h264+opus)
    • simulcast(publish 3 files)
  • Publish rtp to session
    • audio|video only
    • audio codec(opus)
    • video codec
      • vp8
      • vp9
      • h264
  • Simulcast
    • subscribe
    • publish
  • Publish media device to session
    • camera
    • mic
    • screen
  • Support ion cluster

Documentation

Index

Constants

View Source
const (
	MimeTypeH264 = "video/h264"
	MimeTypeOpus = "audio/opus"
	MimeTypeVP8  = "video/vp8"
	MimeTypeVP9  = "video/vp9"
)
View Source
const (
	API_CHANNEL = "ion-sfu"
)

Variables

View Source
var (
	DefaultConfig = RTCConfig{
		WebRTC: WebRTCTransportConfig{
			Configuration: webrtc.Configuration{
				ICEServers: []webrtc.ICEServer{
					{
						URLs: []string{"stun:stun.stunprotocol.org:3478", "stun:stun.l.google.com:19302"},
					},
				},
			},
		},
	}
)

Functions

func FileExist

func FileExist(path string) bool

func GetArgs

func GetArgs(args ...string) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 string)

func GetError

func GetError(err *room.Error) error

func RandomKey

func RandomKey(n int) string

RandomKey generate a random string key

Types

type Call

type Call struct {
	StreamID string `json:"streamId"`
	Video    string `json:"video"`
	Audio    bool   `json:"audio"`
}

Call dc api

type Connector

type Connector struct {
	Metadata metadata.MD

	OnOpen  func(Service)
	OnClose func(Service, ServiceEvent)
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(addr string, config ...ConnectorConfig) *Connector

NewConnector create a ion connector

func (*Connector) Close

func (c *Connector) Close()

func (*Connector) OnEnd

func (c *Connector) OnEnd(service Service, headers metadata.MD)

func (*Connector) OnHeaders

func (c *Connector) OnHeaders(service Service, headers metadata.MD)

func (*Connector) RegisterService

func (c *Connector) RegisterService(service Service)

type ConnectorConfig

type ConnectorConfig struct {
	SSL    bool
	Cafile string
	Token  string
	// contains filtered or unexported fields
}

type JoinConfig

type JoinConfig map[string]string

func NewJoinConfig

func NewJoinConfig() *JoinConfig

func SetRelay

func SetRelay(j JoinConfig) *JoinConfig

func (JoinConfig) SetNoAutoSubscribe

func (j JoinConfig) SetNoAutoSubscribe() *JoinConfig

func (JoinConfig) SetNoPublish

func (j JoinConfig) SetNoPublish() *JoinConfig

func (JoinConfig) SetNoSubscribe

func (j JoinConfig) SetNoSubscribe() *JoinConfig

type JoinInfo

type JoinInfo struct {
	Sid         string
	Uid         string
	DisplayName string
	ExtraInfo   []byte
	Destination string
	Role        Role
	Protocol    Protocol
	Avatar      string
	Direction   Peer_Direction
	Vendor      string
}

type MediaType

type MediaType int32
const (
	MediaType_MediaUnknown  MediaType = 0
	MediaType_UserMedia     MediaType = 1
	MediaType_ScreenCapture MediaType = 2
	MediaType_Cavans        MediaType = 3
	MediaType_Streaming     MediaType = 4
	MediaType_VoIP          MediaType = 5
)

type PeerInfo

type PeerInfo struct {
	Sid         string
	Uid         string
	DisplayName string
	ExtraInfo   []byte
	Destination string
	Role        Role
	Protocol    Protocol
	Avatar      string
	Direction   Peer_Direction
	Vendor      string
}

type PeerState

type PeerState int32
const (
	PeerState_JOIN   PeerState = 0
	PeerState_UPDATE PeerState = 1
	PeerState_LEAVE  PeerState = 2
)

type Peer_Direction

type Peer_Direction int32
const (
	Peer_INCOMING  Peer_Direction = 0
	Peer_OUTGOING  Peer_Direction = 1
	Peer_BILATERAL Peer_Direction = 2
)

type Protocol

type Protocol int32
const (
	Protocol_ProtocolUnknown Protocol = 0
	Protocol_WebRTC          Protocol = 1
	Protocol_SIP             Protocol = 2
	Protocol_RTMP            Protocol = 3
	Protocol_RTSP            Protocol = 4
)

type RTC

type RTC struct {
	Service

	//export to user
	OnTrack       func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver)
	OnDataChannel func(*webrtc.DataChannel)
	OnError       func(error)
	OnTrackEvent  func(event TrackEvent)
	OnSpeaker     func(event []string)

	sync.Mutex
	// contains filtered or unexported fields
}

Client a sdk client

func NewRTC

func NewRTC(connector *Connector, config ...RTCConfig) *RTC

func (*RTC) Close

func (r *RTC) Close()

Close client close

func (*RTC) Connect

func (r *RTC) Connect()

func (*RTC) Connected

func (r *RTC) Connected() bool

func (*RTC) CreateDataChannel

func (r *RTC) CreateDataChannel(label string) (*webrtc.DataChannel, error)

CreateDataChannel create a custom datachannel

func (*RTC) GetBandWidth

func (r *RTC) GetBandWidth(cycle int) (int, int)

GetBandWidth call this api cyclely

func (*RTC) GetPubStats

func (r *RTC) GetPubStats() webrtc.StatsReport

GetPubStats get pub stats

func (*RTC) GetPubTransport

func (r *RTC) GetPubTransport() *Transport

func (*RTC) GetSubStats

func (r *RTC) GetSubStats() webrtc.StatsReport

GetSubStats get sub stats

func (*RTC) GetSubTransport

func (r *RTC) GetSubTransport() *Transport

func (*RTC) Join

func (r *RTC) Join(sid, uid string, config ...*JoinConfig) error

Join client join a session

func (*RTC) Name

func (r *RTC) Name() string

func (*RTC) Publish

func (r *RTC) Publish(tracks ...webrtc.TrackLocal) ([]*webrtc.RTPTransceiver, error)

Publish local tracks

func (*RTC) PublishFile

func (r *RTC) PublishFile(file string, video, audio bool) error

PublishWebm publish a webm producer

func (*RTC) SendAnswer

func (r *RTC) SendAnswer(sdp webrtc.SessionDescription) error

func (*RTC) SendJoin

func (r *RTC) SendJoin(sid string, uid string, offer webrtc.SessionDescription, config map[string]string) error

func (*RTC) SendOffer

func (r *RTC) SendOffer(sdp webrtc.SessionDescription) error

func (*RTC) SendTrickle

func (r *RTC) SendTrickle(candidate *webrtc.ICECandidate, target Target)

func (*RTC) Subscribe

func (r *RTC) Subscribe(trackInfos []*Subscription) error

Subscribe to tracks

func (*RTC) SubscribeFromEvent

func (r *RTC) SubscribeFromEvent(event TrackEvent, audio, video bool, layer string) error

SubscribeFromEvent will parse event and subscribe what you want

func (*RTC) UnPublish

func (r *RTC) UnPublish(transceivers ...*webrtc.RTPTransceiver) error

UnPublish local tracks by transceivers

type RTCConfig

type RTCConfig struct {
	WebRTC WebRTCTransportConfig `mapstructure:"webrtc"`
}

type Role

type Role int32
const (
	Role_Host  Role = 0
	Role_Guest Role = 1
)

type Room

type Room struct {
	Service

	sync.Mutex

	OnJoin       func(success bool, info RoomInfo, err error)
	OnLeave      func(success bool, err error)
	OnPeerEvent  func(state PeerState, Peer PeerInfo)
	OnMessage    func(from string, to string, data map[string]interface{})
	OnDisconnect func(sid, reason string)
	OnRoomInfo   func(info RoomInfo)
	OnError      func(error)
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(connector *Connector) *Room

func (*Room) AddPeer

func (r *Room) AddPeer(peer PeerInfo) error

AddPeer to room, at least a sid

func (*Room) Close

func (c *Room) Close()

func (*Room) Connect

func (c *Room) Connect()

func (*Room) Connected

func (c *Room) Connected() bool

func (*Room) CreateRoom

func (r *Room) CreateRoom(info RoomInfo) error

CreateRoom Params: sid password, at lease a sid

func (*Room) EndRoom

func (r *Room) EndRoom(sid, reason string, delete bool) error

func (*Room) GetPeers

func (r *Room) GetPeers(sid string) []PeerInfo

func (*Room) Join

func (c *Room) Join(j JoinInfo) error

func (*Room) Leave

func (c *Room) Leave(sid, uid string) error

Leave from one session

func (*Room) Name

func (c *Room) Name() string

func (*Room) RemovePeer

func (r *Room) RemovePeer(sid, uid string) error

func (*Room) SendMessage

func (c *Room) SendMessage(sid, from, to string, data map[string]interface{}) error

SendMessage send message from is a uid to is a uid or "all"

func (*Room) UpdatePeer

func (r *Room) UpdatePeer(peer PeerInfo) error

func (*Room) UpdateRoom

func (r *Room) UpdateRoom(info RoomInfo) error

type RoomInfo

type RoomInfo struct {
	Sid      string
	Name     string
	Password string
	Lock     bool
}

type Service

type Service interface {
	Name() string
	Connect()
	Close()
	Connected() bool
}

type ServiceEvent

type ServiceEvent struct {
	Name      string
	ErrStatus *status.Status
}

type Subscription

type Subscription struct {
	TrackId   string
	Mute      bool
	Subscribe bool
	Layer     string
}

type Target

type Target int32
const (
	Target_PUBLISHER  Target = 0
	Target_SUBSCRIBER Target = 1
)

type TrackEvent

type TrackEvent struct {
	State  TrackEvent_State
	Uid    string
	Tracks []*TrackInfo
}

TrackEvent info

type TrackEvent_State

type TrackEvent_State int32
const (
	TrackEvent_ADD    TrackEvent_State = 0
	TrackEvent_UPDATE TrackEvent_State = 1
	TrackEvent_REMOVE TrackEvent_State = 2
)

type TrackInfo

type TrackInfo struct {
	Id        string
	Kind      string
	Muted     bool
	Type      MediaType
	StreamId  string
	Label     string
	Subscribe bool
	Layer     string
	Direction string
	Width     uint32
	Height    uint32
	FrameRate uint32
}

type Transport

type Transport struct {
	SendCandidates []*webrtc.ICECandidate
	RecvCandidates []webrtc.ICECandidateInit
	// contains filtered or unexported fields
}

Transport is pub/sub transport

func NewTransport

func NewTransport(role Target, rtc *RTC) *Transport

NewTransport create a transport

func (*Transport) GetPeerConnection

func (t *Transport) GetPeerConnection() *webrtc.PeerConnection

type WebMProducer

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

WebMProducer support streaming by webm which encode with vp8 and opus

func NewWebMProducer

func NewWebMProducer(name string, offset int) *WebMProducer

NewWebMProducer new a WebMProducer

func (*WebMProducer) GetAudioTrack

func (t *WebMProducer) GetAudioTrack() (*webrtc.TrackLocalStaticSample, error)

GetAudioTrack get audio track

func (*WebMProducer) GetSendBandwidth

func (t *WebMProducer) GetSendBandwidth(cycle int) int

GetSendBandwidth calc the sending bandwidth with cycle(s)

func (*WebMProducer) GetVideoTrack

func (t *WebMProducer) GetVideoTrack() (*webrtc.TrackLocalStaticSample, error)

GetVideoTrack get video track

func (*WebMProducer) Pause

func (t *WebMProducer) Pause(pause bool)

func (*WebMProducer) SeekP

func (t *WebMProducer) SeekP(ts int)

func (*WebMProducer) Start

func (t *WebMProducer) Start()

func (*WebMProducer) Stop

func (t *WebMProducer) Stop()

type WebRTCTransportConfig

type WebRTCTransportConfig struct {
	VideoMime     string
	Configuration webrtc.Configuration
	Setting       webrtc.SettingEngine
}

WebRTCTransportConfig represents configuration options

Directories

Path Synopsis
example
pkg
gstreamer-sink
Package gst provides an easy API to create an appsrc pipeline
Package gst provides an easy API to create an appsrc pipeline
gstreamer-src
Package gst provides an easy API to create an appsink pipeline
Package gst provides an easy API to create an appsink pipeline

Jump to

Keyboard shortcuts

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