engine

package module
v0.0.0-...-54d76d6 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 30 Imported by: 0

README

ion-sdk-go

this is ion golang sdk for ion-sfu Feature:

  • Join a session
  • 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 Call

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

Call dc api

type Candidate

type Candidate struct {
	Target    int                  `json:"target"`
	Candidate *webrtc.ICECandidate `json:candidate`
}

dir /x查看短路径

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 NewClientByPubMedia

func NewClientByPubMedia(engine *Engine, addr string, cid string, me *webrtc.MediaEngine) (*Client, error)

NewClient create a sdk client

func (*Client) AddTrack

func (c *Client) AddTrack(track webrtc.TrackLocal) (*webrtc.RTPSender, error)

Add a local track

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

func (c *Client) CreateMediaEngine(track webrtc.TrackLocal) (*webrtc.RTPSender, error)

Add a local track

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) 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 {
	Log log.MyLogger `mapstructure:"log"`
	// 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 Response

type Response struct {
	Params *webrtc.SessionDescription `json:params`
	Result *webrtc.SessionDescription `json:result`
	Sparam string                     `json:sparam`
	Method string                     `json:method`
	Id     uint64                     `json:id`
}

Response received from the sfu over Websockets

type ResponseCandidate

type ResponseCandidate struct {
	Target    int                      `json:"target"`
	Candidate *webrtc.ICECandidateInit `json:candidate`
}

type SendAnswer

type SendAnswer struct {
	SID    string                     `json:sid`
	Answer *webrtc.SessionDescription `json:answer`
}

SendAnswer object to send to the sfu over Websockets

type SendOffer

type SendOffer struct {
	SID   string                     `json:sid`
	Offer *webrtc.SessionDescription `json:offer`
}

SendOffer object to send to the sfu over Websockets

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

func (*Signal) Offer

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

func (*Signal) Trickle

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

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 NewTransportByMedia

func NewTransportByMedia(role int, signal *Signal, cfg WebRTCTransportConfig, me *webrtc.MediaEngine) *Transport

NewTransport create a transport

func (*Transport) GetPeerConnection

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

type TrickleResponse

type TrickleResponse struct {
	Params ResponseCandidate `json:params`
	Method string            `json:method`
}

TrickleResponse received from the sfu server

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

Jump to

Keyboard shortcuts

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