import("./vant.min.js");
|
// import("./jquery-1.6.4.min.js");
|
// import("./jquery.signalR-2.2.2.min.js");
|
// import("./Hubs.js");
|
|
// const vant = ("./vant.min");
|
|
(function(w) {
|
|
var pushServer = "http://demo.dcloud.net.cn/push/?";
|
var message = null;
|
|
var g_wakelock = null;
|
|
// 监听plusready事件
|
document.addEventListener("plusready", function() {
|
|
|
var main = plus.android.runtimeMainActivity();
|
console.log(main,JSON.stringify(main))
|
var Context = plus.android.importClass("android.content.Context");
|
console.log(Context)
|
var PowerManager = plus.android.importClass("android.os.PowerManager");
|
console.log(PowerManager)
|
var pm = main.getSystemService(Context.POWER_SERVICE);
|
console.log(JSON.stringify(pm))
|
g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
|
console.log(JSON.stringify(g_wakelock))
|
g_wakelock.acquire();
|
|
|
message = document.getElementById("message");
|
// 监听点击消息事件
|
plus.push.addEventListener("click", function(msg) {
|
// 判断是从本地创建还是离线推送的消息
|
switch (msg.payload) {
|
case "LocalMSG":
|
outSet("点击本地创建消息启动:");
|
break;
|
default:
|
outSet("点击离线推送消息启动:");
|
break;
|
}
|
// 提示点击的内容
|
plus.nativeUI.alert(msg.content);
|
// 处理其它数据
|
logoutPushMsg(msg);
|
}, false);
|
// 监听在线消息事件
|
plus.push.addEventListener("receive", function(msg) {
|
if (msg.aps) { // Apple APNS message
|
outSet("接收到在线APNS消息:");
|
} else {
|
outSet("接收到在线透传消息:");
|
}
|
|
logoutPushMsg(msg);
|
}, false);
|
|
// var main = plus.android.runtimeMainActivity()
|
// vant.Notify(main)
|
// var Context = plus.android.importClass("android.content.Context");
|
// vant.Notify(Context)
|
// var PowerManager = plus.android.importClass("android.os.PowerManager");
|
// var pm = main.getSystemService(Context.POWER_SERVICE);
|
// g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
|
// g_wakelock.acquire();
|
|
}, false);
|
|
function CreateNotification(msg, n) {
|
console.log(msg, n)
|
var NotifyID = n;
|
var Context = plus.android.importClass("android.content.Context");
|
var main = plus.android.runtimeMainActivity();
|
var Noti = plus.android.importClass("android.app.Notification");
|
var NotificationManager = plus.android.importClass("android.app.NotificationManager");
|
var nm = main.getSystemService(Context.NOTIFICATION_SERVICE)
|
var Notification = plus.android.importClass("android.app.Notification");
|
var mNotification = new Notification.Builder(main);
|
var pending = plus.android.importClass("android.app.PendingIntent");
|
var intent = plus.android.importClass("android.content.Intent");
|
|
//mNotification.setOngoing(true);
|
mNotification.setContentTitle("您有一条未读消息"); //标题
|
mNotification.setContentText(msg); //内容
|
mNotification.setSmallIcon(17301620); //图标
|
mNotification.setTicker("First Time"); //通知首次出现在通知栏时的效果
|
mNotification.setNumber(5); //通知集合的数量
|
//var str = dateToStr(new Date());
|
//mNotification.setWhen(str);//通知产生时间
|
//mNotification.setContentIntent();//通知栏点击事件
|
mNotification.setDefaults(Noti.DEFAULT_VIBRATE); //声音、闪灯、震动效果,可叠加
|
mNotification.setPriority(Noti.PRIORITY_DEFAULT); //通知优先级
|
mNotification.flags = Notification.FLAG_ONLY_ALERT_ONCE; //发起通知时震动
|
var mNb = mNotification.build()
|
nm.notify(NotifyID, mNb);
|
}
|
|
|
|
/**
|
* 日志输入推送消息内容
|
*/
|
function logoutPushMsg(msg) {
|
outLine("title: " + msg.title);
|
outLine("content: " + msg.content);
|
if (msg.payload) {
|
if (typeof(msg.payload) == "string") {
|
outLine("payload(String): " + msg.payload);
|
} else {
|
outLine("payload(JSON): " + JSON.stringify(msg.payload));
|
}
|
} else {
|
outLine("payload: undefined");
|
}
|
if (msg.aps) {
|
outLine("aps: " + JSON.stringify(msg.aps));
|
}
|
}
|
|
/**
|
* 获取本地推送标识信息
|
*/
|
function getPushInfo() {
|
outSet("获取客户端推送标识信息:");
|
plus.push.getClientInfoAsync(function(info) {
|
outLine('Success');
|
outLine(JSON.stringify(info));
|
}, function(e) {
|
outLine('Failed');
|
outLine(JSON.stringify(e));
|
});
|
}
|
/**
|
* 本地创建一条推动消息
|
*/
|
function createLocalPushMsg(msg) {
|
var cont = $('#cont').val();
|
var options = {
|
cover: false
|
};
|
// console.log('1222')
|
plus.push.createMessage(msg, "LocalMSG", options);
|
outSet("创建本地消息成功!");
|
outLine("请到系统消息中心查看!");
|
if (plus.os.name == "iOS") {
|
outLine('*如果无法创建消息,请到"设置"->"通知"中配置应用在通知中心显示!');
|
}
|
}
|
/**
|
* 读取所有推送消息
|
*/
|
function listAllPush() {
|
var msgs = null;
|
switch (plus.os.name) {
|
case "Android":
|
msgs = plus.push.getAllMessage();
|
break;
|
default:
|
break;
|
}
|
if (!msgs) {
|
outSet("此平台不支持枚举推送消息列表!");
|
return;
|
}
|
outSet("枚举消息列表(" + msgs.length + "):");
|
for (var i in msgs) {
|
var msg = msgs[i];
|
outLine(i + ": " + msg.title + " - " + msg.content);
|
}
|
}
|
|
|
/**
|
* 清空所有推动消息
|
*/
|
function clearAllPush() {
|
plus.push.clear();
|
outSet("清空所有推送消息成功!");
|
}
|
|
// wakeLock()
|
var g_wakelock = null;
|
//允许程序后台运行,以持续获取GPS位置
|
function wakeLock() {
|
//Android
|
|
console.log(1)
|
|
var main = plus.android.runtimeMainActivity();
|
var Context = plus.android.importClass("android.content.Context");
|
var PowerManager = plus.android.importClass("android.os.PowerManager");
|
var pm = main.getSystemService(Context.POWER_SERVICE);
|
g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
|
g_wakelock.acquire();
|
}
|
|
$(function() {
|
|
|
//前端Hub的使用,注意的是,Hub的名字是ChatHub,这里使用时首字母小写
|
// var work = $.connection.chatHub;
|
var work = $.connection.chatHub;
|
|
console.log(work)
|
|
//对应后端的SendMessage函数,消息接收函数
|
work.client.sendMessage = function(msg) {
|
// vant.Notify({
|
// type: 'success',
|
// message: msg,
|
// duration: 5000
|
// })
|
console.log('我是后端返回的消息:',msg)
|
// CreateNotification(msg, Math.random())
|
createLocalPushMsg(msg)
|
|
};
|
|
$.connection.hub.url = 'http://121.196.36.24:8001/signalr'
|
//hub连接开启
|
$.connection.hub.start().done(function() {
|
|
var username = localStorage.getItem('username');
|
|
//发送上线信息
|
work.server.sendLogin(username);
|
|
// console.log('222')
|
// const aaa = [{
|
// "code": "Q",
|
// "name": "呼叫质量",
|
// "children": [{
|
// "usercode": "999",
|
// "username": "楼先生"
|
// }]
|
// }]
|
|
|
// work.server.sendByGroupList('楼先生', 'CJ002', 'SB001', aaa)
|
|
});
|
|
});
|
|
// wakeLock()
|
// var g_wakelock = null;
|
|
// //允许程序后台运行,以持续获取GPS位置
|
// function wakeLock() {
|
// //Android
|
// var main = plus.android.runtimeMainActivity();
|
// var Context = plus.android.importClass("android.content.Context");
|
// var PowerManager = plus.android.importClass("android.os.PowerManager");
|
// var pm = main.getSystemService(Context.POWER_SERVICE);
|
// g_wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ANY_NAME");
|
// g_wakelock.acquire();
|
// }
|
|
//结束程序后台运行
|
// function releaseWakeLock() {
|
// if (g_wakelock != null && g_wakelock.isHeld()) {
|
// g_wakelock.release();
|
// g_wakelock = null;
|
// }
|
// }
|
|
|
|
})(window);
|