# Room

#### new Room()

Description:

  - 房间Room构造函数。

##### Example

    var room = new Room(roomId);

### Members

#### cleanupBoardByReJoinConnected

Description:

  - 重新加会成功后，应用层需要清理白板的标识，true代表要清理。 原因是服务器版本3.1.8开始，当客户端重新加会成功后，会重新下发所有之前白板相关信息包括批注，所以应用层需要先删除掉原来的白板相关界面内容，否则会重复渲染，可能会存在错位。

重新加会成功后，应用层需要清理白板的标识，true代表要清理。 原因是服务器版本3.1.8开始，当客户端重新加会成功后，会重新下发所有之前白板相关信息包括批注，所以应用层需要先删除掉原来的白板相关界面内容，否则会重复渲染，可能会存在错位。

### Methods

#### addCallback(type, callback)

Description:

  - 房间级别的回调

##### Example

    room.addCallback(RoomCallback.connection_status, onConnectionStatus);
    room.addCallback(RoomCallback.connection_indicator,onConnectionIndicator);
    room.addCallback(RoomCallback.room_status_notify, onRoomStatusNotify);

    room.addCallback(RoomCallback.user_join_notify, onUserJoinNotify);
    room.addCallback(RoomCallback.user_leave_notify, onUserLeaveNotify);
    room.addCallback(RoomCallback.leave_indication, onLeaveIndication);
    room.addCallback(RoomCallback.close_room_result, onCloseRoomResult);
    room.addCallback(RoomCallback.close_room_notify, onCloseRoomNotify);
    room.addCallback(RoomCallback.app_data_notify, onAppdataNotify);
    room.addCallback(RoomCallback.user_data_notify, onUserDataNotify);
    room.addCallback(RoomCallback.user_name_notify, onUserNameNotify);

    room.addCallback(RoomCallback.public_message, onPublicMessage);
    room.addCallback(RoomCallback.private_message, onPrivateMessage);
    room.addCallback(RoomCallback.public_data, onPublicData);
    room.addCallback(RoomCallback.private_data, onPrivateData);

    room.addCallback(RoomCallback.screen_sharing_ended, onScreenSharingEnded);

    room.addCallback(RoomCallback.outgoing_invite_status_notify, onOutgoingInviteStatusNotify);
    room.addCallback(RoomCallback.room_control_change_notify, onRoomControlChangeNotify);

    与服务器连接状态回调
    param:status - 连接状态

    function onConnectionStatus(status) {
       if (status == ConnectionStatus.connecting) {
    	       //TODO 与服务器重连中
       } else if (status == ConnectionStatus.connected) {
    	       //TODO 与服务器重连成功
       } else if (status == ConnectionStatus.connectFailed) {
    	      //TODO 与服务器重连失败,需要重新登陆
      }
     }

    与服务器连接指示器回调
    param: connectionIndicator - 连接指示器

    function onConnectionIndicator(connectionIndicator){
               if（connectionIndicator）{
    	              var roomConnection = connectionIndicator.getRoomConnection();

                   //房间级别
                   roomConnection.localAddress   本地地址
                   roomConnection.localPort      本地端口
                   roomConnection.localProtocol  本地协议
                   roomConnection.remoteAddress  远端地址
                   roomConnection.remotePort     远端端口
                   roomConnection.remoteProtocol  远端协议

                   roomConnection.downloadBitrate  下载流量
                   roomConnection.uploadBitrate    上传流量

                   roomConnection.downloadPacket  下载数据包
                   roomConnection.uploadPacket    上传数据包
                   roomConnection.downloadPacketLost  下载数据包丢包数
                   roomConnection.uploadPacketLost   上传数据包丢包数

                   roomConnection.downloadPacketLostRate  下载数据包丢包率
                   roomConnection.uploadPacketLostRate   上传数据包丢包率

                   roomConnection.currentRoundTripTime   当前的往返时间(RTT)
                   roomConnection.totalRoundTripTime     累计的往返时间(RTT)

                   //某路音频相关
                   var audioConnection = connectionIndicator.getAudioConnection(userId);
                   audioConnection.downloadBitrate   音频下载流量
                   audioConnection.uploadBitrate     音频上传流量

                   audioConnection.downloadPacket   音频下载数据包
                   audioConnection.uploadPacket     音频上传数据包

                   audioConnection.packetsLost     音频数据包丢包数
                   audioConnection.packetLostRate  音频数据包丢包率

                   audioConnection.ssrc
                   audioConnection.trackId
                   audioConnection.payloadType
                   audioConnection.mimeType
                   audioConnection.clockRate

                   //某路视频相关
                   videoConnection = connectionIndicator.getVideoConnection(userId, cameraId);
                   videoConnection.downloadBitrate   视频下载流量
                   videoConnection.uploadBitrate     视频上传流量

                   videoConnection.downloadPacket    视频下载数据包
                   videoConnection.uploadPacket     视频传数据包

                   videoConnection.packetsLost     视频数据包丢包数
                   videoConnection.packetLostRate  视频数据包丢包率

                   videoConnection.resolution     分辨率
                   videoConnection.frameRate      帧率

                   videoConnection.qpSum           媒体数据包的总量化值(qpSum
                   videoConnection.framesEncoded   已编码帧的数量
                   videoConnection.framesDecoded   已解码帧的数量
                   videoConnection.perFrameQP      每个视频帧的平均量化值(perFrameQP)

                   videoConnection.ssrc
                   videoConnection.trackId
                   videoConnection.payloadType
                   videoConnection.mimeType
                   videoConnection.clockRate

    *              //某路桌面共享相关
                   screenConnection = connectionIndicator.getScreenConnection(userId);
                   screenConnection.downloadBitrate   桌面共享下载流量
                   screenConnection.uploadBitrate     桌面共享上传流量

                   screenConnection.downloadPacket    桌面共享下载数据包
                   screenConnection.uploadPacket     桌面共享传数据包

                   screenConnection.packetsLost      桌面共享数据包丢包数
                   screenConnection.packetLostRate   桌面共享数据包丢包率

                   screenConnection.resolution        分辨率
                   screenConnection.frameRate         帧率
                   screenConnection.ssrc
                   screenConnection.trackId
                   screenConnection.payloadType
                   screenConnection.mimeType
                   screenConnection.clockRate
              }
    }

    参会者加会回调
    param :users － 参会者数组

    function onUserJoinNotify(users) {

    }

    参会者退会回调
    param:opt - 退会类型
    param:reason  - 退会原因
    param:user - 退会用户

    function onUserLeaveNotify(opt,reason,user) {

    }

    被踢出会议室
    param:reason - 被踢原因
    param:userId - 踢人的操作者

    function onLeaveIndication(reason,userId) {

    }

    房间应用扩展字段回调
    param {Object} key － key值
    param {Object} value － value值
    function onAppdataNotify(key, value) {

    }

    用户扩展内容更新回调
    param:userData - 用户扩展内容
    param:userId - 用户id

    function onUserDataNotify(userData, userId ) {

    }

    用户修改名字回调
    param {String} userName - 用户新名字
    param {String} userId - 用户id

    function onUserNameNotify(userName, userId){

    }

    公聊回调
    param : Message

    function onPublicMessage(Message) {

    }

    私聊回调
    param: Message

    function onPrivateMessage(Message) {

    }

    公有透明通道回调
    param:dataArrayBuffer － DataArrayBuffer对象
    param:userId － user id

    function onPublicData(dataArrayBuffer, userId) {

    }

    私有透明通道回调
    param:dataArrayBuffer － DataArrayBuffer对象
    param:userId － user id

    function onPrivateData(dataArrayBuffer, userId) {

    }

    桌面共享关闭的回调
    function onScreenSharingEnded(){

    }

    外部设备邀请状态回调
    param:type － OutgoingInviteType枚举值
    param:roomId － 房间ID
    param:addr － 设备地址
    param:status － 邀请状态码
    param:msg － 邀请返回状态

    function onOutgoingInviteStatusNotify(type,roomId,addr,status,msg){

    }

    房间参数设置回调
    param:roomControl － 参数对象
    function onRoomControlChangeNotify(roomControl){

    }

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | RoomCallback | 回调枚举标识
`callback` | Object | 回调方法名,可以自定义，建议保持默认值

#### closeRoom(userId)

Description:

  - 关闭房间

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | String | 关闭房间的操作用户ID

#### continuousReJoin()

Description:

  - 多次后重新加会超时后，开启持续永久重新加会

#### getAppData(key) → {String}

Description:

  - 获得房间应用扩展字段信息

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | key值

##### Returns:

value- value值

Type
  String

#### getBoardNumber(status) → {int}

Description:

  - 获取房间内当前白板数

##### Example

    room.getBoardNumber(boardStatusEnum.open);

##### Parameters:

Name | Type | Description
--- | --- | ---
`status` | boardStatusEnum | 白板状态值, 可以不填，不填时包括boardStatusEnum.open和boardStatusEnum.close的

##### Returns:

boardNumber -白板数

Type
  int

#### getMaxAttendee() → {Int}

Description:

  - 获取允许的最大参加会议人数

##### Returns:

maxAttendee - 最大参加会议人数

Type
  Int

#### getMaxAudio() → {Int}

Description:

  - 获取允许的最大音频路数

##### Returns:

maxAudio - 最大音频路数

Type
  Int

#### getMaxVideo() → {Int}

Description:

  - 获取允许的最大视频路数

##### Returns:

maxVideo - 最大视频路数

Type
  Int

#### getOwnerId() → {String}

Description:

  - 获取会议建创者Id

##### Returns:

ownerId - 会议建创者Id

Type
  String

#### getParticipants() → {Object}

Description:

  - 返回参会者数组

##### Returns:

participants -参会者数组

Type
  Object

#### getParticipantsNumber() → {int}

Description:

  - 返回参会者人数

##### Returns:

participantsNumber -参会者人数

Type
  int

#### getPublishedCamera()

Description:

  - 获取房间中所有已发布的摄像头视频对象集

#### getPublishedCameraCount()

Description:

  - 获取房间中所有已发布的摄像头视频数量

#### getPublishedScreen()

Description:

  - 获取房间中所有已发布的共享屏幕窗口视频对象集

#### getPublishedScreenCount()

Description:

  - 获取房间中所有已发发布的共享屏幕窗口视频数量

#### getRoomControl() → {Object}

Description:

  - 获取房间控制参数

##### Returns:

- roomControl 房间控制参数

Type
  Object

#### getRoomId() → {String}

Description:

  - 获取房间号

##### Returns:

roomId - 房间号

Type
  String

#### getRoomTopic() → {String}

Description:

  - 获取会议主题

##### Returns:

topic - 会议主题

Type
  String

#### getRoomType(roomTypEnum) → {Boolean}

Description:

  - 会议类型判断

##### Parameters:

Name | Type | Description
--- | --- | ---
`roomTypEnum` | Enum | 传入会议类型枚举

##### Returns:

true: 是枚举对应的会议类型,false:非枚举对应的会议类型

Type
  Boolean

#### getSelfUser() → {user}

Description:

  - 返回自己对象

##### Returns:

selfUser - 自己对象

Type
  user

#### getSelfUserId() → {String}

Description:

  - 返回自己对象的Id

##### Returns:

userId - 自己对象的Id

Type
  String

#### getUsableAudio() → {Int}

Description:

  - 获取音频路数的剩余可用数。

    逻辑：允许的最大音频路数 － 已发布的音频路数

    注：主要用于界面显示用，具体打开的限制提示时，会采用服务器端的返回号来处理

##### Returns:

usableAudio - 剩余可用音频路数

Type
  Int

#### getUsableVideo() → {Int}

Description:

  - 获取视频路数的剩余可用数。

    逻辑：允许的最大视频路数 － 已发布的视频路数

    注：主要用于界面显示用，具体打开的限制提示时，会采用服务器端的返回号来处理

##### Returns:

usableVideo - 剩余可用视频路数

Type
  Int

#### getUser(userId) → {Object}

Description:

  - 通过用户ID获取用户对象

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | String | 用户的Id

##### Returns:

user - 用户对象

Type
  Object

#### getUserByUserIdAndNodeId(userId) → {Object}

Description:

  - 通过用户ID获取用户对象

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | String | 用户的Id

##### Returns:

user - 用户对象

Type
  Object

#### hasUser(userId)

Description:

  - 通过用户ID,判断用户对象是否存在。

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | String | 用户的Id

#### isMcu() → {Boolean}

Description:

  - 判断当前会议模式是否为MCU模式

##### Returns:

isMcuRoomＭode - 是否为MCU模式. true: mcu模式;false:P2P模式

Type
  Boolean

#### ismuteSpeaker() → {Boolean}

Description:

  - 获取屏蔽会议声音的当前状态

##### Returns:

- 屏蔽会议声音的当前状态

Type
  Boolean

#### (async) join(userId, userName, userData, password)

Description:

  - 加会

##### Example

    room.join('user01','ds','','').then(function(){}).otherwise(function(error){});

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | String | 用户的Id
`userName` | String | 用户名
`userData` | String | 用户扩展字段
`password` | String | 会议密码

#### (async) joinEfficient(serverURI, accessToken, userId, userName, userData, password)

Description:

  - 高效加会,与room.join()接口的区别是不再需要另外调用avdEngine.init()

##### Example

    room.joinEfficient('avd.nice2meet.cn:9610','ZDgyNGU1MGU0ZGY2MTJlZWY3NjkwMjQ5NDY0YWE3MDkxZGJjNmRiZg==','user01','ds','','').then(function(){}).otherwise(function(error){});

##### Parameters:

Name | Type | Description
--- | --- | ---
`serverURI` | String | MCU服务器地址
`accessToken` | String | 访问令牌
`userId` | String | 用户的Id
`userName` | String | 用户名
`userData` | String | 用户扩展字段
`password` | String | 会议密码

#### (async) joinWithOEM(userId, userName, userData, password)

Description:

  - OEM加会

##### Parameters:

Name | Type | Description
--- | --- | ---
`userId` | Object | 用户的Id
`userName` | Object | 用户名
`userData` | Object | 用户扩展字段
`password` | String | 会议密码

#### kickoffUser(reason, userId)

Description:

  - 踢人

##### Parameters:

Name | Type | Description
--- | --- | ---
`reason` | int | 踢人原因，填写808，其它值也都会重置成808
`userId` | String | 被踢用户id

#### (async) leave(reason, kickoffOpt)

Description:

  - 退会

##### Example

    room.leave(1).then(function(){}).otherwise(function(error){});

##### Parameters:

Name | Type | Description
--- | --- | ---
`reason` | int | 退会原因，可以填写 1
`kickoffOpt` | boolean | 退会类型： true:被踢退会，false:主动退会，可以不填

#### muteSpeaker()

Description:

  - 屏蔽会议声音

#### (async) sendPrivateData(dataBinary, userId)

Description:

  - 发送私有透明通道

##### Example

    var dataArrayBuffer = typeConversionUtil.String2ArrayBuffer("This is an important piece of news.");
    room.sendPrivateData(dataArrayBuffer，'15').then(dataSendSuccess).otherwise(dataSendError);
    function dataSendSuccess(dataMsg) {
    }

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataBinary` | Object | － ArrayBinary类型的内容 注： ArrayBinary : 二进制数据的原始缓冲区，该缓冲区用于存储各种类型化数组的数据
`userId` | String | 内容接受用户ID

#### (async) sendPrivateDataToUser(dataBinary, userId)

Description:

  - 发送私有二进制数据。与room.sendPrivateData()的区别，本方法只需要知道对方的userId,内部实现时不用知道对方的nodeId,如一些特殊useAgent的用户，是取不到nodeId的。

##### Example

    var dataArrayBuffer = typeConversionUtil.String2ArrayBuffer("This is an important piece of news.");
    room.sendPrivateDataToUser(dataArrayBuffer，'15').then(dataSendSuccess).otherwise(dataSendError);
    function dataSendSuccess(dataMsg) {
    }

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataBinary` | Object | ArrayBinary类型的内容 注： ArrayBinary : 二进制数据的原始缓冲区，该缓冲区用于存储各种类型化数组的数据
`userId` | String | 内容接受用户ID

#### (async) sendPrivateMessage(message, userId)

Description:

  - 发送私聊消息

##### Example

    room.sendPrivateMessage("hello",'user03').then(function(){}).otherwise(function(error){});

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | String | 消息内容
`userId` | String | 消息接受用户ID

#### sendPublicData(dataBinary)

Description:

  - 发送公有透明通道 @

##### Example

    var dataArrayBuffer = typeConversionUtil.String2ArrayBuffer("This is an important piece of news.");
    room.sendPublicData(dataArrayBuffer).then(dataSendSuccess).otherwise(dataSendError);
    function dataSendSuccess(dataMsg) {
    }

##### Parameters:

Name | Type | Description
--- | --- | ---
`dataBinary` | Object | － ArrayBinary类型的内容 注： ArrayBinary : 二进制数据的原始缓冲区，该缓冲区用于存储各种类型化数组的数据

#### (async) sendPublicMessage(message)

Description:

  - 发送公聊消息

##### Example

    room.sendPublicMessage("hello").then(function(){}).otherwise(function(error){});

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | String | 消息内容

#### (async) setCameraResolutionOrFrameRate(cameraId, resolution, frameRate, resolutionSetType-, aspectRatio-)

Description:

  - 设置摄像头分辨率或帧率

##### Parameters:

Name | Type | Description
--- | --- | ---
`cameraId` | String | 摄摄像头ID
`resolution` | String | 分辨率枚举值,如
`frameRate` | int | 帧率
`resolutionSetType-` | Object | 分辨率设置类型,可不填写，null时默认为ResolutionSetType.exact
`aspectRatio-` | Number | 分辨率宽高比(1.7777777778, 1.3333333333),可不填写(null,0时浏览器自动处理)，16:9或4:3时会开启强制

#### (async) setCameraResolutionWHOrFrameRate(cameraId, resolutionWidth, resolutionHeight, frameRate, resolutionSetType-, aspectRatio-)

Description:

  - 设置摄像头分辨率或帧率

##### Parameters:

Name | Type | Description
--- | --- | ---
`cameraId` | String | 摄摄像头ID
`resolutionWidth` | int | 分辨率宽
`resolutionHeight` | int | 分辨率高
`frameRate` | int | 帧率
`resolutionSetType-` | Object | 分辨率设置类型,可不填写，null时默认为ResolutionSetType.exact
`aspectRatio-` | Number | 分辨率宽高比(1.7777777778, 1.3333333333)，可不填写(null,0时浏览器自动处理)，16:9或4:3时会开启强制

#### setReconnectMaxTimes(count)

Description:

  - 设置信令重连最大次数,默认3次

##### Example

    room.setReconnectMaxTimes(5);

##### Parameters:

Name | Type | Description
--- | --- | ---
`count` | Int | 重连最大次数

#### setReconnectTimeout(timeout)

Description:

  - 设置信令重连最时时长,单元毫秒，默认15000毫秒

##### Example

    room.setReconnectTimeout(20000);

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeout` | Int | 重连最时时长

#### setRejoinInterval(rejoinInterval)

Description:

  - 设置二次重新加会之间间隔的时长

##### Parameters:

Name | Type | Description
--- | --- | ---
`rejoinInterval` | Number | 单位ms，默认3000（3秒）

#### setRejoinTimeout(rejoinTimeout)

Description:

  - 设置重新加会的超时时间

##### Parameters:

Name | Type | Description
--- | --- | ---
`rejoinTimeout` | Number | 单位ms，默认60000（60秒），请传入大于60000的值

#### setRoomControl(attributes)

Description:

  - 设置房间控制参数(参数为JSON格式字符串)

##### Example

    var attributes = '{
    	     'record': 0,
    		 'mix_record' : 0,
    		 'avc_model': 0,
    		 'resolution': '640*480',
    		 'liver'': 0,
    		 'mixer_live: 0
     }";
     room.setRoomControl(attributes);

##### Parameters:

Name | Type | Description
--- | --- | ---
`attributes` | String | 房间控制参数（JSON格式字符串)

#### (async) setSpeakerDevice(deviceId, audioElements)

Description:

  - 设置音频播放设备扬声器

##### Parameters:

Name | Type | Description
--- | --- | ---
`deviceId` | Object | 扬声器设备ID
`audioElements` | Object | audio控件对象集，可以不填，不填时自动获取页面上的所有audio控件对象

#### (async) setSpeakerVolume(volume, audioElements)

Description:

  - 设置扬声器音量大小

##### Parameters:

Name | Type | Description
--- | --- | ---
`volume` | int | 音量值，范围0-1，如0.5表示设置音量为50%。 注：该值只是应用层的设置值与物理设备的具体音量值无关
`audioElements` | Object | audio控件对象集，可以不填，不填时自动获取页面上的所有audio控件对象

#### setUserAgent(userAgent)

Description:

  - 设置当前登陆用户的userAgent属性，默认为USER_AGENT_AVD_DEFAULT

##### Example

    room.setUserAgent(USER_AGENT_AVD_MEDIA_MIXER_ADMIN);

##### Parameters:

Name | Type | Description
--- | --- | ---
`userAgent` | String |

#### unmuteSpeaker()

Description:

  - 取消屏蔽会议声音

#### updateAppData(key, value)

Description:

  - 更新房间应用扩展字段

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | － key值
`value` | String | － value值

#### updateRoomStatus(roomStatus)

Description:

  - 修改会议房间状态

##### Parameters:

Name | Type | Description
--- | --- | ---
`roomStatus` | Enum | 房间状态枚举