9.1 Get the StarRtc.StarRoomSDK instance and implement the callback function
9.1.1 vdn(Audience)mode
functionvideoLiveVdnCallBack(data, status, oper) { var thisRoom = data.obj; switch (status){ case"connect success": //connect success break; case"connect failed": case"connect closed": //connect failed break; case"onWebrtcMessage": //Video interface message switch(data.type) { case"streamCreated": //Create the local video stream,and the data.status == "success" means success break; case"vdnApplyDownload": //the Apply for vdn,and the data.status == "success" means success break; case"addUploader": //Someone has joined the live room break; case"removeUploader": //Someone has left the live room break; case"streamData": //Receive real-time data break; case"streamConfig": //Set the callback of the video size break; case"serverErr": //server error break; } break; case"onChatRoomMessage": //Receive chat room message { switch(data.type) { case"recvChatPrivateMsg": //Received private chat messages if(data.msg.msgType == "applyAgree" || data.msg.msgType == "inviteStart") { //Receive the message that you are agreed to be an broadcaster or invited to start to be an broadcaster } elseif(data.msg.msgType == "linkStop") { // Receive the message that yhou are stopped to link live } elseif(data.msg.msgType == "applyDisagree") { //Receive the message that you are refused to be an broadcaster } elseif(data.msg.msgType == "invite") { ///Receive the message that you are invited to be an broadcaster } else { //Receive a normal message } break; case"recvChatMsg": //Received a message break; case"chatroomUserKicked": ///Receive the message that you are kicked break; case"serverErr": //Server error break; } } break; } } /** * Create a live room * @param _type Type: vdn, viewer; src, uploader * @param _oper Operation type: new: create, open: join * @param _userCallback callback * @param _userData Store information about the live room(id,name,creator),and the structure is{"roomInfo":{"id":"", "name":"", "creator":""}} StarRtc.StarSDK.getVideoLiveRoomSDK = function (_type, _oper, _userCallback, _userData) Sample: var starSDK = new StarRtc.StarSDK(); currRoom = starSDK.getVideoLiveRoomSDK("vdn", "open", videoLiveVdnCallBack, {"roomInfo":{"id":"", "name":"", "creator":""}});
9.1.2 src(broadcaster)mode
functionvideoLiveSrcCallBack(data, status, oper) { var thisRoom = data.obj; switch (status){ case"connect success": //connect success break; case"connect failed": case"connect closed": //connect failed break; case"onWebrtcMessage": //Video interface message { switch(data.type) { case"streamCreated": //Create the local video stream,and the data.status == "success" means success break; case"srcApplyUpload": //Apply for upload,and the data.status == "success" means success break; case"addUploader": //Someone has joined the live room break; case"removeUploader": //Someone has left the live room break; case"delChannel": //delete the live room,and the data.status == "success" means success break; case"createChannel": //create a live room,and the data.status == "success" means success break; case"streamData": //Receive real-time data break; case"streamConfig": //Set the callback of the video size break; case"serverErr": //server error break; } } break; case"onChatRoomMessage": //Receive chat room message { switch(data.type) { case"recvChatPrivateMsg": //Received private chat messages if(data.msg.msgType == "linkStop") { //Receive the message that you are stopped to link live } elseif(data.msg.msgType == "apply") { //Receive the message that you are invited to be an broadcaster } elseif(data.msg.msgType == "inviteAgree") { //Receive the message that you are agreed to be an broadcaster } elseif(data.msg.msgType == "inviteDisagree") { //Receive the message that you are refused to be an broadcasters } else { //Receive a normal message } break; case"recvChatMsg": //Received a message break; case"chatroomUserKicked": ///Receive the message that you are kicked break; case"serverErr": //Server error break; } } break; } }
Sample: var starSDK = new StarRtc.StarSDK(); currRoom = starSDK.getVideoLiveRoomSDK("src", "open", videoLiveSrcCallBack, {"roomInfo":{"ID":"", "Name":"", "Creator":""}});
9.2 API 说明
/** * Connect to the room */ StarRtc.StarRoomSDK.sigConnect = function () /** * Disconnecttotheroom * @paramflagTheflagofWhethertodisconnectactively, whichisusedtodeterminereconnection */ StarRtc.StarRoomSDK.sigDisconnect = function (_flag) /** * Createaroom */ StarRtc.StarRoomSDK.createNew = function () /** * Deletearoom */ StarRtc.StarRoomSDK.deleteCurrRoom = function () /** * Createalocalvideostream * @paramstreamOptionStreamconfiguration(Resolution, etc.),suchas{ "video": true, "audio": { deviceId: { ideal: ["default"] } } }, or{ "video": { width: { ideal: 640 }, height: { ideal: 480 }, frameRate: { ideal: 25 }, facingMode: { ideal: ["user"] } }, "audio": { deviceId: { ideal: ["default"] } } } */ StarRtc.StarRoomSDK.createStream = function (streamOption) /** * Create a shared screen video stream */ StarRtc.StarRoomSDK.createScreenCaptureStream = function () /** * Set the visibility of the stream (It will affect both local and far peer streams) * @param config Stream visibility configuration{"video":true, "audio":true} */ StarRtc.StarRoomSDK.publishStream = function (config) /** * join the room */ StarRtc.StarRoomSDK.joinRoom = function () /** * leave the room * @param _flag Whether to leave the roomactively(optional) */ StarRtc.StarRoomSDK.leaveRoom = function (_flag) /** * Switch the size of the view * @param streamConfig Switch the configuration of the size map, 1for small, 2for large[1,2,1,2...] */ StarRtc.StarRoomSDK.streamConfigApply = function (streamConfig) /** * Send a chat room message * @param msg message */ StarRtc.StarRoomSDK.sendChatMsg = function (msg) /** * Send chat room private message * @param toUserId the user ID the meaasge will be sent to * @param msg message */ StarRtc.StarRoomSDK.sendChatPrivateMsg = function (userId, msg) /** * Send the message that the audience apply to be an anchor */ StarRtc.StarRoomSDK.sendApplyMsg = function () /** * Send the message that agree the audience apply to be an anchor * @param userId the user ID the meaasge will be sent to */ StarRtc.StarRoomSDK.sendApplyAgreeMsg = function (userId) /** * The creater refuses someone to be a broadcaster * @param userId the user ID the meaasge will be sent to */ StarRtc.StarRoomSDK.sendApplyDisagreeMsg = function (userId) /** * the creater invites someone to be a broadcaster * @param userId the user ID the meaasge will be sent to */ StarRtc.StarRoomSDK.sendInviteLinkMsg = function (userId) /** * The audience has agreed to be a broadcaster */ StarRtc.StarRoomSDK.sendInviteLinkAgreeMsg = function () /** * The audience has refused to be a broadcaster */ StarRtc.StarRoomSDK.sendInviteLinkDisagreeMsg = function () /** * Send the message that the creater invites someone to start to be a broadcaster */ StarRtc.StarRoomSDK.sendInviteLinkStartMsg = function () /** * Send the message that the user will be stopped to be a broadcaster * @param userId the user ID the meaasge will be sent to */ StarRtc.StarRoomSDK.sendLinkStopMsg = function (userId) /** * Kick out the user * @param kickOutUserId the user ID who will be kicked out */ StarRtc.StarRoomSDK.kickOutUser = function (kickOutUserId) /** * Speaking not allowed in the room * @param banUserId the user ID of who is speaking not allowed * @param banTime the time duration of speaking not allowed */ StarRtc.StarRoomSDK.banToSendMsg = function (banUserId, banTime) /** * Get the number of online users in the chat room */ StarRtc.StarRoomSDK.getRoomOnlineNum = function () /** * Send real-time data * @param data real-time data */ StarRtc.StarRoomSDK.sendStreamData = function (data) /** * Get the disconnect satus:active or passive? */ StarRtc.StarRoomSDK.activeDisconnect = function ()