Skip to content

媒服服务器 API

媒体服务器 JavaScript API,用于 Room 创建、混流与 RTMP 推流等。

创建 Room

方法: createRoom(options, callback, host)

参数:

参数名必选类型说明
optionsObject参数
callbackfunction回调
hoststring媒服地址
javascript
options = {
    name: 'test',
    /* options: { // 混流输出分辨率,如需向 rtmp 推混流需定义,默认 640×480
        views: [{
            video: {
                parameters: {
                    resolution: {
                        width: 1280,
                        height: 720
                    }
                },
            }
        }]
    } */
}

返回示例:

json
{
    "id": "roomid"
}
参数名类型说明
idstring用于加入会议的 roomid

将流添加到混流中

方法: mixStream(room, streamid, callback, host)

参数:

参数名必选类型说明
roomstringroomid
streamidstring流 id
callbackfunction回调
hoststring媒服地址

将流从混流中移除

方法: removeMixStream(room, streamid, callback, host)

参数:

参数名必选类型说明
roomstringroomid
streamidstring流 id
callbackfunction回调
hoststring媒服地址

更改混流分辨率

调用完方法之后,当 room 中没有人员时才会刷新状态。

方法: updateRoomMixStream(room, options, callback, host)

参数:

参数名必选类型说明
roomstringroomid
optionsObject参数
callbackfunction回调
hoststring媒服地址
javascript
options = {
    views: [{
        video: {
            parameters: {
                resolution: {
                    width: 1280,
                    height: 720
                }
            },
        }
    }]
}

向 RTMP 推流

方法: startStreamingOut(room, options, callback, host)

参数:

参数名必选类型说明
roomstringroomid
optionsObject参数
callbackfunction回调
hoststring媒服地址
javascript
var options = {
    protocol: 'rtmp',
    url: 'rtmp://', // 推流地址
    parameters: undefined,
    media: {
        audio: {
            from: "streamid" // 音频流 streamid
        },
        video: {
            from: "streamid", // 视频流 streamid
        }
    }
};

返回示例:

json
{
    "id": "streamoutid"
}
参数名类型说明
idstringstreamoutid

停止向 RTMP 推流

方法: stopStreamingOut(room, streamOutId, callback, host)

参数:

参数名必选类型说明
roomstringroomid
streamOutIdstringstreamoutid
callbackfunction回调
hoststring媒服地址

微议Pro SDK 开发者文档