You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pushmessage.js 2.7 KiB

4 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function ($, learun) {
  2. "use strict";
  3. learun._im = {
  4. init: function () {
  5. //learun._im.registerServer();
  6. //learun._im.connect();
  7. }
  8. // 连接服务端
  9. , connect: function () {
  10. var loginInfo = learun.clientdata.get(['userinfo']);
  11. if (loginInfo.imOpen != 'true') {
  12. setTimeout(learun._im.connect, 60000);
  13. }
  14. $.ajax({
  15. url: loginInfo.imUrl + "/hubs",
  16. type: "get",
  17. dataType: "text",
  18. success: function (data) {
  19. eval(data);
  20. //Set the hubs URL for the connection
  21. $.connection.hub.url = loginInfo.imUrl;
  22. $.connection.hub.qs = { "userId": loginInfo.userId };
  23. // Declare a proxy to reference the hub.
  24. learun.imChat = $.connection.ChatsHub;
  25. learun.imChat.client.broadcastMessage = function(message) {
  26. top.layer.open({
  27. type: 1 //此处以iframe举例
  28. , title: '通知'
  29. , area: ['390px', '330px']
  30. , shade: 0
  31. , offset: 'rb'
  32. , maxmin: true
  33. , content: message
  34. , btn: null
  35. , yes: function () {
  36. $(that).click(); //此处只是为了演示,实际使用可以剔除
  37. }
  38. , btn2: function () {
  39. layer.closeAll();
  40. }
  41. , zIndex: layer.zIndex //重点1
  42. , success: function (layero) {
  43. layer.setTop(layero); //重点2
  44. }
  45. });
  46. }
  47. if (!learun.imChat) {
  48. setTimeout(learun._im.connect, 60000);
  49. }
  50. // 连接成功后注册服务器方法
  51. $.connection.hub.start().done(function () {
  52. //learun.imChat.server.pushMessage('123123');
  53. });
  54. //断开连接后
  55. $.connection.hub.disconnected(function () {
  56. //
  57. });
  58. },
  59. error: function (XMLHttpRequest, textStatus, errorThrown) {
  60. isLoaded = 0;
  61. },
  62. });
  63. }
  64. };
  65. $(function() {
  66. //learun._im.connect();
  67. })
  68. })(jQuery, top.learun);