NotLimited represents a members container has no member limit
const NotLimited = -1
Unexpected represents an unexpected error
const Unexpected = -2
func EncodeClient(client *Client) string
EncodeClient converts the client struct instance into a string. Use DecodeClient to revert it back to the client struct instance.
func IsUserInRoom(name string, userData *user.User) bool
IsUserInRoom returns true if the user with the matching name is in a members container.
func ResetUser(name string, userData *user.User)
ResetUser resets the user key data with the matching name.
func UnlockExclusive(userData *user.User, key string)
UnlockExclusive forcefully unlocks members exclusive
Client is a representation of the user client with its IP addresses and IDs. The struct is derived from *user.User
type Client struct { SID string ID string MeshAddr string JoinedAt int64 // Available for UDP only: P2P PublicAddr string // Available for UDP only: P2P PrivateAddrBytes []byte // User data copy UserData map[string]interface{} }
func DecodeClient(str string) *Client
DecodeClient reverts back the encoded client struct instance. It returns a nil if the decoding fails.
Members a container to store member data. shard and storage are exclusive shard is used when the limit is -1 storage is used when the limit more than 0
type Members struct {
// contains filtered or unexported fields
}
func New(name string) *Members
New creates a members container without a limit to the number of members.
func NewExclusive(name string) *Members
NewExclusive creates an exclusive members container that does NOT allow the same user to be in another members container without a limit to the number of members.
func NewExclusiveLimited(name string, limit uint) *Members
NewExclusiveLimited creates an exclusive members container that does NOT allow the same user to be in another members container with a limit to the number of members.
func NewLimited(name string, limit uint) *Members
NewLimited creates a members container with a limit to the number of members.
func (m *Members) Add(userData *user.User, meshAddr string) error
Add adds a userData.ID as key and userData.SID as value to the container.
func (m *Members) AddIf(userData *user.User, meshAddr string, check func() bool) error
AddIf allows the user given to be added to the members if the given callback returns true.
func (m *Members) AddReserve(userData *user.User) bool
AddReserve makes a reservation for the given user to make sure that the user may join the members container later for sure.
func (m *Members) AddReserveByUserID(userID string) bool
AddReserveByUserID makes a reservation for the given user ID to make sure that the user may join the members container later for sure.
func (m *Members) Count() int
Count returns the number of members in the container.
func (m *Members) Exists(userID string) bool
Exists returns true if the given key exists in the members container.
func (m *Members) GetAll() map[string]*Client
GetAll returns all member SIDs as a map. The key of the map is user ID and the value of the map is user.
func (m *Members) GetExclusiveLockKey() string
GetExclusiveLockKey returns the key of user exclusive lock
func (m *Members) GetLimit() int
GetLimit returns the maximum allowed number of members.
[NOTE] If there is no limit, it returns NotLimited -1. [NOTE] If *Member is somehow nil, it returns Unexpected -2.
func (m *Members) GetName() string
GetName returns the name of members container.
func (m *Members) GetOne(userID string) *Client
GetOne returns the member user of the given user ID. If the key does not exist, it returns a nil instead.
func (m *Members) IsAddAllowed(clientsToBeAdded int) bool
IsAddAllowed returns true if the members contain still has room to add more users.
func (m *Members) Keys() []string
Keys returns all member keys as an array. The keys are an array of user IDs.
func (m *Members) Remove(userData *user.User) bool
Remove removes a member data from the container.
func (m *Members) RemoveAll()
RemoveAll removes all member users form the members container.
func (m *Members) RemoveReserve(userData *user.User) bool
RemoveReserve cancels the reservation for the given user.
func (m *Members) RemoveReserveByUserID(userID string) bool
RemoveReserveByUserID cancels the reservation for the given user ID.
func (m *Members) UpdateClientByID(uid, sid, pubAddr string, privateAddrs []byte, meshAddr string) bool
UpdateClientByID updates internal client data