broadcast

package
v0.0.0-...-589bc69 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package broadcast implements a generic system where a user can generate content which can then be consumed by multiple other users. This package mostly handles whether or not a user is broadcasting, and what id they are broadcasting to

- A user can only have a single broadcast at a time

- It must be periodically verified that a user is still broadcasting

  • A signature is given when starting a broadcast which can optionally be later used to authenticate a broadcast ID

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserIsBroadcasting = common.ExpectedErr{Code: 400, Err: "user already broadcasting"}
	ErrInvalidID          = common.ExpectedErr{Code: 400, Err: "invalid broadcast.ID"}
	ErrBroadcastEnded     = common.ExpectedErr{Code: 400, Err: "broadcast already ended"}
)

Errors which can be expected from various methods in this package

Functions

This section is empty.

Types

type ID

type ID string

ID represents the unique identifier for a broadcast. IDs have certain data embedded in them, and methods for retrieving that data

func (ID) User

func (id ID) User() string

User returns the name of the user encoded into the id

type System

type System struct {
	*room.System

	// When set a signature will be generated for broadcast IDs which can be
	// used to authenticate that they are legitimate
	Secret []byte

	// Prefix can be filled in on a System returned from New, and is used as
	// part of a prefix on all keys used by this system. Useful if you want to
	// have two broadcast Systems using the same Cmder
	Prefix string

	// This is the amount of seconds which is allowed to elapse with no
	// StillBroadcasting calls for a broadcast before it is considered dead.
	// Defaults to 30
	AlivenessPeriod int
	// contains filtered or unexported fields
}

System holds on to a room.System and implements a broadcast system around it, using the room.System to track what users are in what broadcasts

func New

func New(c util.Cmder) *System

New returns a new initialized system

func (*System) Ended

func (s *System) Ended(id ID) error

Ended records that a broadcast has ended and that the user is no longer broadcasting

func (*System) GetBroadcastID

func (s *System) GetBroadcastID(user string) (ID, error)

GetBroadcastID returns the currently active broadcast id for the user, or empty string if they are not broadcasting. An error is only returned in the case of a database error

func (*System) NewID

func (s *System) NewID(user string) (ID, string)

NewID returns a new broadcast ID for the given user, along with a signature which can verify that the holder of the id is the true owner. This method makes no database changes, see StartBroadcast if that's what you're looking for. The signature will be empty string if Secret is not set on the System

func (*System) StartBroadcast

func (s *System) StartBroadcast(user string) (ID, string, error)

StartBroadcast returns a unique broadcast id for the user to use, and the signature for that id which can be used to verify they are the real broadcaster. The signature will be empty string if Secret is not set on the System. This will error if the user is already broadcasting

func (*System) StillAlive

func (s *System) StillAlive(id ID) error

StillAlive records that the broadcast is still actively going. This must be called periodically or the user will no longer be considered broadcasting, see AlivenessPeriod

func (*System) Verify

func (s *System) Verify(id ID, sig string) bool

Verify returns wheither or not the given sig is the valid signature for the given ID, i.e. they were both returned from the same call to NewID or StartBroadcast. Returns false if Secret is not set on the System

Jump to

Keyboard shortcuts

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