janus

package module
v0.0.0-...-1c3db3c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 10 Imported by: 0

README

janus-go

only support websocket transport

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AckMsg

type AckMsg struct {
	Type string `json:"janus"`
	ID   string `json:"transaction"`
	Hint string `json:"hint,omitempty"`
}

type BaseMsg

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

type DetachedMsg

type DetachedMsg struct{}

type ErrorData

type ErrorData struct {
	Code   int
	Reason string
}

type ErrorMsg

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

func (*ErrorMsg) Error

func (err *ErrorMsg) Error() string

type EventMsg

type EventMsg struct {
	Type       string                 `json:"janus"`
	ID         string                 `json:"transaction"`
	Session    uint64                 `json:"session_id"`
	Handle     uint64                 `json:"sender,omitempty"`
	Plugindata PluginData             `json:"plugindata"`
	Jsep       map[string]interface{} `json:"jsep"`
}

event types

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.RWMutex
	// contains filtered or unexported fields
}

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

func Connect

func Connect(wsURL string) (*Gateway, error)

Connect initiates a webscoket connection with the Janus Gateway

func (*Gateway) Close

func (gateway *Gateway) Close() error

Close closes the underlying connection to the Gateway.

func (*Gateway) CreateSession

func (gateway *Gateway) CreateSession(ctx context.Context, msg BaseMsg) (*SuccessMsg, error)

CreateSession 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, msg BaseMsg) (*InfoMsg, error)

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

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, msg BaseMsg) (*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, msg HandlerMessageJsep) (ack *AckMsg, err 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 AckMsg will be returned and error will be nil.

func (*Handle) Request

func (handle *Handle) Request(ctx context.Context, msg HandlerMessage) (*SuccessMsg, error)

Request sends a sync request

func (*Handle) Trickle

func (handle *Handle) Trickle(ctx context.Context, msg TrickleOne) (*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, msg TrickleMany) (*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 HandlerMessage

type HandlerMessage struct {
	BaseMsg
	Handle uint64         `json:"handle_id,omitempty"`
	Body   map[string]any `json:"body"`
}

type HandlerMessageJsep

type HandlerMessageJsep struct {
	HandlerMessage
	Jsep map[string]any `json:"jsep,omitempty"`
}

type HangupMsg

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

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 `json:"janus"`
	Session   uint64 `json:"session_id,omitempty"`
	Handle    uint64 `json:"sender,omitempty"`
	Mid       string `json:"mid"`
	MediaType string `json:"type"`
	Receiving bool   `json:"receiving"`
}

type PluginData

type PluginData struct {
	Plugin string                 `json:"plugin"`
	Data   map[string]interface{} `json:"data"`
}

type PluginInfo

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

type Session

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

	Data map[string]any // Additional data for the session injected by external sources

	// 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) AttachSession

func (session *Session) AttachSession(ctx context.Context, msg BaseMsg) (*SuccessMsg, error)

AttachSession 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) DestroySession

func (session *Session) DestroySession(ctx context.Context, msg BaseMsg) (ack *SuccessMsg, err error)

DestroySession 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, msg BaseMsg) (*AckMsg, error)

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

func (*Session) LongPoll

func (s *Session) LongPoll(ctx context.Context, maxEv int, msg BaseMsg) (events []any, err error)

LongPoll will trigger events related to session sent from plugins reads all the available events until maxEv is reached or timeout occurs

type SlowLinkMsg

type SlowLinkMsg struct {
	Type    string `json:"janus"`
	Session uint64 `json:"session_id,omitempty"`
	Handle  uint64 `json:"sender,omitempty"`
	Uplink  bool
	Lost    int64
}

type SuccessData

type SuccessData struct {
	ID uint64 `json:"id"`
}

type SuccessMsg

type SuccessMsg struct {
	Type string      `json:"janus"`
	ID   string      `json:"transaction"`
	Data SuccessData `json:"data,omitempty"`
}

type TimeoutMsg

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

type TrickleMany

type TrickleMany struct {
	BaseMsg
	HandleR    uint64 `json:"handle_id,omitempty"`
	Candidates []any  `json:"candidates"`
}

type TrickleOne

type TrickleOne struct {
	BaseMsg
	HandleR   uint64 `json:"handle_id,omitempty"`
	Candidate any    `json:"candidate"`
}

type WebRTCUpMsg

type WebRTCUpMsg struct {
	Type    string `json:"janus"`
	Session uint64 `json:"session_id,omitempty"`
	Handle  uint64 `json:"sender,omitempty"`
}

Jump to

Keyboard shortcuts

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