janus

package module
v0.0.0-...-e2e5946 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 10 Imported by: 0

README

janus-go

only support websocekt transport

Documentation

Overview

Package janus is a Golang implementation of the Janus API, used to interact with the Janus WebRTC Gateway.

Index

Constants

View Source
const (
	Create           = "create"
	Destroy          = "destroy"
	Exists           = "exists"
	Info             = "Info"
	ListParticipants = "listparticipants"
	RtpForward       = "rtp_forward"
)

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

func Int

func Int(v int) *int

func Int64

func Int64(v int64) *int64

func String

func String(v string) *string

Types

type AckMsg

type AckMsg struct{}

type BaseMsg

type BaseMsg struct {
	Type    string `json:"janus"`
	ID      string `json:"transaction"`
	Session uint64 `json:"session_id"`
	Handle  uint64 `json:"sender"`
}

type CreateRequest

type CreateRequest struct {
	GenericRequest
	IsPrivate          *bool   `json:"is_private,omitempty"`
	Audio              *bool   `json:"audio,omitempty"`
	AudioPort          *int    `json:"audioport,omitempty"`
	AudioRTCPPort      *int    `json:"audiortcpport,omitempty"`
	AudioPT            *int    `json:"audiopt,omitempty"`
	AudioRTPMap        *string `json:"audiortpmap,omitempty"`
	AudioCodec         *string `json:"audiocodec,omitempty"`
	Bitrate            *int64  `json:"bitrate,omitempty"`
	FirFreq            *int    `json:"fir_freq,omitempty"`
	Publishers         *int    `json:"publishers,omitempty"`
	TransportWideCcExt *bool   `json:"transport_wide_cc_ext,omitempty"`
	Video              *bool   `json:"video,omitempty"`
	VideoPort          *int    `json:"videoport,omitempty"`
	VideoRTCPPort      *int    `json:"videortcpport,omitempty"`
	VideoPT            *int    `json:"videopt,omitempty"`
	VideoRTPMap        *string `json:"videortpmap,omitempty"`
	VideoCodec         *string `json:"videocodec,omitempty"`
	VideoOrientExt     *string `json:"videoorient_ext,omitempty"`
}

type DetachedMsg

type DetachedMsg struct{}

type ErrorData

type ErrorData struct {
	Code   int
	Reason string
}

type ErrorMsg

type ErrorMsg struct {
	Err ErrorData `json:"error"`
}

func (*ErrorMsg) Error

func (err *ErrorMsg) Error() string

type EventMsg

type EventMsg struct {
	Plugindata PluginData
	Jsep       map[string]interface{}
	Session    uint64 `json:"session_id"`
	Handle     uint64 `json:"sender"`
}

type Gateway

type Gateway struct {
	// Sessions is a map of the currently active sessions to the gateway.
	Sessions map[uint64]*Session

	// Access to the Sessions map should be synchronized with the Gateway.Lock()
	// and Gateway.Unlock() methods provided by the embeded sync.Mutex.
	sync.Mutex
	// contains filtered or unexported fields
}

Gateway represents a connection to an instance of the Janus Gateway.

func Connect

func Connect(ctx context.Context, wsURL string) (*Gateway, error)

Connect initiates a webscoket connection with the Janus Gateway

func (*Gateway) Close

func (gateway *Gateway) Close(code websocket.StatusCode, reason string) error

Close closes the underlying connection to the Gateway.

func (*Gateway) Create

func (gateway *Gateway) Create(ctx context.Context) (*Session, error)

Create sends a create request to the Gateway. On success, a new Session will be returned and error will be nil.

func (*Gateway) GetErrChan

func (gateway *Gateway) GetErrChan() chan error

GetErrChan returns a channels through which the caller can check and react to connectivity errors

func (*Gateway) Info

func (gateway *Gateway) Info(ctx context.Context) (*InfoMsg, error)

Info sends an info request to the Gateway. On success, an InfoMsg will be returned and error will be nil.

type GenericRequest

type GenericRequest struct {
	Request   *string `json:"request,omitempty"`
	Type      *string `json:"type,omitempty"`
	Room      *int64  `json:"room,omitempty"`
	Id        *int    `json:"id,omitempty"`
	Secret    *string `json:"secret,omitempty"`
	Permanent *bool   `json:"permanent,omitempty"`
}

func CreateDestroyIdRequest

func CreateDestroyIdRequest(id int, secret string) *GenericRequest

func CreateDestroyRoomIdRequest

func CreateDestroyRoomIdRequest(room int64, secret string, permanent bool) *GenericRequest

func CreateExistsRequest

func CreateExistsRequest(room int64) *GenericRequest

func CreateGenericRequest

func CreateGenericRequest(requestType *string, _type *string, room *int64, id *int, secret *string, permanent *bool) *GenericRequest

func CreateInfoRequest

func CreateInfoRequest(id int, secret string) *GenericRequest

func CreateListParticipantsRequest

func CreateListParticipantsRequest(room int64) *GenericRequest

type Handle

