index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. export const API_BASE_URL = "wss://sxb-socket.4dkankan.com";
  2. // export const API_BASE_URL = "ws://192.168.20.18:14000";
  3. // ws://192.168.20.18:14000
  4. // wss://sxb-socket.4dkankan.com
  5. // 88888888
  6. export const VIDEO_BASE_URL = "https://houseoss.4dkankan.com/";
  7. export const CDN_URL = "https://culture.4dage.com/air_show/resource";
  8. export let app = {
  9. id: "13750062488",
  10. longtime: null,
  11. websocket: null,
  12. is_connect_ok: null,
  13. is_send_msg: null,
  14. noOperationTimeout: 60,
  15. send(msg) {
  16. if (!app.websocket) {
  17. return
  18. }
  19. if (msg === "request") {
  20. app.websocket.emit(msg + " " + this.id);
  21. } else if (msg === "close") {
  22. app.websocket.emit({
  23. data: msg + " 0"
  24. });
  25. } else {
  26. if (app.is_connect_ok == null) {
  27. app.websocket.emit({
  28. data: "request " + this.id
  29. });
  30. }
  31. setTimeout(function () {
  32. app.websocket.emit({
  33. data: msg
  34. });
  35. }, 300);
  36. }
  37. },
  38. emitEvent: {
  39. close() {
  40. app.websocket && app.websocket.emit('Close', 'close', function (data) {
  41. console.log(data, 'close');
  42. })
  43. },
  44. request(cb = null, authorCode = null) {
  45. app.websocket.emit('Request', `${app.id}#${authorCode}`, function (data) {
  46. cb && cb(data)
  47. })
  48. },
  49. switchMachine(scene) {
  50. app.websocket.emit('Switch', scene, function (data) {
  51. console.log(data, scene);
  52. })
  53. },
  54. Photo(photo, cb = null) {
  55. app.websocket.emit('Photo', photo, function (data) {
  56. console.log(data, photo);
  57. cb && cb(data)
  58. })
  59. },
  60. Video(video, cb = null) {
  61. app.websocket.emit('Video', video, function (data) {
  62. console.log(data, video);
  63. cb && cb(data)
  64. })
  65. },
  66. },
  67. showLoading: function () {
  68. return (() => {
  69. wx.showLoading({
  70. mask: true,
  71. title: "加载中",
  72. });
  73. })();
  74. },
  75. hideLoading: function () {
  76. return (() => {
  77. try {
  78. wx.hideLoading();
  79. } catch (error) {}
  80. })();
  81. },
  82. showAlert(msg, comfirm, confirmText = '确定') {
  83. if (comfirm) {
  84. return (() => {
  85. wx.showModal({
  86. title: "提示",
  87. confirmText,
  88. content: msg,
  89. showCancel: false,
  90. success(res) {
  91. if (res.confirm) {
  92. comfirm();
  93. }
  94. },
  95. });
  96. })();
  97. }
  98. return (() => {
  99. wx.showModal({
  100. title: "提示",
  101. showCancel: false,
  102. content: msg,
  103. success() {},
  104. });
  105. })();
  106. },
  107. sendCheck() {
  108. console.log(this.is_connect, this.is_connect_ok, this.is_other_used);
  109. if (!this.is_connect) {
  110. this.hideLoading()
  111. app.showAlert("服务器连接失败,请重新连接", () => {
  112. app.emitEvent.request();
  113. }, '重新连接');
  114. return false;
  115. } else if (this.is_connect_ok === false) {
  116. this.hideLoading()
  117. app.showAlert("服务器已断开,请重新连接", () => {
  118. setTimeout(() => {
  119. wx.showLoading({
  120. title: "重新连接...",
  121. mask: true
  122. });
  123. });
  124. setTimeout(() => {
  125. app.emitEvent.request();
  126. }, 1000);
  127. }, '重新连接');
  128. return false;
  129. } else if (this.is_other_used) {
  130. this.hideLoading()
  131. app.showAlert("当前画屏正在被使用,请稍后", () => {
  132. app.emitEvent.request();
  133. });
  134. return false;
  135. }
  136. this.is_send_msg = true;
  137. return true;
  138. },
  139. checkOperationTimeout(stop,cb=()=>{}) {
  140. this.operationTimer && clearTimeout(this.operationTimer);
  141. this.operationTimer = null;
  142. if (stop) {
  143. // 暂停检测
  144. return;
  145. }
  146. this.operationTimer = setTimeout(function () {
  147. this.is_other_used = true
  148. this.is_connect_ok = false
  149. app.checkOperationTimeout(true);
  150. cb()
  151. }, (this.noOperationTimeout || 120) * 1000);
  152. },
  153. };