媒服服务器 API
媒体服务器 JavaScript API,用于 Room 创建、混流与 RTMP 推流等。
创建 Room
方法: createRoom(options, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| options | 是 | Object | 参数 |
| callback | 是 | function | 回调 |
| host | 否 | string | 媒服地址 |
javascript
options = {
name: 'test',
/* options: { // 混流输出分辨率,如需向 rtmp 推混流需定义,默认 640×480
views: [{
video: {
parameters: {
resolution: {
width: 1280,
height: 720
}
},
}
}]
} */
}返回示例:
json
{
"id": "roomid"
}| 参数名 | 类型 | 说明 |
|---|---|---|
| id | string | 用于加入会议的 roomid |
将流添加到混流中
方法: mixStream(room, streamid, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| room | 是 | string | roomid |
| streamid | 是 | string | 流 id |
| callback | 否 | function | 回调 |
| host | 是 | string | 媒服地址 |
将流从混流中移除
方法: removeMixStream(room, streamid, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| room | 是 | string | roomid |
| streamid | 是 | string | 流 id |
| callback | 否 | function | 回调 |
| host | 是 | string | 媒服地址 |
更改混流分辨率
调用完方法之后,当 room 中没有人员时才会刷新状态。
方法: updateRoomMixStream(room, options, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| room | 是 | string | roomid |
| options | 是 | Object | 参数 |
| callback | 是 | function | 回调 |
| host | 否 | string | 媒服地址 |
javascript
options = {
views: [{
video: {
parameters: {
resolution: {
width: 1280,
height: 720
}
},
}
}]
}向 RTMP 推流
方法: startStreamingOut(room, options, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| room | 是 | string | roomid |
| options | 是 | Object | 参数 |
| callback | 是 | function | 回调 |
| host | 否 | string | 媒服地址 |
javascript
var options = {
protocol: 'rtmp',
url: 'rtmp://', // 推流地址
parameters: undefined,
media: {
audio: {
from: "streamid" // 音频流 streamid
},
video: {
from: "streamid", // 视频流 streamid
}
}
};返回示例:
json
{
"id": "streamoutid"
}| 参数名 | 类型 | 说明 |
|---|---|---|
| id | string | streamoutid |
停止向 RTMP 推流
方法: stopStreamingOut(room, streamOutId, callback, host)
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| room | 是 | string | roomid |
| streamOutId | 是 | string | streamoutid |
| callback | 是 | function | 回调 |
| host | 否 | string | 媒服地址 |
