// 去除实时图片按键操作
$(function () {
var leftall = document.getElementById("leftall");
leftall.oncontextmenu = function () { return false; };
leftall.ondragstart = function () { return false; };
leftall.onselectstart = function () { return false; };
leftall.onselect = function () { return false; };
})
// stf实时监控类
function NewStf(id,device){
// var wsUri = "ws://127.0.0.1/mandala-agent/ws/stf";
var wsUri = "ws://192.168.3.85:8090/mrd/10/88";
var phoneImg = document.getElementById(id);
NewStf.prototype.startWebSocket = function(){
stf_websocket= new WebSocket(wsUri);
stf_websocket.onopen = function (evt) {
doSend(device);
};
stf_websocket.onclose = function (evt) {
alert("断开连接");
};
stf_websocket.onmessage = function (evt) {
onMessage(evt)
};
stf_websocket.onerror = function (evt) {
alert("异常错误断开连接");
};
}
function onMessage(evt) {
if (typeof (evt.data) == "string") {
$("#loading").fadeOut(300);
} else {
phoneImg.src = URL.createObjectURL(evt.data);
}
}
function doSend(message) {
stf_websocket.send(message);
}
function doSendNoWrite(message) {
stf_websocket.send(message);
}
var mousedown = false;
phoneImg.onmousedown = function (e) {
if (e.button == 2) return;
var rect = this.getBoundingClientRect();
var mouseX = e.clientX - rect.left;//获取鼠标在canvsa中的坐标
var mouseY = e.clientY - rect.top;
doSend("1:" + mouseX/phoneImg.width + "," + mouseY/phoneImg.height);
mousedown = true;
}
phoneImg.onmouseout = function (e) {
if (e.button == 2) return;
if (mousedown != true) return;
mousedown = false;
doSend("2:up");
}
phoneImg.onmouseup = function (e) {
if (e.button == 2) return;
if (mousedown != true) return;
mousedown = false;
doSend("2:up");
}
phoneImg.onmousemove = function (e) {
if (e.button == 2) return;
if (mousedown != true) return;
var e = window.event || e
var rect = this.getBoundingClientRect();
var mouseX = e.clientX - rect.left;//获取鼠标在canvsa中的坐标
var mouseY = e.clientY - rect.top;
doSendNoWrite("3:" + mouseX/phoneImg.width + "," + mouseY/phoneImg.height);
}
$("#android-menu").click(function () {
doSend("4:KEYCODE_APP_SWITCH");
})
$("#android-home").click(function () {
doSend("4:3");
})
$("#android-power").click(function () {
doSend("4:26");
})
$("#android-volum-up").click(function () {
doSend("4:24");
})
$("#android-volum-down").click(function () {
doSend("4:25");
})
$("#android-volum-mute").click(function () {
doSend("4:164");
})
$("#android-settings").click(function () {
// doSend("4:KEYCODE_SETTINGS");
})
$("#android-notification").click(function () {
// doSend("4:83");
})
//确保服务器已经释放相关资源
}
setTimeout(function () {
var stf =new NewStf("phoneImg","NDSL3P0003");
stf.startWebSocket();
}, 500);
// 开启logcat
function getLogcat(){
setTimeout(function () {
var log = new Logcat("NDSL3P0003");
if($.trim($("#g-and-s").text())=="获取"){
$("#g-and-s").html('<span class="fa fa-spinner fa-pulse"></span> 停止');
log.startWebSocket();
}else{
$("#g-and-s").html('<span class="fa fa-spinner "></span> 获取');
log.close();
}
}, 500);
}
// LogCat类
function Logcat(device){
var wsUri = "ws://192.168.3.85:8090/logcat/10/88";
// var wsUri = "ws://10.10.23.88/mandala-agent/ws/logcat";
var logData = document.getElementById("logData");
var logForm = document.getLog;
Logcat.prototype.close = function() {
websocket.send(getFilterJson("stop",""));
}
Logcat.prototype.startWebSocket = function(){
websocket= new WebSocket(wsUri);
websocket.onopen = function (evt) {
onOpen(evt)
};
websocket.onclose = function (evt) {
onClose(evt)
};
websocket.onmessage = function (evt) {
onMessage(evt)
};
websocket.onerror = function (evt) {
onError(evt)
};
}
function onOpen(evt) {
websocket.send(getFilterJson("get",device));
}
function onClose(evt) {
websocket.send(getFilterJson("stop",""));
}
function onMessage(evt) {
console.log(evt.data);
if (typeof (evt.data) == "string") {
writeToScreen(evt.data);
$("#loading").fadeOut(300);
} else {
writeToScreen(evt.data);
}
}
function onError(evt) {
// $("#loading").fadeOut(300);
alert("异常错误断开连接");
}
function doSend() {
websocket.send(getFilterJson("filter",""));
}
function writeToScreen(message) {
if (logData.children.length>20){
logData.removeChild(logData.childNodes[0]);
}
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
if(message.indexOf("I/")>0){
pre.style.color = "teal";
}
else if(message.indexOf("D/")>0){
pre.style.color = "royalblue";
}
else if(message.indexOf("E/")>0){
pre.style.color = "red";
}
else if(message.indexOf("W/")>0){
pre.style.color = "orange";
}
else if(message.indexOf("F/")>0){
pre.style.color = "firebrick";
}
pre.innerHTML = message;
logData.appendChild(pre);
logData.scrollTop = logData.scrollHeight;
}
function getFilterJson(action,device){
var data = new Object();
data.action = action;
data.device = device;
data.type = logForm.type.value;
data.time = logForm.time.value;
data.pid = logForm.pid.value;
data.tid = logForm.tid.value;
data.tag = logForm.tag.value;
data.text = logForm.text.value;
return JSON.stringify(data);
}
document.getElementById("getLog").addEventListener("input", doSend);
document.getElementById("type").addEventListener("change", doSend);
}
// 重置搜索
function clear(){
$("#getLog :input").each(function () {
$(this).val("");
});
$("select[name='type']").val("all");
}
// 清空log
function clearLog(){
$("#logData").empty();
$('#myMenu').hide(200);
}
Websocket-stf
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 导语:知识重在分享 通读专题1、2、3、4之后,就会了解我所作的需求(有不懂得地方可以交流QQ1546166956...
- 导语:知识重在分享 前提:做好事情需要你懂里面的基本知识(javascript怎么用你都不知道,那你在咋写?) 其...
- 说明 本例中对用户请求的响应均通过此类实现,此类为threading.Thread的子类,我们重写了run方法,当...
- 导语:知识重在分享 sendMessage.java(类) package websocket;import ja...
- 本章涉及关于录音的以下几个要点· 构建录音环境· 录音 录音介绍 在iOS中录音的方法有很多这里采用了AVFoun...