index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. export const API_BASE_URL = "ws://192.168.0.134:7015";
  2. // ws://192.168.0.134:7015
  3. // wss://4dart.4dage.com/4dart
  4. // 88888888
  5. export const VIDEO_BASE_URL = "https://houseoss.4dkankan.com/";
  6. export const CDN_URL = "https://culture.4dage.com/air_show/resource";
  7. export let app = {
  8. id: "77777777",
  9. longtime:null,
  10. websocket: null,
  11. is_connect_ok: null,
  12. is_send_msg: null,
  13. noOperationTimeout: 35,
  14. closeByVideoHandle: false,
  15. showAlert(msg, comfirm,confirmText='确定') {
  16. if (comfirm) {
  17. return (() => {
  18. wx.showModal({
  19. title: "提示",
  20. confirmText,
  21. content: msg,
  22. showCancel: false,
  23. success(res) {
  24. if (res.confirm) {
  25. comfirm();
  26. }
  27. },
  28. });
  29. })();
  30. }
  31. return (() => {
  32. wx.showModal({
  33. title: "提示",
  34. showCancel: false,
  35. content: msg,
  36. success() {},
  37. });
  38. })();
  39. },
  40. send(msg) {
  41. if (!app.websocket) {
  42. return
  43. }
  44. if (msg === "request") {
  45. app.websocket.send({ data: msg + " " + this.id });
  46. } else if (msg === "close") {
  47. app.websocket.send({ data: msg + " 0" });
  48. } else {
  49. if (app.is_connect_ok == null) {
  50. app.websocket.send({ data: "request " + this.id });
  51. }
  52. setTimeout(function () {
  53. app.websocket.send({ data: msg });
  54. }, 300);
  55. }
  56. },
  57. showLoading: function () {
  58. return (() => {
  59. wx.showLoading({
  60. mask: true,
  61. title: "加载中",
  62. });
  63. })();
  64. },
  65. hideLoading: function () {
  66. return (() => {
  67. try {
  68. wx.hideLoading();
  69. } catch (error) {}
  70. })();
  71. },
  72. sendCheck() {
  73. console.log(this.is_connect,this.is_connect_ok,this.is_other_used);
  74. if (!this.is_connect) {
  75. this.hideLoading()
  76. app.showAlert("服务器连接失败,请重新连接", () => {
  77. app.send("request");
  78. },'重新连接');
  79. return false;
  80. } else if (this.is_connect_ok === false) {
  81. this.hideLoading()
  82. app.showAlert("服务器已断开,请重新连接", () => {
  83. setTimeout(() => {
  84. wx.showLoading({
  85. title: "重新连接...",
  86. mask: true
  87. });
  88. });
  89. setTimeout(() => {
  90. app.send("request");
  91. }, 1000);
  92. },'重新连接');
  93. return false;
  94. } else if (this.is_other_used) {
  95. this.hideLoading()
  96. app.showAlert("当前画屏正在被使用,请稍后", () => {
  97. app.send("request");
  98. });
  99. return false;
  100. }
  101. this.is_send_msg = true;
  102. return true;
  103. },
  104. checkOperationTimeout(stop) {
  105. this.operationTimer && clearTimeout(this.operationTimer);
  106. this.operationTimer = null;
  107. if (stop) {
  108. // 暂停检测
  109. return;
  110. }
  111. this.operationTimer = setTimeout(function () {
  112. if (app.is_connect_ok) {
  113. app.send("close");
  114. this.is_other_used = true
  115. this.is_connect_ok = false
  116. app.checkOperationTimeout(true);
  117. app.showAlert("抱歉,因您长时间使用,让下一位小伙伴体验吧");
  118. }
  119. }, (this.noOperationTimeout || 120) * 1000);
  120. },
  121. };