## Constructor

#### new Play()

### Members

#### readonly lobbyRoomList

  获取房间列表

#### readonly player

  获取当前玩家

#### readonly room

  获取当前所在房间

#### userId :string

  玩家 ID

### Methods

#### connect(optsopt)

  建立连接

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---

  `opts`

  Object

  <optional>

  连接选项

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `gameVersion` | string | <optional> | 游戏版本号，不同的游戏版本号将路由到不同的服务端，默认值为 0.0.1

#### createRoom(optsopt)

  创建房间

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---

  `opts`

  Object

  <optional>

  创建房间选项

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `roomName` | string | <optional> | 房间名称，在整个游戏中唯一，默认值为 null，则由服务端分配一个唯一 Id

  `roomOptions`

  Object

  <optional>

  创建房间选项，默认值为 null

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `opened` | Boolean | <optional> | 房间是否打开
  `visible` | Boolean | <optional> | 房间是否可见，只有「可见」的房间会出现在房间列表里
  `emptyRoomTtl` | Number | <optional> | 房间为空后，延迟销毁的时间
  `playerTtl` | Number | <optional> | 玩家掉线后，延迟销毁的时间
  `maxPlayerCount` | Number | <optional> | 最大玩家数量
  `customRoomProperties` | Object | <optional> | 自定义房间属性
  `customRoomPropertyKeysForLobby` | Array.<string> | <optional> | 在大厅中可获得的房间属性「键」数组
  `flag` | CreateRoomFlag | <optional> | 创建房间标记，可多选

  `expectedUserIds` | Array.<string> | <optional> | 邀请好友 ID 数组，默认值为 null

#### disconnect()

  断开连接

#### init(opts)

  初始化客户端

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `opts`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `appId` | string | APP ID
  `appKey` | string | APP KEY
  `region` | number | 节点地区

#### joinLobby()

  加入大厅，只有在 autoJoinLobby = false 时才需要调用

#### joinOrCreateRoom(roomName, optsopt)

  随机加入或创建房间

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `roomName` | string |  | 房间名称

  `opts`

  Object

  <optional>

  创建房间选项

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---

  `roomOptions`

  Object

  <optional>

  创建房间选项，默认值为 null

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `opened` | Boolean | <optional> | 房间是否打开
  `visible` | Boolean | <optional> | 房间是否可见，只有「可见」的房间会出现在房间列表里
  `emptyRoomTtl` | Number | <optional> | 房间为空后，延迟销毁的时间
  `playerTtl` | Number | <optional> | 玩家掉线后，延迟销毁的时间
  `maxPlayerCount` | Number | <optional> | 最大玩家数量
  `customRoomProperties` | Object | <optional> | 自定义房间属性
  `customRoomPropertyKeysForLobby` | Array.<string> | <optional> | 在大厅中可获得的房间属性「键」数组
  `flag` | CreateRoomFlag | <optional> | 创建房间标记，可多选

  `expectedUserIds` | Array.<string> | <optional> | 邀请好友 ID 数组，默认值为 null

#### joinRandomRoom(optsopt)

  随机加入房间

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---

  `opts`

  Object

  <optional>

  随机加入房间选项

  ###### Properties

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `matchProperties` | Object | <optional> | 匹配属性，默认值为 null
  `expectedUserIds` | Array.<string> | <optional> | 邀请好友 ID 数组，默认值为 null

#### joinRoom(roomName, expectedUserIdsopt)

  加入房间

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `roomName` | string |  | 房间名称
  `expectedUserIds` | * | <optional> | 邀请好友 ID 数组，默认值为 null

#### leaveLobby()

  离开大厅

#### leaveRoom()

  离开房间

#### reconnect()

  重新连接

#### reconnectAndRejoin()

  重新连接并自动加入房间

#### rejoinRoom(roomName)

  重新加入房间

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `roomName` | string | 房间名称

#### sendEvent(eventId, eventData, options)

  发送自定义消息

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `eventId` | number | string | 事件 ID
  `eventData` | Object | 事件参数

  `options`

  Object

  发送事件选项

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `receiverGroup` | ReceiverGroup | 接收组
  `targetActorIds` | Array.<number> | 接收者 Id。如果设置，将会覆盖 receiverGroup

#### setMaster(newMasterId)

  设置房主

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `newMasterId` | number | 新房主 ID

#### setRoomOpened(opened)

  设置房间开启 / 关闭

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `opened` | Boolean | 是否开启

#### setRoomVisible(visible)

  设置房间可见 / 不可见

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `visible` | Boolean | 是否可见

### Events

#### CONNECT_FAILED

  连接失败

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `code` | Number |
  `detail` | String |

#### CONNECTED

  连接成功

#### CUSTOM_EVENT

  自定义事件

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `eventId` | Number | String |
  `eventData` | Object |
  `senderId` | Number |

#### DISCONNECTED

  断开连接

#### ERROR

  错误事件

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `code` | Number |
  `detail` | String |

#### LOBBY_JOINED

  加入到大厅

#### LOBBY_LEFT

  离开大厅

#### LOBBY_ROOM_LIST_UPDATED

  大厅房间列表变化

#### MASTER_SWITCHED

  主机变更

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `newMaster` | Player |

#### PLAYER_ACTIVITY_CHANGED

  玩家活跃属性变化

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `player` | Player |

#### PLAYER_CUSTOM_PROPERTIES_CHANGED

  玩家自定义属性变化

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `player` | Player |
  `changedProps` | Object |

#### PLAYER_ROOM_JOINED

  有新玩家加入房间

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `newPlayer` | Player |

#### PLAYER_ROOM_LEFT

  有玩家离开房间

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `leftPlayer` | Player |

#### ROOM_CREATE_FAILED

  创建房间失败

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `code` | Number |
  `detail` | String |

#### ROOM_CREATED

  创建房间成功

#### ROOM_CUSTOM_PROPERTIES_CHANGED

  房间自定义属性变化

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `changedProps` | Object |

#### ROOM_JOIN_FAILED

  加入房间失败

#### ROOM_JOINED

  加入房间成功

#### ROOM_LEFT

  离开房间

#### ROOM_OPEN_CHANGED

  房间「开启 / 关闭」

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `opened` | Boolean |

#### ROOM_VISIBLE_CHANGED

  房间「可见 / 不可见」

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `payload`

  Object

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `visible` | Boolean |