package room

import "github.com/Diarkis/diarkis/client/go/modules/room"

Index

Constants

const UpdateObjectDelMode = byte(3)

UpdateObjectDelMode deletes a room object by its name.

const UpdateObjectIncrMode = byte(1)

UpdateObjectIncrMode increments an existing room object's properties.

const UpdateObjectSetMode = byte(2)

UpdateObjectSetMode creates or replaces a room object by the given properties.

Types

type ChatData

type ChatData struct {
	SenderUID string
	Timestamp int64
	Message   string
}

ChatData represents a chat data This is used for chat log

type ListItem

type ListItem struct {
}

ListItem represents a room list item This is used for room finding

type Room

type Room struct {
	ID string
}

Room represents Diarkis Room client

func (*Room) BroadcastTo

func (room *Room) BroadcastTo(roomID string, message []byte, reliable bool)

BroadcastTo broadcasts a message to all members in a room

func (*Room) CancelReservation

func (room *Room) CancelReservation(userIDs []string)

CancelReservation cancels a room reservation

func (*Room) Chat

func (room *Room) Chat(msg string)

Chat sends a message to a room

func (*Room) Create

func (room *Room) Create(maxMembers uint16, allowEmpty bool, join bool, ttl uint16, interval uint16)

Create creates a new room with the specified parameters.

func (*Room) CreateOrJoinByCustomID

func (room *Room) CreateOrJoinByCustomID(customID string, maxMembers uint16, interval uint16, allowTransferOwnership bool, joinPayload []byte)

CreateOrJoinByCustomID creates a room with the given customID and parameters if an already existing room with the same customID does not exist. Otherwise try to join the room.

func (*Room) CreateRoomWithOwnershipTransfer

func (room *Room) CreateRoomWithOwnershipTransfer(maxMembers uint16, allowEmpty bool, join bool, ttl uint16, interval uint16, allowTransferOwnership bool)

CreateRoomWithOwnershipTransfer creates a new room with the specified parameters.

func (*Room) DeleteOnCreate

func (room *Room) DeleteOnCreate()

DeleteOnCreate deletes all of the callbacks assigned via OnCreate

func (*Room) DeleteOnCreateRoomWithTransferOwnership

func (room *Room) DeleteOnCreateRoomWithTransferOwnership()

DeleteOnCreateRoomWithTransferOwnership deletes all of the callbacks assigned via OnCreateRoomWithTransferOwnership

func (*Room) DeleteOnJoin

func (room *Room) DeleteOnJoin()

DeleteOnJoin removes all callbacks assigned via OnJoin

func (*Room) DeleteOnMemberJoin

func (room *Room) DeleteOnMemberJoin()

DeleteOnMemberJoin removes all callbacks assigned via OnJoin

func (*Room) DeleteOnMessageExtended

func (room *Room) DeleteOnMessageExtended()

DeleteOnMessageExtended removes all callbacks set by OnMessageExtended

func (*Room) DeleteOnMessageExtendedResponse

func (room *Room) DeleteOnMessageExtendedResponse()

DeleteOnMessageExtendedResponse removes all callbacks set by OnMessageExtendedResponse

func (*Room) DeleteOnTransferOwnershipResponse

func (room *Room) DeleteOnTransferOwnershipResponse()

DeleteOnTransferOwnershipResponse removes all callbacks set by OnTransferOwnershipResponse

func (*Room) FindRoomsByType

func (room *Room) FindRoomsByType(roomType int, limit int)

FindRoomsByType finds rooms by type - roomType: the type of the room - limit: the maximum number of rooms to return

func (*Room) GetChatLog

func (room *Room) GetChatLog()

GetChatLog gets the chat log of a room

func (*Room) GetMemberIDs

func (room *Room) GetMemberIDs()

GetMemberIDs gets the member IDs of a room

func (*Room) GetNumOfMembers

func (room *Room) GetNumOfMembers(roomID string)

GetNumOfMembers gets the number of members in a room

func (*Room) GetOwnerID

func (room *Room) GetOwnerID(roomID string)

GetOwnerID gets the owner ID of a room - roomID: the ID of the room to get the owner ID of

func (*Room) GetProperty

func (room *Room) GetProperty(keys []string)

GetProperty retrieves properties of the room.

func (*Room) GetRoomInfoByRoomID

func (room *Room) GetRoomInfoByRoomID(roomID string)

GetRoomInfoByRoomID gets room info by roomID

func (*Room) IncrementProperty

func (room *Room) IncrementProperty(key string, delta int64, sync bool)

IncrementProperty increments a property of the room.

func (*Room) Join

func (room *Room) Join(roomID string, message []byte)

