Web JS SDK API 文档
更新时间:2020-12-03
OctopusRTC
Kind: global class
- OctopusRTC
- new OctopusRTC(appId, userId, [env], [type], [logLevel], [userName])
- instance
- .init()
- .login(roomId, role, auth, expire) ⇒
Array|errMsg - .logout()
- .createStream([source]) ⇒
mediastream - .destroyStream(mediastream)
- .startPublishingStream(streamId, mediaElement) ⇒
void - .stopPublishingStream(streamId)
- .startPlayingStream(streamId) ⇒
void - .stopPlayingStream(streamId)
- .updateMixStream(mixStreamConfig) ⇒
* - .replaceTrack(currentStream, track, [streamId])
- .changeConstraints(currentStream, type, @type, [streamId]) ⇒
Promise - .muteSwitch(streamId, mute)
- .cameraSwitch(streamId, state)
- "stream-update" ⇒
stramUpdateResult - "disconnect" ⇒
errMsg - "kick-out" ⇒
kickResult
- static
- .isSupported() ⇒
boolean
- .isSupported() ⇒
创建OctopusRTC实例
new OctopusRTC(appId, userId, [env], [type], [logLevel], [userName])
| Param | Type | Default | Description |
|---|---|---|---|
| appId | string | appId | |
| userId | string | 用户的userId | |
| [env] | string | "prod" | SDK环境选择 |
| [type] | string | "international" | 节点环境选择 |
| [logLevel] | number | 日志级别 | |
| [userName] | string | 用户名称 |
初始化SDK
octopusRTC.init()
Kind: instance method of OctopusRTC
登录房间
octopusRTC.login(roomId, role, auth, expire) ⇒ Array | errMsg
Kind: instance method of OctopusRTC
Returns: Array | errMsg - {(Promise<streamList[] | errMsg>)}
| Param | Type | Description |
|---|---|---|
| roomId | string | 房间id |
| role | 1 | 2 | 角色 |
| auth | string | 鉴权签名值 |
| expire | string | 过期时间戳 |
登出房间
octopusRTC.logout()
Kind: instance method of OctopusRTC
创建流
octopusRTC.createStream([source]) ⇒ mediastream
Kind: instance method of OctopusRTC
Returns: mediastream - {Promise
| Param | Type | Description |
|---|---|---|
| [source] | object | 视频源类型 |
| [source.camera] | object | 摄像头 |
| [source.screen] | object | 屏幕共享 |
| [source.custom] | object | 自定义流 |
| [source.camera.audio] | boolean | 是否开启音频 |
| [source.camera.video] | boolean | 是否开启视频 |
| [source.camera.audioInput] | string | 音频输入设备 |
| [source.camera.audioBitrate] | number | 音频码率 |
| [source.camera.videoInput] | string | 视频输入设备 |
| [source.camera.videoQuality] | 1 | 2 | 3 | 4 | 视频质量 |
| [source.camera.facingMode] | string | 切换摄像头(移动端) |
| [source.camera.width] | number | 宽 |
| [source.camera.height] | number | 高 |
| [source.camera.frameRate] | number | 帧率 |
| [source.camera.bitrate] | number | 码率 |
| [source.camera.AGC] | boolean | 自动增益 |
| [source.camera.ANS] | boolean | 回声消除 |
| [source.camera.AEC] | boolean | 降噪 |
| [source.screen.audio] | boolean | (共享屏幕)是否开启音频 |
| [source.screen.videoQuality] | 1 | 2 | 3 | 4 | 视频质量设置 |
| [source.screen.frameRate] | number | 帧率 |
| [source.screen.bitrate] | number | 码率 |
| source.custom.source | MediaStream | 视频流 |
| [source.custom.bitrate] | number | 码率 |
删除流
octopusRTC.destroyStream(mediastream)
Kind: instance method of OctopusRTC
| Param | Type |
|---|---|
| mediastream | MediaStream |
开始推流
octopusRTC.startPublishingStream(streamId, mediaElement) ⇒ void
Kind: instance method of OctopusRTC
Returns: void - {Promise
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
| mediaElement | MediaStream | 流 |
停止推流
octopusRTC.stopPublishingStream(streamId)
Kind: instance method of OctopusRTC
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
开始拉流
octopusRTC.startPlayingStream(streamId) ⇒ void
Kind: instance method of OctopusRTC
Returns: void - {(Promise<MediaStream | void>)}
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
停止拉流
octopusRTC.stopPlayingStream(streamId)
Kind: instance method of OctopusRTC
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
混流
octopusRTC.updateMixStream(mixStreamConfig) ⇒ *
Kind: instance method of OctopusRTC
Returns: * - {Promise
| Param | Type |
|---|---|
| mixStreamConfig | mixStreamConfig |
更改流track
octopusRTC.replaceTrack(currentStream, track, [streamId])
Kind: instance method of OctopusRTC
| Param | Type |
|---|---|
| currentStream | MediaStream |
| track | MediaStreamTrack |
| [streamId] | string |
更改约束、设备
octopusRTC.changeConstraints(currentStream, type, @type, [streamId]) ⇒ Promise
Kind: instance method of OctopusRTC
Returns: Promise - {(Promise<errMsg | void>)}
| Param | Type | Description |
|---|---|---|
| currentStream | MediaStream | |
| type | 'audio' | 'video' | |
| @type | MediaTrackConstraints | sourceCamera | constrains |
| [streamId] | string |
开启静音
octopusRTC.muteSwitch(streamId, mute)
Kind: instance method of OctopusRTC
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
| mute | boolean | 是否静音 |
切换摄像头
octopusRTC.cameraSwitch(streamId, state)
Kind: instance method of OctopusRTC
| Param | Type | Description |
|---|---|---|
| streamId | string | 流id |
| state | 'close' | 'open' | 摄像头状态 |
流变化通知 event
"stream-update" ⇒ stramUpdateResult
Kind: event emitted by OctopusRTC
Since: 2.0
websocket 断开通知 event.
"disconnect" ⇒ errMsg
Kind: event emitted by OctopusRTC
Since: 2.0
踢人通知 event.
"kick-out" ⇒ kickResult
Kind: event emitted by OctopusRTC
Since: 2.0
判断浏览器是否支持WebRTC
OctopusRTC.isSupported() ⇒ boolean
Kind: static method of OctopusRTC
自定义类型
- errMsg :
Object - sourceCamera :
Object - videoQuality :
1|2|3|4 - stramUpdateResult
- kickResult
errMsg : Object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| code | number |
| msg | string |
sourceCamera : Object
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| audio | boolean | 是否开启音频 |
| video | boolean | 是否开启视频 |
| audioInput | string | 音频输入设备 |
| videoInput | string | 视频输入设备 |
| videoQuality | number | 视频质量 |
| facingMode | string | 摄像头朝向,"user"表示前置摄像头,"environment"表示后置摄像头 |
| width | number | 宽 |
| height | number | 高 |
| frameRate | number | 帧率 |
| bitrate | number | 码率 |
| AGC | boolean | 自动增益 |
| ANS | boolean | 回声消除 |
| AEC | boolean | 降噪 |
videoQuality : 1 | 2 | 3 | 4
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| 1 | number | 分辨率: 320 * 240, 帧率: 15, 码率: 300 |
| 2 | number | 分辨率: 640 * 480, 帧率: 15, 码率: 800 |
| 3 | number | 分辨率: 1280 * 720, 帧率: 20, 码率: 1500 |
| 4 | number | 分辨率: width * height, 帧率: frameRate, 码率: bitRate(k) |
stramUpdateResult
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| code | number | 标识码 1 为增加 0为减少 |
| streamList | [ 'Array' ].<{streamId: string, userId: string, roomId: string}> | 流列表 |
kickResult
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| userId | string | 用户Id |
| roomId | string | 房间Id |
| reason | number | 错误码 |