engine

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 27 Imported by: 38

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 (
	API_CHANNEL = "ion-sfu"
	PUBLISHER   = 0
	SUBSCRIBER  = 1
)

Variables

This section is empty.

Functions

func ValidateVPFile

func ValidateVPFile(name string) (string, bool)

Types

type BizClient added in v0.4.5

type BizClient struct {
	sync.Mutex

	OnJoin        func(success bool, reason string)
	OnLeave       func(reason string)
	OnPeerEvent   func(state PeerState, peer Peer)
	OnStreamEvent func(state StreamState, sid string, uid string, streams []*Stream)
	OnMessage     func(from string, to string, data map[string]interface{})
	OnError       func(error)
	// contains filtered or unexported fields
}

func NewBizClient added in v0.4.5

func NewBizClient(addr string) *BizClient

func (*BizClient) Close added in v0.4.5

func (c *BizClient) Close()

func (*BizClient) Join added in v0.4.5

func (c *BizClient) Join(sid string, uid string, info map[string]interface{}) error

func (*BizClient) Leave added in v0.4.5

func (c *BizClient) Leave(uid string) error

func (*BizClient) SendMessage added in v0.4.5

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

type Call added in v0.2.0

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

Call dc api

type Client added in v0.2.0

type Client struct {

	//export to user
	OnTrack       func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver)
	OnDataChannel func(*webrtc.DataChannel)
	OnError       func(error)
	// contains filtered or unexported fields
}

Client a sdk client

func NewClient added in v0.2.0

func NewClient(engine *Engine, addr string, cid string) (*Client, error)

NewClient create a sdk client

func (*Client) Close added in v0.2.0

func (c *Client) Close()

Close client close

func (*Client) CreateDataChannel added in v0.2.0

func (c *Client) CreateDataChannel(label string) (*webrtc.DataChannel, error)

CreateDataChannel create a custom datachannel

func (*Client) GetPubStats added in v0.2.0

func (c *Client) GetPubStats() webrtc.StatsReport

GetPubStats get pub stats

func (*Client) GetPubTransport added in v0.4.5

func (c *Client) GetPubTransport() *Transport

func (*Client) GetSubStats added in v0.2.0

func (c *Client) GetSubStats() webrtc.StatsReport

GetSubStats get sub stats

func (*Client) GetSubTransport added in v0.4.5

func (c *Client) GetSubTransport() *Transport

func (*Client) Join added in v0.2.0

func (c *Client) Join(sid string, config *JoinConfig) error

Join client join a session

func (*Client) Negotiate added in v0.2.0

func (c *Client) Negotiate(sdp webrtc.SessionDescription) error

Negotiate sub negotiate

func (*Client) OnNegotiationNeeded added in v0.2.0

func (c *Client) OnNegotiationNeeded()

OnNegotiationNeeded will be called when add/remove track, but never trigger, call by hand

func (*Client) Publish added in v0.2.0

func (c *Client) Publish(track webrtc.TrackLocal) (*webrtc.RTPTransceiver, error)

Publish a local track

func (*Client) PublishWebm added in v0.2.0

func (c *Client) PublishWebm(file string, video, audio bool) error

PublishWebm publish a webm producer

func (*Client) SetRemoteSDP added in v0.2.0

func (c *Client) SetRemoteSDP(sdp webrtc.SessionDescription) error

SetRemoteSDP pub SetRemoteDescription and send cadidate to sfu

func (*Client) Simulcast added in v0.4.5

func (c *Client) Simulcast(layer string)

func (*Client) SubscribeAll added in v0.2.0

func (c *Client) SubscribeAll(video string, audio bool)

SubscribeAll subscribe all stream with the same video/audio param

func (*Client) Trickle added in v0.2.0

func (c *Client) Trickle(candidate webrtc.ICECandidateInit, target int)

Trickle receive candidate from sfu and add to pc

func (*Client) UnPublish added in v0.2.0

func (c *Client) UnPublish(t *webrtc.RTPTransceiver) error

UnPublish a local track by Transceiver

func (*Client) UnSubscribeAll added in v0.2.0

func (c *Client) UnSubscribeAll()

UnSubscribeAll unsubscribe all stream

type Config

type Config struct {
	// WebRTC WebRTCConf `mapstructure:"webrtc"`
	WebRTC WebRTCTransportConfig `mapstructure:"webrtc"`
}

Config ..

type Engine added in v0.2.0

type Engine struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Engine a sdk engine

func NewEngine added in v0.2.0

func NewEngine(cfg Config) *Engine

NewEngine create a engine

func (*Engine) AddClient added in v0.2.0

func (e *Engine) AddClient(c *Client) error

AddClient add a client addr: grpc addr sid: session/room id cid: client id

func (*Engine) DelClient added in v0.2.0

func (e *Engine) DelClient(c *Client) error

DelClient delete a client

func (*Engine) ServePProf added in v0.4.5

func (e *Engine) ServePProf(paddr string)

ServePProf listening pprof

func (*Engine) Stats added in v0.2.0