Join joins a room with the given roomID

func (*Room) JoinRandom

func (room *Room) JoinRandom(maxMembers int, ttl int, msg []byte, interval int)

JoinRandom joins a random room or creates a new room if no room is found

func (*Room) Leave

func (room *Room) Leave(roomID string, message []byte)

Leave leaves a room roomID: the room ID to leave message: the message to send to the room

func (*Room) Message

func (room *Room) Message(roomID string, memberIDs []string, message []byte, reliable bool)

Message sends a message to a room - roomID: the ID of the room to send the message to - memberIDs: the IDs of the members to send the message to - message: the message to send - reliable: whether the message should be sent by RUDP or UDP

func (*Room) MessageExtended

func (room *Room) MessageExtended(broadcast bool, memberIDs []string, message []byte, options uint16, reliable dpacket.ReliableFlag)

MessageExtended sends a message to a room or to a specific members - broadcast: broadcast the message to the room instead of sending it to the given memberIDs - memberIDs: the IDs of the members to send the message to. Ignored if broacast is true - message: the message to send - options: options to affect the format of the payload the server will push to the client - reliable: send the message as reliable

func (*Room) Migrate

func (room *Room) Migrate()

Migrate migrates a room that the user is currently in. This operation can only be performed by the owner of the room. When successful, the owner user raises OnConnect event with reconnect flag true. All members of the room will automatically join the new migrated room without sending join broadcast.

func (*Room) Move

func (room *Room) Move(newRoomID string, leaveMessage []byte, joinMessage []byte, callback func(bool, uint))

Move moves a room that the user is currently in.

func (*Room) OnCancelReservation

func (room *Room) OnCancelReservation(callback func(success bool, msg []byte))

OnCancelReservation assigns a callback on cancel reservation event

func (*Room) OnChatLog

func (room *Room) OnChatLog(callback func(bool, []ChatData, []byte))

OnChatLog assigns a callback on chat log event

func (*Room) OnChatPush

func (room *Room) OnChatPush(callback func(data ChatData))

OnChatPush assigns a callback on chat push event

func (*Room) OnChatSync

func (room *Room) OnChatSync(callback func(bool, []byte))

OnChatSync assigns a callback on chat sync event

func (*Room) OnCreate

func (room *Room) OnCreate(callback func(bool, string, uint))

OnCreate is a callback setter that is called when a room is created The callback is called with the following arguments: - success: whether the room was created successfully - roomID: the ID of the room that was created - roomCreateTime: the time at which the room was create

func (*Room) OnCreateByCustomID

func (room *Room) OnCreateByCustomID(callback func(success bool, roomID string, roomCreatedTime uint, isOwner bool))

OnCreateByCustomID is a callback setter that is called when a room is created with a custom ID The callback is called with the following arguments: - success: whether the room was created successfully - roomID: the ID of the room that was created - roomCreateTime: the time at which the room was create - isOwner: the user is the owner of the room or not

func (*Room) OnCreateRoomWithTransferOwnership

func (room *Room) OnCreateRoomWithTransferOwnership(callback func(bool, string, uint))

OnCreateRoomWithTransferOwnership is a callback setter that is called when a room is created with transfer ownership flag The callback is called with the following arguments: - success: whether the room was created successfully - roomID: the ID of the room that was created - roomCreateTime: the time at which the room was create

func (*Room) OnFindRoomsByType

func (room *Room) OnFindRoomsByType(callback func(success bool, room []ListItem))

OnFindRoomsByType is a callback setter that is called when a room is created The callback is called with the following arguments: - success: whether the room was created successfully - roomListItem: the list of roomListItem

func (*Room) OnGetMemberIDs

func (room *Room) OnGetMemberIDs(callback func(bool, []byte, [][]byte))

OnGetMemberIDs assigns a callback on get member IDs event

func (*Room) OnGetNumOfMembers

func (room *Room) OnGetNumOfMembers(callback func(bool, []byte, int, int))

OnGetNumOfMembers assigns a callback on get number of members event

func (*Room) OnGetOwnerID

func (room *Room) OnGetOwnerID(callback func(bool, []byte))

OnGetOwnerID assigns a callback on get owner ID event The callback is called with the following arguments: - success: whether the room was joined successfully - ownerID: the ID of the owner of the room

func (*Room) OnGetRoomInfo

func (room *Room) OnGetRoomInfo(callback func(roomID string, currentMembers uint16,
	maxMembers uint16, memberIDs []string, ownerID string, allowEmpty bool, ttl int64,
	lastPropUpdated int64, updaterSID string, interval int64, created int64,
	reserves []string, allowTransferOwnership bool)) bool

