room

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: 3 Imported by: 0

README

mediocre-api/room

GoDoc

This package provides basic functionality for managing "rooms" of users

A room is a place where multiple users gather together to interact in some way. They have the following qualities:

  • A single unique string identifies the room

  • Rooms are ephemeral, they are not explicitely created nor explicitely destroyed

  • A user can join a room and leave a room. They cannot be in a room twice at the same time. Users must periodically "check in" to a room to confirm they are still in it

  • A user is identified by an arbitrary string

  • Any user can retrieve a list of users currently in a room

Documentation

Overview

Package room implements an abstraction for a basic room system. Rooms can be checked in to and checkd out of by users

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts struct {

	// Prefix can be used if you wish to have two separate room systems being
	// persisted on the same Cmder. Prefix will be part of a string prepended to
	// all key names
	Prefix string

	// CheckInPeriod indicates how long a user has to check in to a room before
	// they are recorded as not being in it anymore. It should not be set to
	// less than 1 second. Defaults to 30 seconds
	CheckInPeriod time.Duration
}

Opts are different options which may be passed into New when creating a system. They all have sane defaults which will cover most use cases

type System

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

System holds on to a Cmder and uses it to implement a basic room system

func New

func New(c util.Cmder, o *Opts) *System

New returns a new System which will use the given Cmder as its persistence layer. The passed in Opts may be used to modify behavior of the System, or may be nil to just use the defaults

func (*System) Cardinality

func (s *System) Cardinality(room string) (int64, error)

Cardinality returns the number of user ids currently checked into a room

func (*System) CheckIn

func (s *System) CheckIn(room, id string) error

CheckIn records that a user with the given id has joined the given room. The user must check in periodically (see the CheckInPeriod field of System) or they will be recorded as not in the room anymore

func (*System) CheckOut

func (s *System) CheckOut(room, id string) error

CheckOut records that a user is no longer in a room

func (*System) Key

func (s *System) Key(room string, extra ...string) string

Key returns a key which can be used to interact with some arbitrary room data directly in redis. This is useful if more complicated, lower level operations are needed to be done

func (*System) Members

func (s *System) Members(room string) ([]string, error)

Members returns the list of user ids currently checked into a room

func (*System) Stop

func (s *System) Stop()

Stop cleans up any go routines that this room system has running for it. It does not remove any persisted data nor close its Cmder

Directories

Path Synopsis
Package broadcast implements a generic system where a user can generate content which can then be consumed by multiple other users.
Package broadcast implements a generic system where a user can generate content which can then be consumed by multiple other users.

Jump to

Keyboard shortcuts

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