1 Star 0 Fork 205

ipfshit/starrtc-web

forked from starRTC/starrtc-web 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 53.68 KB
一键复制 编辑 原始数据 按行查看 历史
elesos.com 提交于 2018-11-07 16:32 . update
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
var activeTab = "main";
var agentId = "BjR6QV3vUJ4d";
var userId = "";
var authKey = "";
var videoMeetingMsgWindow = null;
var voipMsgWindow = null;
var videoLiveMsgWindow = null;
var tmpStream;
var MyCanvas = function(_id, _draw_mode, _draw_callback)
{
var id = _id;
var draw_mode = false || _draw_mode;
var draw_callback = null || _draw_callback;
var canvasObj = $("#"+id);
if(canvasObj == undefined)
{
return null;
}
var ctx = canvasObj[0].getContext('2d');
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
var drawPoints = [];
var points = {};
points["-1"] = [];
if(draw_mode)
{
canvasObj.unbind("mousedown");
canvasObj.unbind("mousemove");
canvasObj.unbind("mouseup");
canvasObj.bind("mousedown", function(ev){
var ev=ev || window.event;
ctx.strokeStyle = "red";
ctx.lineCap = 'round';
ctx.lineWidth = 4;
drawPoints = [];
ctx.beginPath();
ctx.moveTo(ev.offsetX,ev.offsetY);
drawPoints.push([ev.offsetX,ev.offsetY]);
canvasObj.bind("mousemove", function(ev){
var ev = ev || window.event;
ctx.lineTo(ev.offsetX,ev.offsetY);
drawPoints.push([ev.offsetX,ev.offsetY]);
ctx.stroke();
});
});
canvasObj.bind("mouseup", function(ev){
canvasObj.unbind("mousemove");
drawPoints.push([0,0]);
if(draw_callback != null)
{
draw_callback(drawPoints);
}
points["-1"] = points["-1"].concat(drawPoints);
});
}
MyCanvas.prototype.addPoint = function(_id,x,y)
{
if(points[_id] == undefined)
{
points[_id] = [];
}
points[_id].push([x,y]);
}
MyCanvas.prototype.setSize = function(width,height)
{
canvasObj[0].width = width;
canvasObj[0].height = height;
ctx = canvasObj[0].getContext('2d');
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
}
MyCanvas.prototype.fitSize = function()
{
if(canvasObj[0].width != canvasObj[0].clientWidth || canvasObj[0].height != canvasObj[0].clientHeight)
{
this.setSize(canvasObj[0].clientWidth, canvasObj[0].clientHeight);
}
}
MyCanvas.prototype.redraw = function()
{
this.fitSize();
this.clearCanvas();
for(var upId in points)
{
var count = 0;
if((count = points[upId].length) > 1)
{
var selectColor = "red";
switch (upId){
case "-1":
selectColor = "#FF6c00";
break;
case "0":
selectColor = "#FF4081";
break;
case "1":
selectColor = "yellow";
break;
case "2":
selectColor = "blue";
break;
case "3":
selectColor = "cyan";
break;
case "4":
selectColor = "green";
break;
case "5":
selectColor = "magenta";
break;
case "6":
selectColor = "red";
break;
}
ctx.lineCap = 'round';
ctx.lineWidth = 4;
ctx.strokeStyle = selectColor;
var flag = false;
var linePoints = 0;
for(var i=0;i<count;++i)
{
if(!flag)
{
ctx.beginPath();
ctx.moveTo(points[upId][i][0], points[upId][i][1]);
flag = true;
linePoints = 1;
}
else
{
if(points[upId][i][0] <= 0)
{
if(linePoints > 1)
{
ctx.stroke();
}
flag = false;
}
else
{
ctx.lineTo(points[upId][i][0], points[upId][i][1]);
linePoints++;
}
}
}
if(flag && linePoints > 1)
{
ctx.stroke();
}
}
}
}
MyCanvas.prototype.clearCanvas = function()
{
ctx.clearRect(0,0,canvasObj[0].width,canvasObj[0].height);
}
MyCanvas.prototype.clearAll = function()
{
points = {"-1":[]};
this.clearCanvas();
}
return this;
}
var currFunc={
"exit":undefined
};
function loginSuccessViewSet()
{
switchLogin(false);
$("#userId").html(userId);
$("#userImage").html("<image src=\"images/user.png\" />");
bindTabs(true);
videoMeetingMsgWindow.userName = userId;
videoMeetingMsgWindow.setShowHideCallBack(1000, null, 1000, function(){
$("#videoMeetingVideoZone").css("width", "100%");
$("#vidoeMeetingMessageButton").show();
});
voipMsgWindow.userName = userId;
voipMsgWindow.setShowHideCallBack(1000, null, 1000, function(){
$("#voipVideoZone").css("width", "100%");
$("#voipMessageButton").show();
});
videoLiveMsgWindow.userName = userId;
videoLiveMsgWindow.setShowHideCallBack(1000, null, 1000, function(){
$("#videoLiveVideoZone").css("width", "100%");
$("#vidoeLiveMessageButton").show();
});
}
function starlogout()
{
StarRtc.Instance.logout();
bindTabs(false);
$("#userImage").html("");
userId = "";
authKey = "";
$("#userId").html("请先登录");
switchLogin(true);
}
function switchLogin(flag)
{
$("#login").unbind("click");
$("#login").bind("click", flag?starlogin:starlogout);
$("#login").html(flag?"登录":"退出");
}
function showMainTab()
{
activeTab = "main";
$(".tab[id!=mainTab]").hide();
$("#mainTab").slideDown(2000);
}
function showVoipTab()
{
activeTab = "voip";
$(".tab").hide();
$("#voipTab").slideDown(2000, enterVoipFunc);
}
function showVideoLiveTab()
{
activeTab = "videoLive";
$(".tab").hide();
$("#videoLiveTab").slideDown(2000, enterVideoLiveFunc);
}
function showVideoMeetingTab()
{
activeTab = "videoMeeting";
$(".tab").hide();
$("#videoMeetingTab").slideDown(2000, enterVideoMeetingFunc);
}
function showIotCarTab()
{
activeTab = "iotCar";
$(".tab").hide();
$("#iotCarTab").slideDown(2000, enterIotCarFunc);
}
function bindTabs(flag)
{
if(flag)
{
$("#voipButton").bind("click", showVoipTab);
$("#videoLiveButton").bind("click", showVideoLiveTab);
$("#videoMeetingButton").bind("click", showVideoMeetingTab);
$("#iotCarButton").bind("click", showIotCarTab);
}
else
{
$("#voipButton").unbind("click");
$("#videoLiveButton").unbind("click");
$("#videoMeetingButton").unbind("click");
$("#iotCarButton").unbind("click");
}
}
function bindEvent()
{
$(".backButton").each(function(id, ele){
$(ele).bind("click", function(){
showMainTab();
if(currFunc.exit != undefined)
{
currFunc.exit();
}
});
});
$("#vidoeLiveApplyButton").bind("click", vidoeLiveVdnApply);
$("#vidoeCanvasButton").bind("click", videoLiveCanvasShow)
$("#vidoeMeetingCreateButton").bind("click", vidoeMeetingCreateNewDlg);
$("#vidoeMeetingMessageButton").bind("click", function(){
$("#videoMeetingVideoZone").css("width", "85%");
$("#videoMeetingVideoZone").css("float", "left");
$("#vidoeMeetingMessageButton").hide();
videoMeetingMsgWindow.show();
});
$("#vidoeLiveCreateButton").bind("click", vidoeLiveCreateNewDlg);
$("#vidoeLiveMessageButton").bind("click", function(){
$("#videoLiveVideoZone").css("width", "85%");
$("#videoLiveVideoZone").css("float", "left");
$("#vidoeLiveMessageButton").hide();
videoLiveMsgWindow.show();
});
$("#voipMessageButton").bind("click", function(){
$("#voipVideoZone").css("width", "85%");
$("#voipVideoZone").css("float", "left");
$("#voipMessageButton").hide();
voipMsgWindow.show();
});
$("#voipCalling").bind("click", callingVOIP);
$("#voipHangup").bind("click", hangupVOIP);
$("#voipSmallVideo").bind("click", switchVoipVideo);
$("#voipBigVideo").bind("click", switchVoipVideo);
$("#iotCarCtrlUp").bind("mousedown", function(){
iotCarCtrl("up");
});
$("#iotCarCtrlDown").bind("mousedown", function(){
iotCarCtrl("down")
});
$("#iotCarCtrlLeft").bind("mousedown", function(){
iotCarCtrl("left");
});
$("#iotCarCtrlRight").bind("mousedown", function(){
iotCarCtrl("right");
});
$("#iotCarStart").bind("click", startIotCar);
}
//////////////////////////////////////////////star box////////////////////////////////////////
function starlogin(evt, _userId)
{
if(_userId == undefined)
{
_userId = ""+ (Math.floor(Math.random()*899999) + 100000);
//_userId = "VIP9527";
}
userId = _userId;
$("#userImage").html("<div class=\"rect1\"></div>\n<div class=\"rect2\"></div>\n<div class=\"rect3\"></div>\n<div class=\"rect4\"></div>\n<div class=\"rect5\"></div>");
setCookie("starrtc_userId",userId,null);
$.get("https://api.starrtc.com/demo/authKey.php?userid="+userId,function (data,status) {
//traceLog("authKey 返回:"+status+"||"+data);
if(status === "success"){
var obj = JSON.parse(data);
if(obj.status == 1){
authKey = obj.data;
setCookie("starrtc_authKey",authKey,null);
loginSuccessViewSet();
starRtcLogin(agentId,userId,authKey,starRtcLoginCallBack);
}
}else{
$('#userId').html("登录失败");
}
});
}
function starRtcLoginCallBack(data,status) {
switch (status){
//链接状态
case "connect success":
case "connect failed":
case "connect closed":
break;
//收到消息
case "onSingleMessage":
var fid = data.fromId;
//var msgJson = JSON.parse(data.msg);
//var msgTxt = msgJson.contentData;
voipMsgWindow.displayMessage(data.fromId, data.msg.contentData, false);
//setSingleMessageInnerHTML(fid+":<br/>&nbsp;&nbsp;&nbsp;"+msgTxt);
break;
case "onGroupMessage":
var gid = data.groupId;
var fid = data.fromId;
var msgJson = JSON.parse(data.msg);
var msgTxt = msgJson.contentData;
setGroupMessageInnerHTML(gid,fid+":<br/>&nbsp;&nbsp;&nbsp;"+msgTxt);
break;
case "onGroupPrivateMessage":
var gid = data.groupId;
var fid = data.fromId;
var msgJson = JSON.parse(data.msg);
var msgTxt = msgJson.contentData;
setGroupMessageInnerHTML(gid,fid+":<br/>&nbsp;&nbsp;&nbsp;"+msgTxt);
break;
case "onGroupPushMessage":
var gid = data.groupId;
var msgJson = JSON.parse(data.msg);
var msgTxt = msgJson.contentData;
setGroupMessageInnerHTML(gid,msgTxt);
break;
case "onSystemPushMessage":
var msgJson = JSON.parse(data.msg);
var msgTxt = msgJson.contentData;
setSingleMessageInnerHTML(status+":"+msgTxt);
setGroupMessageInnerHTML("all",status+":"+msgTxt);
break;
case "onVoipMessage":
switch(data.type)
{
case "voipCall":
$("#callerId").html(data.fromId);
voipResponseDlg.dialog("open");
break;
case "voipRefuse":
$("#callerId").html("");
alert("对方拒绝了通话!");
break;
}
break;
case "onErrorMessage":
switch(data.errId)
{
case 2:
alert("您的账号在另外的设备登录,您已经下线");
$(".backButton")[0].click();
starlogout();
break;
}
break;
}
};
function starRtcLogin(agentId,userId,authKey,callBack)
{
StarRtc.Instance.version();
StarRtc.Instance.login(agentId,userId,authKey,callBack);
}
//////////////////////////////////////////////star box end////////////////////////////////////////
//////////////////////////////////////////////webrtc//////////////////////////////////////////////
function createWebrtcStream(callback)
{
rtc.createStream({
"video": {
width: { min: 640, ideal: 640, max: 640 },
height: { min: 480, ideal: 480, max: 480 },
frameRate: { ideal: 15, max: 15 }
}
//"audio": true
}, callback);
}
//////////////////////////////////////////////webrtc end//////////////////////////////////////////
//////////////////////////////////////////////videoMeeting////////////////////////////////////////
var videoMeetingIds;
var selectVideoMeetingIndex;
var videoMeetingCreateDialog;
var videoMeetingDelDialog;
var oldBigVideo;
var nowBigVideo;
var currRoom = null;
//获取视频会议列表
function enterVideoMeetingFunc()
{
currFunc.exit = exitVideoMeetingFunc;
$("#videoMeetingList").html("");
loadVideoMeetingList();
}
function loadVideoMeetingList(_callback)
{
$("#videoMeetingList").html("");
$.get("https://api.starrtc.com/demo/meeting/list.php",function (data,status) {
//traceLog("groupList 返回:"+status+"||"+data);
if(status === "success"){
var obj = JSON.parse(data);
if(obj.status == 1){
videoMeetingIds = obj.data;
for(var i = 0;i<videoMeetingIds.length;i++){
var item = videoMeetingIds[i];
$("#videoMeetingList")[0].innerHTML +=
"<div class='button2' onclick='openVideoMeeting("+i+")'>"+item.Name+"</div>";
}
if(_callback != undefined)
{
_callback();
}
}else{
$("videoMeetingList").html("获取失败");
}
}else{
$("videoMeetingList").html("获取失败");
}
});
}
//进入视频会议
function openVideoMeeting(index, from){
if(selectVideoMeetingIndex==index)return;
if(currRoom != null)
{
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
selectVideoMeetingIndex = index;
currRoom = StarRtc.Instance.getVideoMeetingRoomSDK("open", videoMeetingCallBack, {"roomInfo":videoMeetingIds[index]});
currRoom.sigConnect();
}
function joinMeetingRoom(meetingInfo)
{
$('#videoMeetingTitle').html("");
$('#videoMeetingTitle').html(meetingInfo.Name);
if(meetingInfo.Creator == userId)
{
var delButton = $("<div style=\"width:25px;height:25px;position:absolute;left:10px;top:10px;background-image: url(images/exitMsgWindow.jpg);background-size: cover;cursor:pointer;z-index:1;\"></div>");
delButton.bind("click", function(){
videoMeetingDelDialog.dialog("open");
});
$('#videoMeetingTitle').append(delButton);
}
}
function videoMeetingSetStream(object)
{
var selfVideo = $("#videoMeetingSelfVideo")[0];
selfVideo.srcObject = object;
selfVideo.play();
}
function videoMeetingCallBack(data, status, oper)
{
var thisRoom = data.obj;
switch (status){
//链接状态
case "connect success":
//alert(status);
switch(oper)
{
case "open":
thisRoom.createStream();
break;
case "new":
thisRoom.createNew();
break;
}
break;
case "connect failed":
case "connect closed":
//alert(status + ":" + data.data);
stopVideoMeeting();
break;
case "onChatRoomMessage":
//alert(data.type + ":" + data.status);
switch(data.type)
{
case "joinChatRoom":
if(data.status == "success")
{}
else
{
alert(data.failedStatus);
}
break;
}
break;
case "onWebrtcMessage":
//alert(data.type + ":" + data.status);
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
videoMeetingSetStream(data.streamObj);
//alert("joinRoom" + ":" + oper);
switch(oper)
{
case "open":
thisRoom.joinRoom();
break;
case "new":
thisRoom.joinRoom();
break;
}
}
else
{
alert("获取摄像头视频失败!请检查摄像头设备是否接入!");
}
break;
case "srcApplyUpload":
if(data.status == "success")
{
//data.userData.roomInfo.Name += ":---Big---:" + data.tmpData.bigVideoSSRC + ":---small---:" + data.tmpData.smallVideoSSRC
joinMeetingRoom(data.userData.roomInfo);
}
else
{
alert("上传申请失败");
console.log("收到_webrtc_apply_failed");
}
break;
case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
var streamInfo = data.streamInfo;
streamInfo.videoId = newVideoId;
videoMeetingAddNewVideo(newVideoId, streamInfo.streamObj, function(evt){
thisRoom.streamConfigChange(data.upId);
});
break;
case "removeUploader":
var streamInfo = data.streamInfo;
var newVideoId = streamInfo.videoId;
removeNewVideo($("#videoMeetingVideoZone"), $("#" + newVideoId));
if(data.bigFlag)
{
var videos = $("#videoMeetingVideoZone").find("video[id!='videoMeetingSelfVideo']");
if(videos.length > 0)
{
videos[videos.length - 1].click();
}
}
break;
case "delChannel":
if(data.status == "success")
{
videoMeetingDelDialog.dialog("close");
loadVideoMeetingList();
}
else
{
alert("删除视频会议失败");
}
break;
case "createChannel":
if(data.status == "success")
{
videoMeetingCreateDialog.dialog("close");
loadVideoMeetingList(function(){
var index = -1;
for(var i in videoMeetingIds)
{
if(videoMeetingIds[i].ID == data.userData.roomInfo.ID)
{
index = i;
}
}
if(index >= 0)
{
selectVideoMeetingIndex = index;
}
else
{
selectVideoMeetingIndex = undefined;
}
thisRoom.createStream();
});
}
else
{
alert("创建失败:" + data.msg);
}
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
break;
}
}
function stopVideoMeeting()
{
videoMeetingCreateDialog.dialog("close");
videoMeetingDelDialog.dialog("close");
selectVideoMeetingIndex = undefined;
$('#videoMeetingTitle').html("");
$("#videoMeetingVideoZone").children().each(function(ids,ele){
var video = $(ele).children("video").first();
if(video.attr("id") != "videoMeetingSelfVideo")
{
$(ele).remove();
}
else
{
video[0].srcObject = null;
video[0].load();
}
});
}
function exitVideoMeetingFunc()
{
if(currRoom != null)
{
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
}
function videoMeetingAddNewVideo(newVideoId, stream, clickCallback)
{
var parentObj = $("#videoMeetingVideoZone");
var wrapperObj = $("<div></div>");
var videoObj = $("<video id=\"" + newVideoId + "\" style=\"width:100%;height:100%\"></video>");
videoObj.bind("click", clickCallback);
wrapperObj.append(videoObj);
addNewVideo(parentObj, wrapperObj);
videoObj[0].srcObject = stream;
videoObj[0].play();
}
function vidoeMeetingCreateNewDlg()
{
$("#newMeetingName").val("网页会议_"+userId);
videoMeetingCreateDialog.dialog("open");
}
function videoMeetingCreateNewMeeting()
{
var newMeetingName = $("#newMeetingName").val();
if(newMeetingName == "")
{
alert("会议室名称不能为空!");
}
else
{
var type = $('#meetingTypecheck').is(':checked')?1:0;
currRoom = StarRtc.Instance.getVideoMeetingRoomSDK("new", videoMeetingCallBack, {"roomInfo":{
"Creator":userId,
"ID":"",
"Name":newMeetingName,
"Type":type
}
}
);
currRoom.sigConnect();
}
}
function videoMeetingDelMeeting()
{
//if(selectVideoMeetingIndex != undefined)
{
if(currRoom != null)
{
currRoom.deleteCurrRoom();
}
}
}
//////////////////////////////////////////////videoMeeting end////////////////////////////////
//////////////////////////////////////////////videoLive///////////////////////////////////////
var videoLiveIds;
var selectVideoLiveIndex;
var videoLiveCreateDialog;
var videoLiveDelDialog;
var videoLiveManageDialog;
var videoLiveMyCanvas = null;
var videoLiveCanvasDlg;
//获取视频会议列表
function enterVideoLiveFunc()
{
currFunc.exit = exitVideoLiveFunc;
$("#videoLiveList").html("");
loadVideoLiveList();
}
function exitVideoLiveFunc()
{
if(currRoom != null)
{
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
}
//获取视频会议列表
function loadVideoLiveList(_callback)
{
$("#videoLiveList").html("");
$.get("https://api.starrtc.com/demo/live/list.php",function (data,status) {
//traceLog("groupList 返回:"+status+"||"+data);
if(status === "success"){
var obj = JSON.parse(data);
if(obj.status == 1){
videoLiveIds = obj.data;
for(var i = 0;i<videoLiveIds.length;i++){
var item = videoLiveIds[i];
$("#videoLiveList")[0].innerHTML +=
"<div class='button2' onclick='openVideoLive("+i+")'>"+item.Name+"</div>";
}
if(_callback != undefined)
{
_callback();
}
}else{
$("videoLiveList").html("获取失败");
}
}else{
$("videoLiveList").html("获取失败");
}
});
}
function joinLiveRoom(liveInfo)
{
$('#videoLiveTitle').html("");
$('#videoLiveTitle').html(liveInfo.Name);
if(liveInfo.Creator == userId)
{
var delButton = $("<div style=\"width:25px;height:25px;position:absolute;left:10px;top:10px;background-image: url(images/exitMsgWindow.jpg);background-size: cover;cursor:pointer;z-index:1;\"></div>");
delButton.bind("click", function(){
videoLiveDelDialog.dialog("open");
});
$('#videoLiveTitle').append(delButton);
}
}
function videoLiveSetStream(object)
{
$("#videoLiveSelfVideo").parent().show();
var selfVideo = $("#videoLiveSelfVideo")[0];
selfVideo.srcObject = object;
selfVideo.play();
}
function videoLiveSrcCallBack(data, status, oper)
{
var thisRoom = data.obj;
switch (status){
//链接状态
case "connect success":
switch(oper)
{
case "open":
thisRoom.createStream();
break;
case "new":
thisRoom.createNew();
break;
}
break;
case "connect failed":
case "connect closed":
stopVideoLive();
break;
case "onWebrtcMessage":
{
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
videoLiveSetStream(data.streamObj);
switch(oper)
{
case "open":
thisRoom.joinRoom();
break;
case "new":
thisRoom.joinRoom();
break;
}
}
else
{
alert("获取摄像头视频失败!请检查摄像头设备是否接入!");
}
break;
case "srcApplyUpload":
if(data.status == "success")
{
if(oper == "new")
{
videoLiveMyCanvas = new MyCanvas("videoLiveMyCanvas", true, canvasDrawCallback);
}
$("#vidoeLiveApplyButton").hide();
$("#vidoeCanvasButton").show();
joinLiveRoom(data.userData.roomInfo);
}
else
{
alert("上传视频申请失败!");
console.log("收到_webrtc_apply_failed");
}
break;
case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
var streamInfo = data.streamInfo;
streamInfo.videoId = newVideoId;
videoLiveAddNewVideo(newVideoId, streamInfo.streamObj, function(evt){
thisRoom.streamConfigChange(data.upId);
});
break;
case "removeUploader":
var streamInfo = data.streamInfo;
var newVideoId = streamInfo.videoId;
removeNewVideo($("#videoLiveVideoZone"), $("#" + newVideoId));
if(data.bigFlag)
{
var videos = $("#videoLiveVideoZone").find("video[id!='videoLiveSelfVideo']");
if(videos.length > 0)
{
videos[videos.length - 1].click();
}
}
break;
case "delChannel":
if(data.status == "success")
{
videoLiveDelDialog.dialog("close");
loadVideoLiveList();
}
else
{
alert("删除视频会议失败");
}
break;
case "createChannel":
if(data.status == "success")
{
videoLiveCreateDialog.dialog("close");
loadVideoLiveList(function(){
var index = -1;
for(var i in videoLiveIds)
{
if(videoLiveIds[i].ID == data.userData.roomInfo.ID)
{
index = i;
}
}
if(index >= 0)
{
selectVideoLiveIndex = index;
}
else
{
selectVideoLiveIndex = undefined;
}
thisRoom.createStream();
});
}
else
{
alert("创建失败:" + data.msg);
}
break;
case "streamData":
if(data.streamData != "CLEAN")
{
if(data.streamData.indexOf(",") != -1)
{
videoLiveCanvasDlg.dialog("open");
var points = data.streamData.split("/");
for(var i in points)
{
var point = points[i].split(",");
videoLiveMyCanvas.addPoint(data.upId, parseInt(point[0]), parseInt(point[1]));
}
videoLiveMyCanvas.redraw();
}
}
else
{
videoLiveMyCanvas.clearAll();
}
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
}
break;
case "onChatRoomMessage":
{
switch(data.type)
{
case "recvChatPrivateMsg":
if(data.msg.msgType == "linkStop")
{
openVideoLive(selectVideoLiveIndex);
}
else if(data.msg.msgType == "apply")
{
videoLiveManageDialog.userData = {"fromUserId":data.fromUserId};
$("#applyTargetId").html(data.msg.fromId);
videoLiveManageDialog.dialog("open");
}
else if(data.msg.msgType == "inviteAgree")
{
}
else if(data.msg.msgType == "inviteDisagree")
{
alert(data.msg.fromId +"拒绝了您的连麦邀请!")
}
else
{
videoLiveMsgWindow.displayMessage(data.msg.fromId + "私信", data.msg.contentData, false);
}
break;
case "recvChatMsg":
videoLiveMsgWindow.displayMessage(data.msg.fromId, data.msg.contentData, false);
break;
case "chatroomUserKicked":
thisRoom.leaveRoom();
alert("你已被踢出房间!");
break;
case "deleteChatRoom":
if(data.status == "success")
{
videoLiveDelDialog.dialog("close");
loadVideoLiveList();
}
else
{
alert("删除聊天室失败");
}
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
}
break;
}
}
function videoLiveVdnCallBack(data, status, oper)
{
var thisRoom = data.obj;
switch (status){
//链接状态
case "connect success":
switch(oper)
{
case "open":
thisRoom.createStream();
break;
case "new":
break;
}
break;
case "connect failed":
case "connect closed":
stopVideoLive();
break;
case "onWebrtcMessage":
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
thisRoom.joinRoom();
}
else
{
alert("获取摄像头视频失败!请检查摄像头设备是否接入!");
}
break;
case "vdnApplyDownload":
if(data.status == "success")
{
joinLiveRoom(data.userData.roomInfo);
$("#vidoeLiveApplyButton").show();
}
else
{
alert("获取数据失败");
console.log("收到vdnApplyDownload_failed");
thisRoom.leaveRoom();
}
break;
case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
var streamInfo = data.streamInfo;
streamInfo.videoId = newVideoId;
videoLiveAddNewVideo(newVideoId, streamInfo.streamObj, function(evt){
thisRoom.streamConfigChange(data.upId);
});
break;
case "removeUploader":
var streamInfo = data.streamInfo;
var newVideoId = streamInfo.videoId;
removeNewVideo($("#videoMeetingVideoZone"), $("#" + newVideoId));
if(data.bigFlag)
{
var videos = $("#videoLiveVideoZone").find("video[id!='videoLiveSelfVideo']");
if(videos.length > 0)
{
videos[videos.length - 1].click();
}
}
break;
case "streamData":
videoLiveCanvasDlg.dialog("open");
if(data.streamData != "CLEAN")
{
var points = data.streamData.split("/");
for(var i in points)
{
var point = points[i].split(",");
videoLiveMyCanvas.addPoint(data.upId, parseInt(point[0]), parseInt(point[1]));
}
videoLiveMyCanvas.redraw();
}
else
{
videoLiveMyCanvas.clearAll();
}
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
break;
case "onChatRoomMessage":
{
switch(data.type)
{
case "recvChatPrivateMsg":
if(data.msg.msgType == "applyAgree" || data.msg.msgType == "inviteStart")
{
openVideoLive(selectVideoLiveIndex, "applyAgree");
}
else if(data.msg.msgType == "linkStop")
{
openVideoLive(selectVideoLiveIndex);
}
else if(data.msg.msgType == "applyDisagree")
{
alert("房主拒绝了连麦申请");
}
else if(data.msg.msgType == "invite")
{
}
else
{
videoLiveMsgWindow.displayMessage(data.msg.fromId + "私信", data.msg.contentData, false);
}
break;
case "recvChatMsg":
videoLiveMsgWindow.displayMessage(data.msg.fromId, data.msg.contentData, false);
break;
case "chatroomUserKicked":
thisRoom.leaveRoom();
alert("你已被踢出房间!");
break;
case "serverErr":
alert("服务器错误:" + data.msg);
break;
}
}
break;
}
}
function stopVideoLive()
{
if(videoLiveMyCanvas != undefined)
{
videoLiveMyCanvas.clearAll();
}
$("#vidoeLiveApplyButton").hide();
$("#vidoeCanvasButton").hide();
videoLiveCreateDialog.dialog("close");
videoLiveDelDialog.dialog("close");
selectVideoLiveIndex = undefined;
$('#videoLiveTitle').html("");
$("#videoLiveVideoZone").children().each(function(ids,ele){
var video = $(ele).children("video").first();
if(video.attr("id") != "videoLiveSelfVideo")
{
$(ele).remove();
}
else
{
video[0].srcObject = null;
video[0].load();
}
});
}
function videoLiveAddNewVideo(newVideoId, stream, clickCallback)
{
var parentObj = $("#videoLiveVideoZone");
var wrapperObj = $("<div></div>");
var videoObj = $("<video id=\"" + newVideoId + "\" style=\"width:100%;height:100%\"></video>");
videoObj.bind("click", clickCallback);
wrapperObj.append(videoObj);
addNewVideo(parentObj, wrapperObj);
videoObj[0].srcObject = stream;
videoObj[0].play();
}
function addNewVideo(parentObj, videoObject)
{
var childrenObjs = parentObj.children();
switch(childrenObjs.length)
{
case 0:
videoObject.css({"width":"100%","height":"100%", "float":"left"});
break;
case 1:
childrenObjs.css({"width":"50%","height":"100%", "float":"left"});
videoObject.css({"width":"50%","height":"100%", "float":"left"});
break;
case 2:
childrenObjs.css({"width":"33.33%","height":"100%", "float":"left"});
videoObject.css({"width":"33.33%","height":"100%", "float":"left"});
break;
case 3:
childrenObjs.css({"width":"50%","height":"50%", "float":"left"});
videoObject.css({"width":"50%","height":"50%", "float":"left"});
break;
case 4:
childrenObjs.css({"width":"33.33%","height":"100%", "float":"left"});
videoObject.css({"width":"33.33%","height":"100%", "float":"left"});
break;
case 5:
childrenObjs.css({"width":"33.33%","height":"50%", "float":"left"});
videoObject.css({"width":"33.33%","height":"50%", "float":"left"});
break;
case 6:
childrenObjs.css({"width":"33.33%","height":"100%", "float":"left"});
videoObject.css({"width":"33.33%","height":"100%", "float":"left"});
break;
}
parentObj.append(videoObject);
}
function removeNewVideo(parentObj, videoObject)
{
if(videoObject != undefined)
{
videoObject.parent().remove();
var childrenObjs = parentObj.children();
switch(childrenObjs.length)
{
case 1:
childrenObjs.css({"width":"100%","height":"100%", "float":"left"});
break;
case 2:
childrenObjs.css({"width":"50%","height":"100%", "float":"left"});
break;
case 3:
childrenObjs.css({"width":"33.33%","height":"100%", "float":"left"});
break;
case 4:
childrenObjs.css({"width":"50%","height":"50%", "float":"left"});
break;
case 5:
childrenObjs.css({"width":"33.33%","height":"50%", "float":"left"});
break;
case 6:
childrenObjs.css({"width":"33.33%","height":"50%", "float":"left"});
break;
}
}
}
//进入视频会议
function openVideoLive(index, from){
var tmpFrom = from || "";
if(selectVideoLiveIndex==index && tmpFrom != "applyAgree") return;
if(currRoom != null)
{
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
selectVideoLiveIndex = index;
if(videoLiveIds[index].Creator == userId || tmpFrom == "applyAgree")
{
videoLiveMyCanvas = new MyCanvas("videoLiveMyCanvas", true, canvasDrawCallback);
currRoom = StarRtc.Instance.getVideoLiveRoomSDK("src", "open", videoLiveSrcCallBack, {"roomInfo":videoLiveIds[index]});
}
else
{
videoLiveMyCanvas = new MyCanvas("videoLiveMyCanvas", true, canvasDrawCallback);
$("#videoLiveSelfVideo").parent().hide();
currRoom = StarRtc.Instance.getVideoLiveRoomSDK("vdn", "open", videoLiveVdnCallBack, {"roomInfo":videoLiveIds[index]});
}
currRoom.sigConnect();
}
function videoLiveCanvasShow()
{
if(videoLiveMyCanvas != null)
{
videoLiveCanvasDlg.dialog("open");
}
}
function videoLiveCleanCanvas()
{
if(videoLiveMyCanvas != null && currRoom != null)
{
videoLiveMyCanvas.clearAll();
currRoom.sendStreamData("CLEAN");
}
}
function canvasDrawCallback(points)
{
if(currRoom)
{
var data = points.join("/");
currRoom.sendStreamData(data);
}
}
function vidoeLiveCreateNewDlg()
{
$("#newLiveName").val("网页直播_"+userId);
videoLiveCreateDialog.dialog("open");
}
function videoLiveCreateNewLive()
{
var newLiveName = $("#newLiveName").val();
if(newLiveName == "")
{
alert("直播名称不能为空!");
}
else
{
var type = $('#liveTypecheck').is(':checked')?1:0;
currRoom = StarRtc.Instance.getVideoLiveRoomSDK("src", "new", videoLiveSrcCallBack, {"roomInfo":{
"Creator":userId,
"ID":"",
"Name":newLiveName,
"Type":type
}
}
);
currRoom.sigConnect();
}
}
function videoLiveDelLive()
{
//if(selectVideoLiveIndex != undefined)
{
if(currRoom != null)
{
currRoom.deleteCurrRoom();
}
}
}
function videoLiveInputMsgCallBack(msg)
{
if(currRoom != null)
{
currRoom.sendChatMsg(msg);
}
}
function vidoeLiveVdnApply()
{
if(currRoom != null)
{
currRoom.sendApplyMsg();
}
}
function videoLiveKickOutUser()
{
if(currRoom != null)
{
var kickOutUserId = $("#applyTargetId").html();
currRoom.kickOutUser(kickOutUserId);
}
}
function videoLiveBanToSendMsg()
{
}
function videoLiveSendPrivateMsg()
{
}
function videoLiveApplyAgree()
{
if(currRoom != null)
{
var userId = $("#applyTargetId").html();
currRoom.sendApplyAgreeMsg(userId);
}
videoLiveManageDialog.dialog( "close" );
}
function videoLiveLinkStop()
{
if(currRoom != null)
{
var userId = $("#applyTargetId").html();
currRoom.sendLinkStopMsg(userId);
}
}
//////////////////////////////////////////////videoLive end///////////////////////////////////
//////////////////////////////////////////////voip////////////////////////////////////////////
var voipResponseDlg;
function enterVoipFunc()
{
currFunc.exit = exitVoipFunc;
}
function exitVoipFunc()
{
if(currRoom != null)
{
currRoom.leaveRoom();
currRoom.sigDisconnect();
currRoom = null;
}
}
function callingVOIP()
{
var targetUid = $('#targetUserId').val();
if(targetUid==null||targetUid==undefined||targetUid==""){
alert("对方ID不能为空");
return;
}
currRoom = StarRtc.Instance.getVoipRoomSDK("call", voipCallBack, {"roomInfo":{"targetId":targetUid}});
currRoom.sigConnect();
}
function hangupVOIP()
{
exitVoipFunc();
}
function voipCallBack(data, status, oper)
{
var thisRoom = data.obj;
switch (status){
//链接状态
case "connect success":
thisRoom.createStream();
break;
case "connect failed":
case "connect closed":
stopVoip();
break;
case "onWebrtcMessage":
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
voipSetStream($("#voipSmallVideo")[0], data.streamObj);
thisRoom.joinRoom();
}
else
{
alert("获取摄像头视频失败!请检查摄像头设备是否接入!");
}
break;
case "voipCalling":
if(data.status == "success")
{
}
break;
case "voipStreamReady":
voipSetStream($("#voipBigVideo")[0], data.streamObj);
break;
}
break;
case "onVoipMessage":
switch(data.type)
{
case "voipRefuse":
$("#callerId").html("");
alert("对方拒绝了通话!");
thisRoom.sigDisconnect();
break;
case "voipHangup":
alert("对方挂断了通话!");
break;
case "voipConnect":
break;
case "voipBusy":
alert("对方正忙!");
break;
case "voipSingleMsg":
voipMsgWindow.displayMessage(data.fromId, data.msg.contentData, false);
break;
}
break;
}
}
function voipSetStream(videoObj, streamObj)
{
videoObj.srcObject = streamObj;
videoObj.play();
}
var voipMode = true;
function switchVoipVideo()
{
$("#voipSmallVideo")[0].style="float:left;";
$("#voipBigVideo")[0].style="";
if(voipMode)
{
$("#voipSmallVideo").animate({"max-width":"85%","height":"100%"}, 1000);
$("#voipBigVideo").animate({"width":"15%","max-height":"100%"}, 1000);
}
else
{
$("#voipBigVideo").animate({"max-width":"85%","height":"100%"}, 1000);
$("#voipSmallVideo").animate({"width":"15%","max-height":"100%"}, 1000);
}
voipMode = !voipMode;
}
function voipAcceptCall()
{
if(currFunc.exit != undefined)
{
currFunc.exit();
}
showVoipTab();
var targetId = $("#callerId").html();
currRoom = StarRtc.Instance.getVoipRoomSDK("response", voipCallBack, {"roomInfo":{"targetId":targetId}});
currRoom.sigConnect();
voipResponseDlg.dialog("close");
}
function voipRefuseCall()
{
var targetId = $("#callerId").html();
StarRtc.Instance.sendVoipRefuseMsg(targetId);
voipResponseDlg.dialog("close");
}
function stopVoip()
{
voipResponseDlg.dialog("close");
$("#callerId").html("");
$('#targetUserId').val("");
$("#voipBigVideo")[0].srcObject = null;
$("#voipBigVideo")[0].load();
$("#voipSmallVideo")[0].srcObject = null;
$("#voipSmallVideo")[0].load();
}
function voipInputMsgCallBack(msg)
{
if(currRoom != null)
{
currRoom.sendVoipMsg(msg);
}
}
//////////////////////////////////////////////void end////////////////////////////////////////
//////////////////////////////////////////////iot car start////////////////////////////////////////
var Demo = window.NameSpace || {};
Demo.IotCarSDK = function()
{
var self = this;
var roomSDK = null;
var starImInterface = StarRtc.Instance;
var car0Id = "xh_iot_car_0";
var userData = {"roomInfo":{}};
starImInterface.setIMExtraback(function(_data,status){
iotInnerCallback(_data,"onIotMessage");
});
var iotInnerCallback = function (data, status) {
data.userData = userData;
data.obj = self;
switch (status){
case "onIotMessage":
{
if(data.msg.fromId == car0Id)
{
userData.roomInfo.ID = data.msg.contentData;
userData.roomInfo.Creator = car0Id;
roomSDK = StarRtc.Instance.getVideoLiveRoomSDK("vdn", "open", iotCarVdnCallBack, userData);
roomSDK.sigConnect();
}
}
break;
default:
break;
}
}
function iotCarVdnCallBack(data, status, oper)
{
data.obj = self;
switch (status){
//链接状态
case "connect success":
roomSDK.createStream();
break;
case "connect failed":
case "connect closed":
//stopVideoLive();
break;
case "onWebrtcMessage":
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
roomSDK.joinRoom();
}
else
{
}
break;
case "vdnApplyDownload":
if(data.status == "success")
{
roomSDK.sendApplyMsg();
//joinLiveRoom(data.userData.roomInfo);
//$("#vidoeLiveApplyButton").show();
}
else
{
console.log("收到vdnApplyDownload_failed");
roomSDK.leaveRoom();
}
break;
/* case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
var streamInfo = data.streamInfo;
streamInfo.videoId = newVideoId;
videoLiveAddNewVideo(newVideoId, streamInfo.streamObj, function(evt){
thisRoom.streamConfigChange(data.upId);
});
break;
case "removeUploader":
var streamInfo = data.streamInfo;
var newVideoId = streamInfo.videoId;
removeNewVideo($("#videoMeetingVideoZone"), $("#" + newVideoId));
if(data.bigFlag)
{
var videos = $("#videoLiveVideoZone").find("video[id!='videoLiveSelfVideo']");
if(videos.length > 0)
{
videos[videos.length - 1].click();
}
}
break;
case "streamData":
videoLiveCanvasDlg.dialog("open");
if(data.streamData != "CLEAN")
{
var points = data.streamData.split("/");
for(var i in points)
{
var point = points[i].split(",");
videoLiveMyCanvas.addPoint(data.upId, parseInt(point[0]), parseInt(point[1]));
}
videoLiveMyCanvas.redraw();
}
else
{
videoLiveMyCanvas.clearAll();
}
break; */
}
break;
case "onChatRoomMessage":
{
switch(data.type)
{
case "recvChatPrivateMsg":
if(data.msg.msgType == "applyAgree" || data.msg.msgType == "inviteStart")
{
roomSDK.leaveRoom();
roomSDK.sigDisconnect();
roomSDK = null;
roomSDK = StarRtc.Instance.getVideoLiveRoomSDK("src", "open", iotCarSrcCallBack, userData);
roomSDK.sigConnect();
//openVideoLive(selectVideoLiveIndex, "applyAgree");
}
else if(data.msg.msgType == "linkStop")
{
//openVideoLive(selectVideoLiveIndex);
}
else if(data.msg.msgType == "applyDisagree")
{
alert("房主拒绝了连麦申请");
}
else if(data.msg.msgType == "invite")
{
}
else
{
//videoLiveMsgWindow.displayMessage(data.msg.fromId + "私信", data.msg.contentData, false);
}
break;
case "recvChatMsg":
//videoLiveMsgWindow.displayMessage(data.msg.fromId, data.msg.contentData, false);
break;
case "chatroomUserKicked":
roomSDK.leaveRoom();
alert("你已被踢出房间!");
break;
}
}
break;
}
}
function iotCarSrcCallBack(data, status, oper)
{
data.obj = self;
switch (status){
//链接状态
case "connect success":
alert("启动小车成功!");
roomSDK.createStream();
break;
case "connect failed":
case "connect closed":
//stopVideoLive();
break;
case "onWebrtcMessage":
{
switch(data.type)
{
case "streamCreated":
if(data.status == "success")
{
//videoLiveSetStream(data.streamObj);
switch(oper)
{
case "open":
roomSDK.joinRoom();
break;
}
}
else
{
}
break;
case "srcApplyUpload":
if(data.status == "success")
{
//$("#vidoeLiveApplyButton").hide();
//joinLiveRoom(data.userData.roomInfo);
}
else
{
console.log("收到_webrtc_apply_failed");
}
break;
case "addUploader":
var newVideoId = "webrtc_video_" + data.upUserId;
var streamInfo = data.streamInfo;
streamInfo.videoId = newVideoId;
roomSDK.streamConfigChange(data.upId);
iotCarAddNewVideo(newVideoId, streamInfo.streamObj, function(evt){
roomSDK.streamConfigChange(data.upId);
});
break;
case "removeUploader":
var streamInfo = data.streamInfo;
var newVideoId = streamInfo.videoId;
removeNewVideo($("#iotCarVideoZone"), $("#" + newVideoId));
if(data.bigFlag)
{
var videos = $("#iotCarVideoZone").find("video[id!='videoLiveSelfVideo']");
if(videos.length > 0)
{
videos[videos.length - 1].click();
}
}
break;
}
}
break;
case "onChatRoomMessage":
{
switch(data.type)
{
case "recvChatPrivateMsg":
if(data.msg.msgType == "linkStop")
{
//openVideoLive(selectVideoLiveIndex);
}
else if(data.msg.msgType == "apply")
{
//videoLiveManageDialog.userData = {"fromUserId":data.fromUserId};
//$("#applyTargetId").html(data.msg.fromId);
//videoLiveManageDialog.dialog("open");
}
else if(data.msg.msgType == "inviteAgree")
{
}
else if(data.msg.msgType == "inviteDisagree")
{
alert(data.msg.fromId +"拒绝了您的连麦邀请!")
}
else
{
//videoLiveMsgWindow.displayMessage(data.msg.fromId + "私信", data.msg.contentData, false);
}
break;
case "recvChatMsg":
//videoLiveMsgWindow.displayMessage(data.msg.fromId, data.msg.contentData, false);
break;
case "chatroomUserKicked":
roomSDK.leaveRoom();
alert("你已被踢出房间!");
break;
}
}
break;
}
}
self.startIotCar = function()
{
starImInterface.sendSingleMsg(car0Id, "新消息", "IotCarStart", MSG_DATA_TYPE.MSG_DATA_TYPE_CONTROL);
}
self.stopIotCar = function()
{
starImInterface.setIMExtraback(null);
if(roomSDK != null)
{
roomSDK.leaveRoom();
roomSDK.sigDisconnect();
roomSDK = null;
}
}
self.iotCarCtrl = function(type)
{
if(roomSDK != null)
{
roomSDK.sendStreamData(type);
}
}
return self;
}
function iotCarAddNewVideo(newVideoId, stream, clickCallback)
{
var parentObj = $("#iotCarVideoZone");
var wrapperObj = $("<div></div>");
var videoObj = $("<video id=\"" + newVideoId + "\" style=\"width:100%;height:100%\"></video>");
videoObj.bind("click", clickCallback);
wrapperObj.append(videoObj);
addNewVideo(parentObj, wrapperObj);
videoObj[0].srcObject = stream;
videoObj[0].play();
}
function enterIotCarFunc()
{
currFunc.exit = exitIotCarFunc;
}
function exitIotCarFunc()
{
if(currRoom != null)
{
currRoom.stopIotCar();
currRoom = null;
}
}
function startIotCar()
{
if(currRoom != null)
{
currRoom.stopIotCar();
currRoom = null;
}
currRoom = new Demo.IotCarSDK();
currRoom.startIotCar();
}
function iotCarCtrl(type)
{
if(currRoom != null)
{
currRoom.iotCarCtrl("start");
currRoom.iotCarCtrl(type);
$(window).bind("mouseup", function(){
currRoom.iotCarCtrl("stop");
$(window).unbind("mouseup");
});
}
}
var lastData = "camera==";
function iotCarDragStop(event , ui)
{
lastData = "camera==";
if(currRoom)
{
currRoom.iotCarCtrl(lastData);
}
}
function iotCarDrag( event, ui ) {
// Keep the left edge of the element
// at least 100 pixels from the container
/* ui.position.left = Math.min( 50, ui.position.left );
ui.position.top = Math.min( 50, ui.position.top );
ui.position.left = Math.max( -50, ui.position.left );
ui.position.top = Math.max( -50, ui.position.top ); */
var data = lastData;
if(ui.position.left >= 16)
{
if(ui.position.top >= 16)
{
data = "camera-+";
}
else if(ui.position.top <= -17)
{
data = "camera--";
}
else
{
data = "camera-=";
}
}
else if(ui.position.left <= -17)
{
if(ui.position.top >= 16)
{
data = "camera++";
}
else if(ui.position.top <= -17)
{
data = "camera+-";
}
else
{
data = "camera+=";
}
}
else
{
if(ui.position.top >= 16)
{
data = "camera=+";
}
else if(ui.position.top <= -17)
{
data = "camera=-";
}
else
{
data = "camera==";
}
}
if(lastData != data)
{
lastData = data;
//console.log(data);
if(currRoom)
{
currRoom.iotCarCtrl(data);
}
}
}
function showAndroidQr(){
var evt = event || window.event;
var x = evt.clientX;
var y = evt.clientY - 300;
$("#android_app").css({"left":x + "px","top":y + "px", "display":"block", "zIndex":"999"});
//document.getElementById("android_app").style.left = x + "px";
//document.getElementById("android_app").style.top = y + "px";
//document.getElementById("android_app").style.display='block';
//document.getElementById("android_app").style.zIndex='999';
}
function hideAndroidQr(){
document.getElementById("android_app").style.display='none';
}
function showiOSQr(){
var evt = event || window.event;
var x = evt.clientX;
var y = evt.clientY - 300;
document.getElementById("ios_app").style.left = x + "px";
document.getElementById("ios_app").style.top = y + "px";
document.getElementById("ios_app").style.display='block';
document.getElementById("ios_app").style.zIndex='999';
}
function hideiOSQr(){
document.getElementById("ios_app").style.display='none';
}
//////////////////////////////////////////////iot car end////////////////////////////////////////
$().ready(function(){
/* $.ajax({
type: 'POST',
url: "http://10.80.22.174:5000/calc_hash",
data: {
"guid":"1",
"url":"/data1/liuyan3/work/videoIdentify/xzhanjing.mp4",
"callback":"http://10.80.1.175:5001/hello"
}
});
return; */
showMainTab();
var fullHeight = $($(".tab")[0]).height();
var fullWidth = $($(".tab")[0]).width();
var backButtonHeight = $($(".backButton")[0]).height() + 20;
$("#videoMeetingList").height(fullHeight - backButtonHeight);
$("#videoMeetingZone").height(fullHeight - backButtonHeight);
$("#videoLiveList").height(fullHeight - backButtonHeight);
$("#videoLiveZone").height(fullHeight - backButtonHeight);
$("#voipCtrl").height(fullHeight - backButtonHeight);
$("#voipZone").height(fullHeight - backButtonHeight);
$("#iotCarZone").height(fullHeight - backButtonHeight);
videoMeetingMsgWindow = new MyMsgWindow("videoMeetingMsgWindow");
voipMsgWindow = new MyMsgWindow("voipMsgWindow", voipInputMsgCallBack);
videoLiveMsgWindow = new MyMsgWindow("videoLiveMsgWindow", videoLiveInputMsgCallBack);
$("#iotCarMsgWindow").hide();
$("#videoLiveMsgWindow").hide();
$("#videoMeetingMsgWindow").hide();
$("#voipMsgWindow").hide();
$("#vidoeLiveApplyButton").hide();
$("#vidoeCanvasButton").hide();
$("#iotCarButton").hide();
$("#videoLiveSelfVideo").parent().hide();
$( "#iotCarDrag" ).draggable({
drag: iotCarDrag,
revert: true,
containment: "#iotCarDragZone",
stop:iotCarDragStop
});
voipResponseDlg = $("#voipResponseDlg").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"同意": voipAcceptCall,
"拒绝": voipRefuseCall
},
});
videoMeetingCreateDialog = $( "#videoMeetingCreateDlg" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"创建": videoMeetingCreateNewMeeting,
"取消": function() {
videoMeetingCreateDialog.dialog( "close" );
}
},
});
videoMeetingDelDialog = $( "#videoMeetingDelDlg" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"确定": exitVideoMeetingFunc,
"取消": function() {
videoMeetingDelDialog.dialog( "close" );
}
},
});
videoLiveManageDialog = $( "#videoLiveManageDlg" ).dialog({
autoOpen: false,
height: 200,
width: 500,
modal: true,
buttons: {
/* "踢出": videoLiveKickOutUser,
"禁言": videoLiveBanToSendMsg,
"私信": videoLiveSendPrivateMsg, */
"同意": videoLiveApplyAgree,
"拒绝": function() {
videoLiveManageDialog.dialog( "close" );
}
/* "下麦": videoLiveLinkStop, */
},
});
videoLiveCreateDialog = $( "#videoLiveCreateDlg" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"创建": videoLiveCreateNewLive,
"取消": function() {
videoLiveCreateDialog.dialog( "close" );
}
},
});
videoLiveDelDialog = $( "#videoLiveDelDlg" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"确定": exitVideoLiveFunc,
"取消": function() {
videoLiveDelDialog.dialog( "close" );
}
},
});
videoLiveCanvasDlg = $( "#videoLiveCanvasDlg" ).dialog({
autoOpen: false,
height: 800,
width: 400,
modal: true,
buttons: {
"确定": function() {
videoLiveCanvasDlg.dialog( "close" );
},
"清除": videoLiveCleanCanvas
},
});
$( "#liveTypecheck" ).button();
$( "#meetingTypecheck" ).button();
var localId = getCookie("starrtc_userId");
var localAuthKey = getCookie("starrtc_authKey");
if(localId!=""&&localAuthKey!=""){
userId = localId;
authKey = localAuthKey;
loginSuccessViewSet();
starRtcLogin(agentId,userId,authKey,starRtcLoginCallBack);
}
else
{
switchLogin(true);
}
bindEvent();
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ipfshit/starrtc-web.git
git@gitee.com:ipfshit/starrtc-web.git
ipfshit
starrtc-web
starrtc-web
master

搜索帮助