|
|
@@ -0,0 +1,75 @@ |
|
|
|
(function ($, learun) { |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
learun._im = { |
|
|
|
init: function () { |
|
|
|
learun._im.registerServer(); |
|
|
|
learun._im.connect(); |
|
|
|
} |
|
|
|
// 连接服务端 |
|
|
|
, connect: function () { |
|
|
|
var loginInfo = learun.clientdata.get(['userinfo']); |
|
|
|
if (loginInfo.imOpen != 'true') { |
|
|
|
setTimeout(learun._im.connect, 1000); |
|
|
|
} |
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
url: loginInfo.imUrl + "/hubs", |
|
|
|
type: "get", |
|
|
|
dataType: "text", |
|
|
|
success: function (data) { |
|
|
|
eval(data); |
|
|
|
//Set the hubs URL for the connection |
|
|
|
$.connection.hub.url = loginInfo.imUrl; |
|
|
|
$.connection.hub.qs = { "userId": loginInfo.userId }; |
|
|
|
// Declare a proxy to reference the hub. |
|
|
|
learun.imChat = $.connection.ChatsHub; |
|
|
|
learun.imChat.client.broadcastMessage = function(message) { |
|
|
|
top.layer.open({ |
|
|
|
type: 1 //此处以iframe举例 |
|
|
|
, title: '通知' |
|
|
|
, area: ['390px', '330px'] |
|
|
|
, shade: 0 |
|
|
|
, offset: 'rb' |
|
|
|
, maxmin: true |
|
|
|
, content: message |
|
|
|
, btn: null |
|
|
|
, yes: function () { |
|
|
|
$(that).click(); //此处只是为了演示,实际使用可以剔除 |
|
|
|
} |
|
|
|
, btn2: function () { |
|
|
|
layer.closeAll(); |
|
|
|
} |
|
|
|
|
|
|
|
, zIndex: layer.zIndex //重点1 |
|
|
|
, success: function (layero) { |
|
|
|
layer.setTop(layero); //重点2 |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
if (!learun.imChat) { |
|
|
|
setTimeout(learun._im.connect, 1000); |
|
|
|
} |
|
|
|
// 连接成功后注册服务器方法 |
|
|
|
$.connection.hub.start().done(function () { |
|
|
|
learun.imChat.server.pushMessage('123123'); |
|
|
|
}); |
|
|
|
//断开连接后 |
|
|
|
$.connection.hub.disconnected(function () { |
|
|
|
// |
|
|
|
}); |
|
|
|
}, |
|
|
|
error: function (XMLHttpRequest, textStatus, errorThrown) { |
|
|
|
isLoaded = 0; |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
$(function() { |
|
|
|
learun._im.connect(); |
|
|
|
}) |
|
|
|
|
|
|
|
})(jQuery, top.learun); |