互动直播
9.1 获取StarRtc.StarRoomSDK实例,实现回调函数
9.1.1 vdn(观众)模式
function videoLiveVdnCallBack(data, status, oper) { var thisRoom = data.obj; switch (status){ case "connect success": break; case "connect failed": case "connect closed": break; case "onWebrtcMessage": switch(data.type) { case "streamCreated": break; case "vdnApplyDownload": break; case "addUploader": break; case "removeUploader": break; case "streamData": break; case "streamConfig": break; case "serverErr": break; } break; case "onChatRoomMessage": { switch(data.type) { case "recvChatPrivateMsg": if(data.msg.msgType == "applyAgree" || data.msg.msgType == "inviteStart") { } else if(data.msg.msgType == "linkStop") { } else if(data.msg.msgType == "applyDisagree") { } else if(data.msg.msgType == "invite") { } else { } break; case "recvChatMsg": break; case "chatroomUserKicked": break; case "serverErr": break; } } break; } }
StarRtc.StarSDK.getVideoLiveRoomSDK = function (_type, _oper, _userCallback, _userData)
例: var starSDK = new StarRtc.StarSDK(); currRoom = starSDK.getVideoLiveRoomSDK("vdn", "open", videoLiveVdnCallBack, {"roomInfo":{"id":"", "name":"", "creator":""}});
|
9.1.2 src(主播)模式
function videoLiveSrcCallBack(data, status, oper) { var thisRoom = data.obj; switch (status){ case "connect success": break; case "connect failed": case "connect closed": break; case "onWebrtcMessage": { switch(data.type) { case "streamCreated": break; case "srcApplyUpload": break; case "addUploader": break; case "removeUploader": break; case "delChannel": break; case "createChannel": break; case "streamData": break; case "streamConfig": break; case "serverErr": break; } } break; case "onChatRoomMessage": { switch(data.type) { case "recvChatPrivateMsg": if(data.msg.msgType == "linkStop") { } else if(data.msg.msgType == "apply") { } else if(data.msg.msgType == "inviteAgree") { } else if(data.msg.msgType == "inviteDisagree") { } else { } break; case "recvChatMsg": break; case "chatroomUserKicked": break; case "deleteChatRoom": break; case "serverErr": break; } } break; } }
例: var starSDK = new StarRtc.StarSDK(); currRoom = starSDK.getVideoLiveRoomSDK("src", "open", videoLiveSrcCallBack, {"roomInfo":{"ID":"", "Name":"", "Creator":""}});
|
9.2 API 说明
StarRtc.StarRoomSDK.sigConnect = function ()
/** * 断连房间 * @param flag 是否主动断开连接的标志为,用于判断重连 */ StarRtc.StarRoomSDK.sigDisconnect = function (_flag)
/** * 创建房间 */ StarRtc.StarRoomSDK.createNew = function ()
/** * 删除房间 */ StarRtc.StarRoomSDK.deleteCurrRoom = function ()
/** * 创建本地视频流 * @param streamOption 流配置(分辨率等),如{ "video": true, "audio": { deviceId: { ideal: ["default"] } } }, 或{ "video": { width: { ideal: 640 }, height: { ideal: 480 }, frameRate: { ideal: 25 }, facingMode: { ideal: ["user"] } }, "audio": { deviceId: { ideal: ["default"] } } */ StarRtc.StarRoomSDK.createStream = function (streamOption)
/** * 创建分享屏幕视频流 */ StarRtc.StarRoomSDK.createScreenCaptureStream = function ()
/** * 设置流可见性(会同时影响自己本地流和对端流) * @param config 流可见性配置{"video":true, "audio":true} */ StarRtc.StarRoomSDK.publishStream = function (config)
/** * 加入房间 */ StarRtc.StarRoomSDK.joinRoom = function ()
/** * 离开房间 * @param _flag 是否主动离开(可选) */ StarRtc.StarRoomSDK.leaveRoom = function (_flag)
/** * 切换大小图 * @param streamConfig 切换大小图的配置,数组,1为小图,2为大图[1,2,1,2...] */ StarRtc.StarRoomSDK.streamConfigApply = function (streamConfig)
/** * 发送聊天室消息 * @param msg 消息 */ StarRtc.StarRoomSDK.sendChatMsg = function (msg)
/** * 发送聊天室私聊消息 * @param toUserId 发送对象 * @param msg 消息 */ StarRtc.StarRoomSDK.sendChatPrivateMsg = function (userId, msg)
/** * 发送申请上麦消息 */ StarRtc.StarRoomSDK.sendApplyMsg = function ()
/** * 发送同意申请上麦消息 * @param userId 待发送的用户id */ StarRtc.StarRoomSDK.sendApplyAgreeMsg = function (userId)
/** * 发送拒绝申请上麦消息 * @param userId 待发送的用户id */ StarRtc.StarRoomSDK.sendApplyDisagreeMsg = function (userId)
/** * 发送邀请上麦消息 * @param userId 待发送的用户id */ StarRtc.StarRoomSDK.sendInviteLinkMsg = function (userId)
/** * 发送同意邀请上麦消息 */ StarRtc.StarRoomSDK.sendInviteLinkAgreeMsg = function ()
/** * 发送拒绝邀请上麦消息 */ StarRtc.StarRoomSDK.sendInviteLinkDisagreeMsg = function ()
/** * 发送开始邀请上麦消息 */ StarRtc.StarRoomSDK.sendInviteLinkStartMsg = function ()
/** * 发送断开上麦消息 * @param userId 待发送的用户id */ StarRtc.StarRoomSDK.sendLinkStopMsg = function (userId)
/** * 聊天室踢人 * @param kickOutUserId 踢出的用户Id */ StarRtc.StarRoomSDK.kickOutUser = function (kickOutUserId)
/** * 聊天室禁言 * @param banUserId 禁言的用户Id * @param banTime 禁言的时间长度 */ StarRtc.StarRoomSDK.banToSendMsg = function (banUserId, banTime)
/** * 获取聊天室在线用户数 */ StarRtc.StarRoomSDK.getRoomOnlineNum = function ()
/** * 发送实时数据 * @param data 实时数据 */ StarRtc.StarRoomSDK.sendStreamData = function (data)
/** * 获取是主动断开还是被动断开 */ StarRtc.StarRoomSDK.activeDisconnect = function ()
|