OnGetRoomInfo assigns a callback on room get room info event The callback is called with the following arguments:

func (*Room) OnJoin

func (room *Room) OnJoin(callback func(bool, uint))

OnJoin is a callback setter that is called when a room is joined The callback is called with the following arguments: - success: whether the room was joined successfully - roomCreatedTime: the time at which the room was created

func (*Room) OnLeave

func (room *Room) OnLeave(callback func(bool))

OnLeave assigns a callback on leave event

func (*Room) OnMemberBroadcast

func (room *Room) OnMemberBroadcast(callback func([]byte))

OnMemberBroadcast assigns a callback on member broadcast event

func (*Room) OnMemberJoin

func (room *Room) OnMemberJoin(callback func([]byte))

OnMemberJoin assigns a callback on member join event

func (*Room) OnMemberLeave

func (room *Room) OnMemberLeave(callback func([]byte))

OnMemberLeave assigns a callback on member leave event

func (*Room) OnMemberMessage

func (room *Room) OnMemberMessage(callback func([]byte))

OnMemberMessage is a callback setter that is called when a message is received from a member The callback is called with the following arguments: - message: the message that was received

func (*Room) OnMessageExtended

func (room *Room) OnMessageExtended(callback func(message []byte, broadcasted bool, senderID *string))

OnMessageExtended is a callback setter that is called when a message extended is received from a member The callback is called with the following arguments: - message: the message that was received - broadcasted: if true the message was broadcasted to all members - senderID: if non nil the id of the user who sent the message

func (*Room) OnMessageExtendedResponse

func (room *Room) OnMessageExtendedResponse(callback func(bool))

OnMessageExtendedResponse is a callback setter that is called when a room's message extended failed. The callback is called with the following argument: - success: whether the message extended was successful

func (*Room) OnMigrate

func (room *Room) OnMigrate(callback func(bool, string))

OnMigrate assigns a callback on migrate event

func (*Room) OnObjectUpdatePush

func (room *Room) OnObjectUpdatePush(callback func(uint8, string, map[string]float64))

OnObjectUpdatePush assigns a callback on object update push event

func (*Room) OnObjectUpdateResponse

func (room *Room) OnObjectUpdateResponse(callback func(msg []byte))

OnObjectUpdateResponse assigns a callback on object update response event

func (*Room) OnP2PInit

func (room *Room) OnP2PInit(callback func(success bool))

OnP2PInit is a callback setter that is called when P2P started based on Room. The callback is called with the following arguments: - success: whether the P2P was started successfully

[IMPORTANT] This callback is just to check if the request is accepted by the server

To handle the P2P information pushed by the server, use p2p.OnStartP2PSync This is because the packet format for Push is shared between Room and MatchMaker.

func (*Room) OnPropGetResponse

func (room *Room) OnPropGetResponse(callback func(success bool, props [][]byte))

OnPropGetResponse assigns a callback on get property event response

func (*Room) OnPropIncrPush

func (room *Room) OnPropIncrPush(callback func(success bool, key string, numProps uint64))

OnPropIncrPush assigns a callback on property incr event push

func (*Room) OnPropIncrResponse

func (room *Room) OnPropIncrResponse(callback func(success bool, numProps int64))

OnPropIncrResponse assigns a callback on property incr event response

func (*Room) OnPropSyncResponse

func (room *Room) OnPropSyncResponse(callback func(success bool, props map[string][]byte))

OnPropSyncResponse assigns a callback on sync properties event

func (*Room) OnPropUpdatePush

func (room *Room) OnPropUpdatePush(callback func(rops map[string][]byte))

OnPropUpdatePush assigns a callback on property update event push

func (*Room) OnPropUpdateResponse

func (room *Room) OnPropUpdateResponse(callback func(success bool))

OnPropUpdateResponse assigns a callback on get property event response

func (*Room) OnRegister

func (room *Room) OnRegister(callback func(success bool, msg []byte))

OnRegister is a callback setter that is called when a room is created The callback is called with the following arguments: - success: whether the room was created successfully - msg: Error message byte array if success was false.

func (*Room) OnRelayProfilePush

func (room *Room) OnRelayProfilePush(callback func(msg []byte))

OnRelayProfilePush assigns a callback on relay profile push event

func (*Room) OnRelayProfileResponse

func (room *Room) OnRelayProfileResponse(callback func(success bool, msg []byte))

OnRelayProfileResponse assigns a callback on relay profile response event

func (*Room) OnRelayPush

func (room *Room) OnRelayPush(callback func(msg []byte))

OnRelayPush assigns a callback on relay push event

func (*Room) OnRelayResponse

