sssssss

 

var Logic =
{
apiUrl: "",
login: function (account, pwd, callback, failCallback) {
var data = { accountNumber: account, password: pwd, platform: Configs.platform };
data = JSON.stringify(data);
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/mobile/loginByAccountNumber',
dataType: "json",
async: true,
data: data,
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data.webrtcAccountId, data.accountId, data.userId, data.token);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
sendMessage: function (accountId, videoMembers, meetingType, meetingId, token, callback, failCallback) {
var data = JSON.stringify({ accountId: accountId, videoMembers: videoMembers, meetingType: meetingType, meetingId: meetingId, accountName: accountId, platform: Configs.platform, token: token });

$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/push',
dataType: "json",
async: true,
data: data,
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
isUerOnline: function (users, token, accountId, callback, failCallback) {
var data = JSON.stringify({ users: users, token: token, accountId: accountId, platform: Configs.platform });
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/mobile/getStatusAndPlatform',
dataType: "json",
async: true,
data: data,
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data.users);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
createMeeting: function (accountId, token, callback, failCallback) {
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/create',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, token: token, platform: Configs.platform }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data.meetingId);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
updatePushId: function (accountId, token, callback, failCallback) {
var pushId = accountId;
var pushIdType = "7";
var pushType = Configs.platform;

$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/mobile/updatePushId',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, pushId: pushId, model: "", pushIdType: pushIdType, pushType: pushType, token: token, platform: Configs.platform }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback();
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
reportStatus: function (accountId, state, token, callback, failCallback) {

StaticDataCenter.recoverData("state", state);
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/mobile/reportStatus',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, platform: Configs.platform, state: state, token: token }),
contentType: "application/json;charset=utf-8",
success: function (data) {

if (data.msg == "成功") {
console.error("**********************上报普通状态成功:" + state + "********************************");
callback();
}
else {
failCallback(data.msg);
}
},
error: function (data) {

failCallback(data);
}
});
},
updateReportStatus: function (accountId, state, callback, failCallback) {
StaticDataCenter.recoverData("state", state);
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/mobile/updateReportStatus',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, platform: Configs.platform, state: state }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback();
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
reportAnswerStatus: function (accountId, meetingId, state, token, callback, failCallback) {

$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/reportAnswerStatus',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, meetingId: meetingId, state: state, token: token, platform: Configs.platform }),
contentType: "application/json;charset=utf-8",
success: function (data) {

if (data.msg == "成功") {
console.error("*******************上报会议状态成功,值为" + state + "******************会议:" + meetingId + "******账号:" + accountId);
callback();
}
else {
console.error("*******************上报会议状态失败,值为" + state + "******************会议:" + meetingId + "******账号:" + accountId);
failCallback(data.msg);
}
},
error: function (data) {
console.error("上报会议状态失败");
failCallback(data);
}
});
},
checkAnswerStatus: function (accountId, meetingId, token, callback, failCallback) {
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/checkAnswerStatus',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, meetingId: meetingId, token: token, platform: Configs.platform }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {

callback(data.results);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
getMeetingList: function (accountId, token, callback, failCallback) {
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/getMeetingList',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, token: token, platform: Configs.platform }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data.meetingList);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
getCallRecords: function (accountId, startTime, token, callback, failCallback) {

var data = null;
if (startTime == undefined || startTime == null || startTime == "") {
data = JSON.stringify({ accountId: accountId, token: token, platform: Configs.platform });
}
else {
data = JSON.stringify({ accountId: accountId, token: token, platform: Configs.platform, startTime: startTime });
}

$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/getCallRecords',
dataType: "json",
async: true,
data: data,
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback(data.callList, data.calledList);
}
else {
failCallback(data.msg);
}
},
error: function (data) {
failCallback(data);
}
});
},
intoMeeting: function (accountId, meetingId, token, callback, failCallback) {
$.ajax({
type: "Post",
url: Logic.apiUrl + 'SinopecDemo/meeting/valid',
dataType: "json",
async: true,
data: JSON.stringify({ accountId: accountId, token: token, platform: Configs.platform, meetingId: meetingId }),
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.msg == "成功") {
callback();
}
else {
failCallback();
}
},
error: function (data) {
failCallback(data);
}
});
},

}


