bridge

package
v0.0.0-...-0ddd045 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package bridge provides utilities to create, keep track of and delete WebRTC calls

Index

Constants

View Source
const (
	// TypeOffer describes the event type 'offer'
	TypeOffer string = "offer"

	// TypeAnswer describes the event type 'answer'
	TypeAnswer string = "answer"

	// TypeCandidate describes the event type 'candidate'
	TypeCandidate string = "candidate"

	// TypeMute describes the event type 'mute'
	TypeMute string = "mute"

	// TypeUnmute describes the event type 'unmute'
	TypeUnmute string = "unmute"

	// TypeUser describes the event type 'user'
	TypeUser string = "user"

	// TypeUserJoin describes the event type 'user-join'
	TypeUserJoin string = "user-join"

	// TypeUserLeave describes the event type 'user-leave'
	TypeUserLeave string = "user-leave"
)

Variables

View Source
var (
	// ErrNoSuchRoom indicates no such room with given key exists in the pool of active
	// rooms
	ErrNoSuchRoom = errors.New("No such room")

	// ErrDuplicateRoom indicates the room with given key already exists
	ErrDuplicateRoom = errors.New("Duplicate room")
)
View Source
var (
	ErrNoSuchEvent   = errors.New("no such event")
	ErrChanClosed    = errors.New("channel closed")
	ErrInvalidTrack  = errors.New("track is nil")
	ErrInvalidPacket = errors.New("packet is nil")
)

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge keeps track of active rooms

func NewBridge

func NewBridge() *Bridge

NewBridge returns a new bridge

func (*Bridge) AddRoom

func (b *Bridge) AddRoom(roomHash string) (*Room, error)

AddRoom adds a room to the pool of active rooms with the key 'roomHash'. If the room already exists ErrDuplicateRoom is returned

func (*Bridge) Connect

func (b *Bridge) Connect(username, roomHash string, w http.ResponseWriter, r *http.Request) error

Connect connects a user with 'username' to room and sets up the sognaling websocket

func (*Bridge) GetOrCreateRoom

func (b *Bridge) GetOrCreateRoom(roomHash string) (*Room, error)

GetOrCreateRoom returns an existing room, or if no such room exists, creates a new one and returns it

func (*Bridge) GetRoom

func (b *Bridge) GetRoom(roomHash string) (*Room, error)

GetRoom returns room with 'roomHash' from the pool of active rooms. If the room doesn't exists ErrNoSuchRoom is returned

func (*Bridge) RemoveRoom

func (b *Bridge) RemoveRoom(roomHash string) error

RemoveRoom removes a room with key 'roomHash' from the pool of active rooms. If the room with the given key doesn't exist ErrNoSuchRoom is returned

type Event

type Event struct {
	Type string `json:"type"`

	Offer     *webrtc.SessionDescription `json:"offer,omitempty"`
	Answer    *webrtc.SessionDescription `json:"answer,omitempty"`
	Candidate *webrtc.ICECandidateInit   `json:"candidate,omitempty"`
	User      *PublicUser                `json:"user,omitempty"`
}

Event represents a WebRTC signaling message / event

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message carries a message with the additional info of the sender. A message will be delivered to everyone except the sender

type PublicUser

type PublicUser struct {
	ID string `json:"id"`
	UserInfo
}

PublicUser is the public representation of a user. It only includes necessary data

type Room

type Room struct {
	// contains filtered or unexported fields
}

Room maintains a number of active connections and handles messages from and to clients

func NewRoom

func NewRoom(roomHash string) *Room

NewRoom creates and returns a new room

func (*Room) Broadcast

func (r *Room) Broadcast(data []byte, user *User)

Broadcast sends a message to everyone except sender

func (*Room) BroadcastEvent

func (r *Room) BroadcastEvent(event Event, user *User) error

BroadcastEvent sends an event message to everyone except sender

func (*Room) BroadcastEventJoin

func (r *Room) BroadcastEventJoin(user *User) error

BroadcastEventJoin creates a join event and broadcasts it

func (*Room) BroadcastEventLeave

func (r *Room) BroadcastEventLeave(user *User) error

BroadcastEventLeave creates a leave event and broadcasts it

func (*Room) BroadcastEventMute

func (r *Room) BroadcastEventMute(user *User) error

BroadcastEventMute creates microphone mute event and broadcasts it

func (*Room) BroadcastEventUnmute

func (r *Room) BroadcastEventUnmute(user *User) error

BroadcastEventUnmute creates microphone unmute event and broadcasts it

func (*Room) GetParticipants

func (r *Room) GetParticipants(u *User) []*User

GetParticipants returns all users except the provided user as a slice

func (*Room) GetUsersList

func (r *Room) GetUsersList() []*User

GetUsersList returns the user map as a slice of users

func (*Room) Join

func (r *Room) Join(user *User)

Join connects the user to the room

func (*Room) Leave

func (r *Room) Leave(user *User)

Leave disconnects the user from the room

func (*Room) Run

func (r *Room) Run()

Run runs the main event loop

type User

type User struct {
	ID string // A unique ID of the user
	// contains filtered or unexported fields
}

User keeps track of a websocket connection for signaling, a WebRTC peer connection and connects hub, room and user

func NewUser

func NewUser(username string, conn *websocket.Conn, pc *webrtc.PeerConnection, room *Room) *User

NewUser creates and returns a new user

func (*User) AddListeners

func (u *User) AddListeners() error

AddListeners adds all neccesary WebRTC PC event handlers

func (*User) AddTrack

func (u *User) AddTrack(ssrc uint32) error

AddTrack adds track to peer connection

func (*User) GetOutTracks

func (u *User) GetOutTracks() map[uint32]*webrtc.Track

GetOutTracks return outgoing tracks

func (*User) Offer

func (u *User) Offer() (webrtc.SessionDescription, error)

Offer return a offer

func (*User) ReadRTP

func (u *User) ReadRTP() (*rtp.Packet, error)

ReadRTP reads rtp packets

func (*User) SendEventUser

func (u *User) SendEventUser() error

SendEventUser sends user to client to identify himself

func (*User) SendOffer

func (u *User) SendOffer() error

SendOffer creates webrtc offer

func (*User) ToPublic

func (u *User) ToPublic() *PublicUser

ToPublic returns the public representation of a user

func (*User) Watch

func (u *User) Watch()

Watch for debug

func (*User) WriteRTP

func (u *User) WriteRTP(pkt *rtp.Packet) error

WriteRTP sends rtp packets to user's outgoing tracks

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Mute     bool   `josn:"mute"`
}

UserInfo holds some user information

Jump to

Keyboard shortcuts

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