index.js 4.0 KB

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