func (room *Room) OnRelayResponse(callback func(success bool, msg []byte))

OnRelayResponse assigns a callback on relay response event

func (*Room) OnRelayToProfilePush

func (room *Room) OnRelayToProfilePush(callback func(msg []byte))

OnRelayToProfilePush assigns a callback on relay to profile push event

func (*Room) OnRelayToProfileResponse

func (room *Room) OnRelayToProfileResponse(callback func(success bool, msg []byte))

OnRelayToProfileResponse assigns a callback on relay to profile response event

func (*Room) OnRelayToPush

func (room *Room) OnRelayToPush(callback func(msg []byte))

OnRelayToPush assigns a callback on relay to push event

func (*Room) OnRelayToResponse

func (room *Room) OnRelayToResponse(callback func(success bool, msg []byte))

OnRelayToResponse assigns a callback on relay to response event

func (*Room) OnReserve

func (room *Room) OnReserve(callback func(success bool, msg []byte))

OnReserve assigns a callback on reserve event

func (*Room) OnRoomOwnerChange

func (room *Room) OnRoomOwnerChange(callback func(message []byte))

OnRoomOwnerChange is a callback setter that is called when the owner of the room changes. The callback is called with the following arguments: - roomID: the new ID of the room

func (*Room) OnStartP2PSyncDoNotUse

func (room *Room) OnStartP2PSyncDoNotUse()

OnStartP2PSyncDoNotUse does nothing. You will be happy with p2p.OnStartP2PSync

func (*Room) OnTransferOwnershipResponse

func (room *Room) OnTransferOwnershipResponse(callback func(bool))

OnTransferOwnershipResponse is a callback setter that is called when a room's ownership transfer response is received. The callback is called with the following argument: - success: whether the ownership transfer was successful

func (*Room) Register

func (room *Room) Register(roomType int, roomName string, roomMetadata string)

Register a room (the client is already a member of) with a type (used by FindRoomsByType). OnRegister is called when the room is registered. Register registers a room with the given parameters - roomType: the type of the room - roomName: the name of the room - roomMetadata: Extra string data for the room registered.

func (*Room) Relay

func (room *Room) Relay(message []byte, reliable bool)

Relay sends a message to a room

func (*Room) RelayProfile

func (room *Room) RelayProfile(message []byte, reliable bool)

RelayProfile sends a message to a room

func (*Room) RelayTo

func (room *Room) RelayTo(memberIDs []string, message []byte, reliable bool)

RelayTo sends a message to a room memebers

func (*Room) RelayToProfile

func (room *Room) RelayToProfile(memberIDs []string, message []byte, reliable bool)

RelayToProfile sends a message to a room memebers

func (*Room) Reserve

func (room *Room) Reserve(userIDs []string)

Reserve reserves a room

func (*Room) SetupAsTCP

func (room *Room) SetupAsTCP(tcpClient *tcp.Client) bool

SetupAsTCP sets up Room client as TCP client

func (*Room) SetupAsUDP

func (room *Room) SetupAsUDP(udpClient *udp.Client) bool

SetupAsUDP sets up Room client as UDP client

func (*Room) SetupOnJoinEvent

func (room *Room) SetupOnJoinEvent(ver uint8, cmd uint16)

SetupOnJoinEvent has been deprecated

func (*Room) SetupOnOffline

func (room *Room) SetupOnOffline(callback func())

SetupOnOffline registers a callback which is triggered when server goes offline state

func (*Room) StartP2PSync

func (room *Room) StartP2PSync(clients uint8)

StartP2PSync Starts peer-to-peer communications with the remote clients in the same room. This method raises OnStartP2PSync event. Params: - clients: Number of clients to be linked directly via peer-to-peer.Other remote clients in the room will be linked via relay.

func (*Room) SyncProperties

func (room *Room) SyncProperties()

SyncProperties etrieve properties of the room.

Raises OnPropertySync event.

Only properties with byte array value will be synchronized.

func (*Room) TransferOwnership

func (room *Room) TransferOwnership(roomID string, newOwnerUID string)

TransferOwnership transfers ownership of the room with the given room ID to the provided UID. If the new owner's UID is empty, a random room member will be selected. This corresponds to the JSON definition for TransferOwnership:

func (*Room) UpdateObject

func (room *Room) UpdateObject(mode byte, name string, obj map[string]float64, reliable bool)

UpdateObject updates a room object by the given properties. mode: UpdateObjectIncrMode, UpdateObjectSetMode, UpdateObjectDelMode

func (*Room) UpdateProperty

func (room *Room) UpdateProperty(props map[string][]byte, sync bool)

UpdateProperty updates properties of the room.