engine

package module
v0.5.1-0...-e9fb175 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: MIT Imports: 27 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 (
	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

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

func NewBizClient(addr string) *BizClient

func (*BizClient) Close

func (c *BizClient) Close()

func (*BizClient) Join

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

func (*BizClient) Leave

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

func (*BizClient) SendMessage

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

type Call

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

Call dc api

type Client

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

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

NewClient create a sdk client

func (*Client) Close

func (c *Client) Close()

Close client close

func (*Client) CreateDataChannel

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

CreateDataChannel create a custom datachannel

func (*Client) GetPubStats

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

GetPubStats get pub stats

func (*Client) GetPubTransport

func (c *Client) GetPubTransport() *Transport

func (*Client) GetSubStats

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

GetSubStats get sub stats

func (*Client) GetSubTransport

func (c *Client) GetSubTransport() *Transport

func (*Client) Join

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

Join client join a session

func (*Client) Negotiate

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

Negotiate sub negotiate

func (*Client) OnNegotiationNeeded

func (c *Client) OnNegotiationNeeded()

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

func (*Client) Publish

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

Publish a local track

func (*Client) PublishWebm

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

PublishWebm publish a webm producer

func (*Client) SetRemoteSDP

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

SetRemoteSDP pub SetRemoteDescription and send cadidate to sfu

func (*Client) Simulcast

func (c *Client) Simulcast(layer string)

func (*Client) SubscribeAll

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

SubscribeAll subscribe all stream with the same video/audio param

func (*Client) Trickle

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

Trickle receive candidate from sfu and add to pc

func (*Client) UnPublish

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

UnPublish a local track by Transceiver

func (*Client) UnSubscribeAll

func (c *Client) UnSubscribeAll()

UnSubscribeAll unsubscribe all stream

type Config

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

Config ..

type Engine

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

Engine a sdk engine

func NewEngine

func NewEngine(cfg Config) *Engine

NewEngine create a engine

func (*Engine) AddClient

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

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

func (*Engine) DelClient

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

DelClient delete a client

func (*Engine) ServePProf

func (e *Engine) ServePProf(paddr string)

ServePProf listening pprof

func (*Engine) Stats

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

Stats show a total stats to console: clients and bandwidth

type IonConnector

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

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

func (*IonConnector) Close

func (i *IonConnector) Close()

func (*IonConnector) Join

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

func (*IonConnector) Leave

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

func (*IonConnector) Message

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

func (*IonConnector) SFU

func (i *IonConnector) SFU() *Client

type JoinConfig

type JoinConfig map[string]string

func NewJoinConfig

func NewJoinConfig() *JoinConfig

func SetRelay

func SetRelay(j JoinConfig) *JoinConfig

func (JoinConfig) SetNoPublish

func (j JoinConfig) SetNoPublish() *JoinConfig

func (JoinConfig) SetNoSubscribe

func (j JoinConfig) SetNoSubscribe() *JoinConfig

type Message

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

type Peer

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

type PeerEvent

type PeerEvent struct {
	State PeerState
	Peer  Peer
}

type PeerState

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

type Signal

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

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

NewSignal create a grpc signaler

func (*Signal) Answer

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

func (*Signal) Close

func (s *Signal) Close()

func (*Signal) Join

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

func (*Signal) Offer

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

func (*Signal) Trickle

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

func (*Signal) TrickleFromInit

func (s *Signal) TrickleFromInit(candidate webrtc.ICECandidateInit, target int)

type Stream

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

type StreamEvent

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

type StreamState

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

type Track

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

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 int, signal *Signal, cfg WebRTCTransportConfig) *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(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

Jump to

Keyboard shortcuts

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