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.
 
 
 
 
 
 

75 lines
2.7 KiB

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