janus

package module
v0.0.0-...-5d1e9c5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT Imports: 8 Imported by: 2

README

janus-go

only support websocket transport

Update 1/14/2020

Notedit, the original creator is busy with other things, and has handed over the maintainer role on this project.

You can find a fork by @nustiueudinastea Here: https://github.com/nustiueudinastea/janus-go

Please see if it suits your needs, and feel free to file PRs, issues and suggestions there.

Thanks, Cameron and Alex

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

func ParseEvent

func ParseEvent(data []byte) (interface{}, error)

func StructToMap

func StructToMap(obj interface{}) (map[string]interface{}, error)

Types

type AckMsg

type AckMsg struct{}

type BaseEvent

type BaseEvent struct {
	Emitter   string
	Type      int
	Subtype   int
	Timestamp int64
	Session   uint64 `json:"session_id"`
	Handle    uint64 `json:"handle_id"`
	OpaqueID  string `json:"opaque_id"`
	Event     map[string]interface{}
}

type BaseMsg

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

func ParseMessage

func ParseMessage(data []byte) (*BaseMsg, interface{}, error)

type CoreEvent

type CoreEvent struct {
	BaseEvent
}

type DateTime

type DateTime struct {
	time.Time
}

func (*DateTime) IsSet

func (dt *DateTime) IsSet() bool

func (DateTime) MarshalJSON

func (dt DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(b []byte) (err error)

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 ExternalEvent

type ExternalEvent struct {
	BaseEvent
	Event ExternalEventBody `json:"event"`
}

type ExternalEventBody

type ExternalEventBody struct {
	Schema string
	Data   map[string]interface{}
}

type Gateway

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

	// Stored token to use for authentication.
	// See https://janus.conf.meetecho.com/docs/auth.html#token
	Token string

	// Access to the Sessions map should be synchronized with the Gateway.Lock()
	// and Gateway.Unlock() methods provided by the embedded sync.Mutex.
	sync.Mutex
	// 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) Create

func (gateway *Gateway) Create() (*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() (*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() (*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(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(body interface{}) (*SuccessMsg, error)

Request sends a sync request

func (*Handle) Trickle

func (handle *Handle) Trickle(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(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 HandleEvent

type HandleEvent struct {
	BaseEvent
	Event HandleEventBody `json:"event"`
}

type HandleEventBody

type HandleEventBody struct {
	Name   string
	Plugin string
}

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 JSEPEvent

type JSEPEvent struct {
	BaseEvent
	Event JSEPEventBody `json:"event"`
}

type JSEPEventBody

type JSEPEventBody struct {
	Owner string
	JSEP  JSEPInfo
}

type JSEPInfo

type JSEPInfo struct {
	Type string
	SDP  string
}

type MediaEvent

type MediaEvent struct {
	BaseEvent
}

type MediaMsg

type MediaMsg struct {
	Type      string
	Receiving bool
}

type PluginData

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

type PluginEvent

type PluginEvent struct {
	BaseEvent
	Event PluginEventBody `json:"event"`
}

type PluginEventBody

type PluginEventBody 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 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(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() (*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() (*AckMsg, error)

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

type SessionEvent

type SessionEvent struct {
	BaseEvent
	Event SessionEventBody `json:"event"`
}

type SessionEventBody

type SessionEventBody struct {
	Name      string
	Transport map[string]interface{}
}

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 TextroomPostMsg

type TextroomPostMsg struct {
	Textroom string
	Room     int // this has changed to string in janus API
	From     string
	Date     DateTime
	Text     string
	Whisper  bool
}

func ParseTextroomMessage

func ParseTextroomMessage(data []byte) (*TextroomPostMsg, error)

type TimeoutMsg

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

type TransportEvent

type TransportEvent struct {
	BaseEvent
	Event TransportEventBody `json:"event"`
}

type TransportEventBody

type TransportEventBody struct {
	Transport string
	ID        string
	Data      map[string]interface{}
}

type WebRTCEvent

type WebRTCEvent struct {
	BaseEvent
}

type WebRTCUpMsg

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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