type Handle struct {
	// ID is the handle_id of this plugin handle
	ID uint64

	// Type   // pub  or sub
	Type string

	//User   // Userid
	User string

	// Events is a receive only channel that can be used to receive events
	// related to this handle from the gateway.
	Events chan interface{}
	// contains filtered or unexported fields
}

Handle represents a handle to a plugin instance on the Gateway.

func (*Handle) Detach

func (handle *Handle) Detach(ctx context.Context) (*AckMsg, error)

Detach sends a detach request to the Gateway to remove this handle. On success, an AckMsg will be returned and error will be nil.

func (*Handle) Message

func (handle *Handle) Message(ctx context.Context, body, jsep interface{}) (*EventMsg, error)

Message sends a message request to a plugin handle on the Gateway. body should be the plugin data to be passed to the plugin, and jsep should contain an optional SDP offer/answer to establish a WebRTC PeerConnection. On success, an EventMsg will be returned and error will be nil.

func (*Handle) Request

func (handle *Handle) Request(ctx context.Context, body interface{}) (*SuccessMsg, error)

Request sends a sync request

func (*Handle) Trickle

func (handle *Handle) Trickle(ctx context.Context, candidate interface{}) (*AckMsg, error)

Trickle sends a trickle request to the Gateway as part of establishing a new PeerConnection with a plugin. candidate should be a single ICE candidate, or a completed object to signify that all candidates have been sent:

{
	"completed": true
}

On success, an AckMsg will be returned and error will be nil.

func (*Handle) TrickleMany

func (handle *Handle) TrickleMany(ctx context.Context, candidates interface{}) (*AckMsg, error)

TrickleMany sends a trickle request to the Gateway as part of establishing a new PeerConnection with a plugin. candidates should be an array of ICE candidates. On success, an AckMsg will be returned and error will be nil.

type HangupMsg

type HangupMsg struct {
	Reason  string
	Session uint64 `json:"session_id"`
	Handle  uint64 `json:"sender"`
}

type InfoMsg

type InfoMsg struct {
	Name          string
	Version       int
	VersionString string `json:"version_string"`
	Author        string
	DataChannels  bool   `json:"data_channels"`
	IPv6          bool   `json:"ipv6"`
	LocalIP       string `json:"local-ip"`
	IceTCP        bool   `json:"ice-tcp"`
	Transports    map[string]PluginInfo
	Plugins       map[string]PluginInfo
}

type MediaMsg

type MediaMsg struct {
	Type      string
	Receiving bool
}

type Participant

type Participant struct {
	ID        *int64  `json:"id,omitempty"`
	Display   *string `json:"display,omitempty"`
	Publisher *bool   `json:"publisher,omitempty"`
	Talking   *bool   `json:"talking,omitempty"`
	Setup     *bool   `json:"setup,omitempty"`
	Muted     *bool   `json:"muted,omitempty"`
	Username  *string `json:"username,omitempty"`
}

type PluginData

type PluginData struct {
	Plugin string
	Data   map[string]interface{}
}

type PluginInfo

type PluginInfo struct {
	Name          string
	Author        string
	Description   string
	Version       int
	VersionString string `json:"version_string"`
}

type RTPForwardRequest

type RTPForwardRequest struct {
	GenericRequest
	PublisherID   *int    `json:"publisher_id,omitempty"`
	Host          *string `json:"host,omitempty"`
	HostFamily    *string `json:"host_family,omitempty"`
	VideoPort     *int    `json:"video_port,omitempty"`
	VideoRTCPPort *int    `json:"video_rtcp_port,omitempty"`
	AlwaysOn      *bool   `json:"always_on,omitempty"`
}

type RTPForwarder

type RTPForwarder struct {
	AudioStreamID *int64  `json:"audio_stream_id,omitempty"`
	VideoStreamID *int64  `json:"video_stream_id,omitempty"`
	DataStreamID  *int64  `json:"data_stream_id,omitempty"`
	IP            *string `json:"ip,omitempty"`
	Port          *int    `json:"port,omitempty"`
	RTCPPort      *int    `json:"rtcp_port,omitempty"`
	SSRC          *int64  `json:"ssrc,omitempty"`
	Pt            *int64  `json:"pt,omitempty"`
	SubStream     *string `json:"substream,omitempty"`
	SRTP          *bool   `json:"srtp,omitempty"`
}

type RTPForwarders

type RTPForwarders struct {
	PublisherID  *int64          `json:"publisher_id,omitempty"`
	RTPForwarder *[]RTPForwarder `json:"rtp_forwarder,omitempty"`
	StreamID     *int64          `json:"stream_id,omitempty"`
	IP           *string         `json:"ip,omitempty"`
	Port         *int            `json:"port,omitempty"`
	SSRC         *int64          `json:"ssrc,omitempty"`
	Codec        *string         `json:"codec,omitempty"`
	PType        *int64          `json:"ptype,omitempty"`
	SRTP         *bool           `json:"srtp,omitempty"`
	AlwaysOn     *bool           `json:"always_on,omitempty"`
}

type Response