func (e *Engine) Stats(cycle int) string

Stats show a total stats to console: clients and bandwidth

type IonConnector added in v0.4.5

type IonConnector struct {
	OnJoin        func(success bool, reason string)
	OnLeave       func(reason string)
	OnTrack       func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver)
	OnDataChannel func(dc *webrtc.DataChannel)
	OnPeerEvent   func(event PeerEvent)
	OnStreamEvent func(event StreamEvent)
	OnMessage     func(msg Message)
	OnError       func(error)
	// contains filtered or unexported fields
}

func NewIonConnector added in v0.4.5

func NewIonConnector(addr string, uid string, pinfo map[string]interface{}) *IonConnector

func (*IonConnector) Close added in v0.4.5

func (i *IonConnector) Close()

func (*IonConnector) Join added in v0.4.5

func (i *IonConnector) Join(sid string) error

func (*IonConnector) Leave added in v0.4.5

func (i *IonConnector) Leave(uid string) error

func (*IonConnector) Message added in v0.4.5

func (i *IonConnector) Message(from string, to string, data map[string]interface{})

func (*IonConnector) SFU added in v0.4.5

func (i *IonConnector) SFU() *Client

type JoinConfig added in v0.6.0

type JoinConfig map[string]string

func NewJoinConfig added in v0.6.0

func NewJoinConfig() *JoinConfig

func SetRelay added in v0.6.0

func SetRelay(j JoinConfig) *JoinConfig

func (JoinConfig) SetNoPublish added in v0.6.0

func (j JoinConfig) SetNoPublish() *JoinConfig

func (JoinConfig) SetNoSubscribe added in v0.6.0

func (j JoinConfig) SetNoSubscribe() *JoinConfig

type Message added in v0.4.5

type Message struct {
	From string
	To   string
	Data map[string]interface{}
}

type Peer added in v0.4.5

type Peer struct {
	Sid  string
	Uid  string
	Info map[string]interface{}
}

type PeerEvent added in v0.4.5

type PeerEvent struct {
	State PeerState
	Peer  Peer
}

type PeerState added in v0.4.5

type PeerState int32
const (
	PeerJOIN   PeerState = 0
	PeerUPDATE PeerState = 1
	PeerLEAVE  PeerState = 2
)

type Signal added in v0.2.0

type Signal struct {
	OnNegotiate    func(webrtc.SessionDescription) error
	OnTrickle      func(candidate webrtc.ICECandidateInit, target int)
	OnSetRemoteSDP func(webrtc.SessionDescription) error
	OnError        func(error)

	sync.Mutex
	// contains filtered or unexported fields
}

Signal is a wrapper of grpc

func NewSignal added in v0.2.0

func NewSignal(addr, id string) (*Signal, error)

NewSignal create a grpc signaler

func (*Signal) Answer added in v0.2.0

func (s *Signal) Answer(sdp webrtc.SessionDescription)

func (*Signal) Close added in v0.2.0

func (s *Signal) Close()

func (*Signal) Join added in v0.2.0

func (s *Signal) Join(sid string, uid string, offer webrtc.SessionDescription, config *JoinConfig) error

func (*Signal) Offer added in v0.2.0

func (s *Signal) Offer(sdp webrtc.SessionDescription)

func (*Signal) Trickle added in v0.2.0

func (s *Signal) Trickle(candidate *webrtc.ICECandidate, target int)

type Stream added in v0.4.5

type Stream struct {
	Id     string
	Tracks []*Track
}

type StreamEvent added in v0.4.5

type StreamEvent struct {
	State   StreamState
	Sid     string
	Uid     string
	Streams []*Stream
}

type StreamState added in v0.4.5

type StreamState int32
const (
	StreamADD    StreamState = 0
	StreamREMOVE StreamState = 2
)

type Track added in v0.4.5

type Track struct {
	Id        string
	Label     string
	Kind      string
	Simulcast map[string]string
}

type Transport added in v0.2.0

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

Transport is pub/sub transport

func NewTransport added in v0.2.0

func NewTransport(role int, signal *Signal, cfg WebRTCTransportConfig) *Transport

NewTransport create a transport

func (*Transport) GetPeerConnection added in v0.4.5

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(id, name string, offset int) *WebMProducer

NewWebMProducer new a WebMProducer

func (*WebMProducer) AddTrack

func (t *WebMProducer) AddTrack(pc *webrtc.PeerConnection, kind string) (*webrtc.TrackLocalStaticSample, error)

AddTrack will add new track to pc

func (*WebMProducer) AudioTrack

func (t *WebMProducer) AudioTrack() *webrtc.TrackLocalStaticSample

func (*WebMProducer) GetSendBandwidth

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

GetSendBandwidth calc the sending bandwidth with cycle(s)

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()

func (*WebMProducer) VideoCodec

func (t *WebMProducer) VideoCodec() string

func (*WebMProducer) VideoTrack

func (t *WebMProducer) VideoTrack() *webrtc.TrackLocalStaticSample

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