Constructor
new Client(opts)
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
Properties
|
Members
-
readonly lobbyRoomList :Array.<LobbyRoom>
-
获取房间列表
-
readonly player :Player
-
获取当前玩家
-
readonly room :Room
-
获取当前所在房间
-
readonly userId :String
-
获取用户 id
Methods
-
addRoomExpectedUserIds(expectedUserIds)
-
增加房间占位玩家 Id 列表
Parameters:
Name Type Description expectedUserIds* 增加的玩家 Id 列表 -
clearRoomExpectedUserIds()
-
清空房间占位玩家 Id 列表
-
async close() [async]
-
关闭
-
connect()
-
建立连接
-
async createRoom(optsopt) [async]
-
创建房间
Parameters:
Name Type Attributes Description optsObject <optional>
创建房间选项 Properties
Name Type Attributes Description roomNameString <optional>
房间名称,在整个游戏中唯一,默认值为 null,则由服务端分配一个唯一 Id roomOptionsObject <optional>
创建房间选项,默认值为 null Properties
Name Type Attributes Description openBoolean <optional>
房间是否打开 visibleBoolean <optional>
房间是否可见,只有「可见」的房间会出现在房间列表里 emptyRoomTtlNumber <optional>
房间为空后,延迟销毁的时间 playerTtlNumber <optional>
玩家掉线后,延迟销毁的时间 maxPlayerCountNumber <optional>
最大玩家数量 customRoomPropertiesObject <optional>
自定义房间属性 customRoomPropertyKeysForLobbyArray.<String> <optional>
在大厅中可获得的房间属性「键」数组 flagCreateRoomFlag <optional>
创建房间标记,可多选 expectedUserIdsArray.<String> <optional>
邀请好友 ID 数组,默认值为 null -
joinLobby()
-
加入大厅
-
async joinOrCreateRoom(roomName, optsopt) [async]
-
随机加入或创建房间
Parameters:
Name Type Attributes Description roomNameString 房间名称 optsObject <optional>
创建房间选项 Properties
Name Type Attributes Description roomOptionsObject <optional>
创建房间选项,默认值为 null Properties
Name Type Attributes Description openBoolean <optional>
房间是否打开 visibleBoolean <optional>
房间是否可见,只有「可见」的房间会出现在房间列表里 emptyRoomTtlNumber <optional>
房间为空后,延迟销毁的时间 playerTtlNumber <optional>
玩家掉线后,延迟销毁的时间 maxPlayerCountNumber <optional>
最大玩家数量 customRoomPropertiesObject <optional>
自定义房间属性 customRoomPropertyKeysForLobbyArray.<String> <optional>
在大厅中可获得的房间属性「键」数组 flagCreateRoomFlag <optional>
创建房间标记,可多选 expectedUserIdsArray.<String> <optional>
邀请好友 ID 数组,默认值为 null -
async joinRandomRoom(optsopt) [async]
-
随机加入房间
Parameters:
Name Type Attributes Description optsObject <optional>
随机加入房间选项 Properties
Name Type Attributes Description matchPropertiesObject <optional>
匹配属性,默认值为 null -
async joinRoom(roomName, expectedUserIdsopt) [async]
-
加入房间sss
Parameters:
Name Type Attributes Description roomNameString 房间名称 expectedUserIds* <optional>
邀请好友 ID 数组,默认值为 null -
kickPlayer(actorId, optsopt)
-
踢人
Parameters:
Name Type Attributes Description actorIdNumber 踢用户的 actorId optsObject <optional>
附带参数 Properties
Name Type Attributes Description codeNumber <optional>
编码 msgString <optional>
附带信息 -
leaveLobby()
-
离开大厅
-
async leaveRoom() [async]
-
离开房间
-
matchRandom(optsopt)
-
随机匹配,匹配成功后并不加入房间,而是返回房间 id
Parameters:
Name Type Attributes Description optsObject <optional>
随机加入房间选项 Properties
Name Type Attributes Description matchPropertiesObject <optional>
匹配属性,默认值为 null -
pauseMessageQueue() → {void}
-
暂停消息队列处理
Returns:
void -
async reconnect() [async]
-
重新连接
-
async reconnectAndRejoin() [async]
-
重新连接并自动加入房间
-
async rejoinRoom(roomName) [async]
-
重新加入房间
Parameters:
Name Type Description roomNameString 房间名称 -
removeRoomExpectedUserIds(expectedUserIds)
-
移除房间占位玩家 Id 列表
Parameters:
Name Type Description expectedUserIds* 移除的玩家 Id 列表 -
resumeMessageQueue() → {void}
-
恢复消息队列处理
Returns:
void -
sendEvent(eventId, eventData, options)
-
发送自定义消息
Parameters:
Name Type Description eventIdNumber | String 事件 ID eventDataObject 事件参数 optionsObject 发送事件选项 Properties
Name Type Description receiverGroupReceiverGroup 接收组 targetActorIdsArray.<Number> 接收者 Id。如果设置,将会覆盖 receiverGroup -
setMaster(newMasterId)
-
设置房主
Parameters:
Name Type Description newMasterIdNumber 新房主 ID -
setRoomExpectedUserIds(expectedUserIds)
-
设置房间占位玩家 Id 列表
Parameters:
Name Type Description expectedUserIds* 玩家 Id 列表 -
setRoomMaxPlayerCount(count)
-
设置房间允许的最大玩家数量
Parameters:
Name Type Description count* 数量 -
setRoomOpen(open)
-
设置房间开启 / 关闭
Parameters:
Name Type Description openBoolean 是否开启 -
setRoomVisible(visible)
-
设置房间可见 / 不可见
Parameters:
Name Type Description visibleBoolean 是否可见