var IM_Client = function () {
var webSocket = null;
var _serveraddress = null;
var _userId = null;
this.Intlize = function (serveraddress, userId, token, paltform) {
var _userId = userId;
var _serveraddress = serveraddress;
var _token = token;
var _paltform = paltform;
var timer = null;
var heartflag = false;

webSocket = new WebSocket(serveraddress + "/" + userId + "/" + paltform + "/" + token);
webSocket.onopen = open;
function open() {
systemControl.closeLoadingWindow();
_connectCallback();
if (timer != null) {
window.clearInterval(timer);
}
tryTime = 0;
heartflag = true;

timer = window.setInterval(function () {
if (heartflag == false) { return; }
webSocket.send("&");
}, Configs.webSocketHeartTime);
};
// 异常
webSocket.onerror = error;
function error() {
_onConnectError("及时通讯连接异常");
};

// 收到服务端消息
webSocket.onmessage = messagecome;
function messagecome(msg) {
try {
var dd = JSON.parse(msg.data);
if (msg.data == "&") { return; }
if (dd.pushType == 1) {

_onCancelMeeting(dd.meetingId);
return;
}

if (dd.accountName == undefined || dd.accountName == null || dd.accountName == "") {
return;
}

_onReviveMessage(msg);
}
catch (e) {
return;
}
return;
};

var tryTime = 0;
var reconnectTime = parseInt(Math.random() * 300000, 10) + 1000;
// 断线重连
webSocket.onclose = close;
function close(e) {
heartflag = false;
if (timer != null) {
window.clearInterval(timer);
}

var isreconnection = false;
//判断IE浏览器版本
var browser = "NOIE";
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if (fIEVersion == 7) {
browser = "IE7";
} else if (fIEVersion == 8) {
browser = "IE8";
} else if (fIEVersion == 9) {
browser = "IE9";
} else if (fIEVersion == 10) {
browser = "IE10";
} else {
browser = "IE6";//IE版本<7
}
} else if (isEdge) {
browser = 'edge';//edge
} else if (isIE11) {
browser = "IE11"; //IE11
} else {
browser = "NOIE";//不是ie浏览器
}

if (browser == "IE11") {
if (e.reason == undefined || e.reason == null || e.reason == "") {
isreconnection = true;
} else {
var reasonSTR = e.reason.split("&")[0];
if ("4001" == reasonSTR || "4002" == reasonSTR || "4003" == reasonSTR || "4005" == reasonSTR) {
isreconnection = false;
} else {
isreconnection = true;
}
}
} else {
if (e.code == '4001' || e.code == '4002' || e.code == '4003' || e.code == '4005') {
isreconnection = false;
} else {
isreconnection = true;
}
}
if (isreconnection == false) {
//如果断开原因为4001 , 4002 , 4003 不进行重连.

$.cookie("pwd", "");

systemControl.confirm("连接断开了,原因:" + e.reason, function () {
location.href = "../Client/Main.html";
}, function () {
location.href = "../Client/Main.html";
});
return;
}

systemControl.showLoadingWindow("即时通讯正在断线重连");

if (reconnectTime > 3600000) { reconnectTime = 3600000; }
else if (tryTime > 0) {
reconnectTime += 600000
}
window.setTimeout(function () {
webSocket = null;
tryTime++;
webSocket = new WebSocket(serveraddress + "/" + userId + "/" + paltform + "/" + token);
webSocket.onclose = close;
webSocket.onopen = open;
webSocket.onmessage = messagecome;
webSocket.onerror = error;
}, reconnectTime);

};

var _onCancelMeeting = null;
this.OnCancelMeeting = function (callback) {
_onCancelMeeting = callback;
}

}
this.SendPrivateText = function (accountId, meetingId, mettingType, toUsernames, token, callback) {
Logic.sendMessage(accountId, toUsernames, mettingType, meetingId, StaticDataCenter.getData("token"), function () {
callback(true);
}, function (msg) {
console.error("呼叫失败会议Id为:" + meetingId);
systemControl.showMessage("呼叫失败:" + msg);
return;
});

};
//*********************************************************************************
var _connectCallback = null;
this.onConnectCallback = function (callback) {
_connectCallback = callback;
}
var _onConnectError = null;
this.onConnectError = function (callback) {
_onConnectError = callback;
}
var _onTokenError = null;
this.onTokenError = function (callback) {
_onTokenError = callback;
}
var _onReviveMessage = null;
this.onReviveMessage = function (callback) {
_onReviveMessage = callback;
}
}

IMType = {
rongyun: "rongyun",
huanxin: "huanxin"
}

posted on 2017-08-09 14:36  你的乐哥哥  阅读(1291)  评论(0编辑  收藏  举报