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 ¶
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
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 (*System) Ended ¶
Ended records that a broadcast has ended and that the user is no longer broadcasting
func (*System) GetBroadcastID ¶
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 ¶
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 ¶
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 ¶
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