switchboard

package
v0.0.0-...-12eefb5 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package switchboard contains logic for routing audio data among channels and their clients.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoChannel is the error returned when performing operations on a channel that
	// does not exist
	ErrNoChannel = errors.New("no channel")

	// ErrUserAlreadyInChannel is the error returned when attempting to move a user
	// into a channel they are already in.
	ErrUserAlreadyInChannel = errors.New("user already in channel")
)

Functions

This section is empty.

Types

type Channel

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

The Channel type represents a collection of clients all communicating.

func (*Channel) Join

func (ch *Channel) Join(name string) (*Client, error)

Join a channel under a given name. Returns ErrUserAlreadyInChannel if a user already exists within the channel.

func (*Channel) Leave

func (ch *Channel) Leave(name string)

Leave a channel, is a noop if the user does not exist in the channel.

func (*Channel) Write

func (ch *Channel) Write(ctx context.Context, a *audio.Audio) error

Write the provided audio data to the channel, this function blocks until all clients have read the audio data or the provided context is cancelled.

type Client

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

The Client type represents a single client communicating via the switchboard.

func (*Client) Read

func (e *Client) Read(ctx context.Context) (*audio.Audio, error)

Read audio data sent to the client, this function blocks until audio data is read or the provided context is cancelled.

func (*Client) Write

func (e *Client) Write(ctx context.Context, a *audio.Audio) error

Write audio data to the client, this function blocks until audio data is written to the client or the provided context is cancelled.

type SwitchBoard

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

The SwitchBoard type is used to route audio data between clients in various channels.

func New

func New() *SwitchBoard

New creates a new, empty switchboard.

func (*SwitchBoard) Channel

func (sb *SwitchBoard) Channel(name string) (*Channel, error)

Channel returns the Channel instance for a given name. Creates the channel if it does not exist.

Jump to

Keyboard shortcuts

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