type Response struct {
	VideoRoom     *string          `json:"videoroom,omitempty"`
	AudioBridge   *string          `json:"audiobridge,omitempty"`
	TextRoom      *string          `json:"textroom,omitempty"`
	Streaming     string           `json:"streaming,omitempty"`
	Room          *int64           `json:"room,omitempty"`
	Exists        *bool            `json:"exists,omitempty"`
	Participants  *[]Participant   `json:"participants,omitempty"`
	Rooms         *[]Room          `json:"list,omitempty"`
	Info          *Room            `json:"info,omitempty"`
	RTPForwarders *[]RTPForwarders `json:"rtp_forwarders,omitempty"`
}

type Room

type Room struct {
	Room            *int64  `json:"room,omitempty"`
	Description     *string `json:"description,omitempty"`
	PinRequired     *bool   `json:"pin_required,omitempty"`
	MaxPublishers   *int    `json:"max_publishers,omitempty"`
	Bitrate         *int    `json:"bitrate,omitempty"`
	BitrateCap      *bool   `json:"bitrate_cap,omitempty"`
	FirFreq         *int    `json:"fir_freq,omitempty"`
	AudioCodec      *string `json:"audiocodec,omitempty"`
	VideoCodec      *string `json:"videocodec,omitempty"`
	Record          *bool   `json:"record,omitempty"`
	RecordDir       *string `json:"record_dir,omitempty"`
	LockRecord      *bool   `json:"lock_record,omitempty"`
	NumParticipants *int    `json:"num_participants,omitempty"`
	SamplingRate    *int    `json:"sampling_rate,omitempty"`
	ID              *int64  `json:"id,omitempty"`
	Name            *string `json:"name,omitempty"`
	Type            *string `json:"type,omitempty"`
	Metadata        *string `json:"metadata,omitempty"`
	Enabled         *bool   `json:"enabled,omitempty"`
	AudioAgeMs      *int    `json:"audio_age_ms,omitempty"`
	VideoAgeMs      *int    `json:"video_age_ms,omitempty"`
	Pin             *string `json:"pin,omitempty"`
	IsPrivate       *string `json:"is_private,omitempty"`
	Viewers         *int    `json:"viewers,omitempty"`
	Audio           *bool   `json:"audio,omitempty"`
	AudioPort       *int    `json:"audioport,omitempty"`
	AudioRTCPPort   *int    `json:"audiortcpport,omitempty"`
	AudioPt         *int    `json:"audiopt,omitempty"`
	AudioRTPMap     *string `json:"audiortpmap,omitempty"`
	AudioFMTP       *string `json:"audiofmtp,omitempty"`
	Video           *bool   `json:"video,omitempty"`
	VideoPort       *int    `json:"videoport,omitempty"`
	VideoRTCPPort   *int    `json:"videortcpport,omitempty"`
	VideoPt         *int    `json:"videopt,omitempty"`
	VideoRTPMap     *string `json:"videortpmap,omitempty"`
	VideoFMTP       *int    `json:"videofmtp,omitempty"`
}

type Session

type Session struct {
	// ID is the session_id of this session
	ID uint64

	// Handles is a map of plugin handles within this session
	Handles map[uint64]*Handle

	Events chan interface{}

	// Access to the Handles map should be synchronized with the Session.Lock()
	// and Session.Unlock() methods provided by the embeded sync.Mutex.
	sync.Mutex
	// contains filtered or unexported fields
}

Session represents a session instance on the Janus Gateway.

func (*Session) Attach

func (session *Session) Attach(ctx context.Context, plugin string) (*Handle, error)

Attach sends an attach request to the Gateway within this session. plugin should be the unique string of the plugin to attach to. On success, a new Handle will be returned and error will be nil.

func (*Session) Destroy

func (session *Session) Destroy(ctx context.Context) (*AckMsg, error)

Destroy sends a destroy request to the Gateway to tear down this session. On success, the Session will be removed from the Gateway.Sessions map, an AckMsg will be returned and error will be nil.

func (*Session) KeepAlive

func (session *Session) KeepAlive(ctx context.Context) (*AckMsg, error)

KeepAlive sends a keep-alive request to the Gateway. On success, an AckMsg will be returned and error will be nil.

type SlowLinkMsg

type SlowLinkMsg struct {
	Uplink bool
	Lost   int64
}

type SuccessData

type SuccessData struct {
	ID uint64
}

type SuccessMsg

type SuccessMsg struct {
	Data       SuccessData
	PluginData PluginData
	Session    uint64 `json:"session_id"`
	Handle     uint64 `json:"sender"`
}

type TimeoutMsg

type TimeoutMsg struct {
	Session uint64 `json:"session_id"`
}

type Transaction

type Transaction struct {
	ID           string
	StartedAt    time.Time
	Used         bool
	ResponseChan chan interface{}
	// contains filtered or unexported fields
}

type WebRTCUpMsg

type WebRTCUpMsg struct {
	Session uint64 `json:"session_id"`
	Handle  uint64 `json:"sender"`
}

Jump to

Keyboard shortcuts

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