index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. export const API_BASE_URL = "wss://sxbv2-socket.4dkankan.com";
  2. // export const API_BASE_URL = "ws://192.168.0.76:14001";
  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. console.log('-------',app.id,authorCode);
  46. app.websocket.emit('Request', `${app.id}#${authorCode}`, function (data) {
  47. cb && cb(data)
  48. })
  49. },
  50. switchMachine(scene) {
  51. app.websocket.emit('Switch', scene, function (data) {
  52. console.log(data, scene);
  53. })
  54. },
  55. Photo(photo, cb = null) {
  56. app.websocket.emit('Photo', photo, function (data) {
  57. console.log(data, photo);
  58. cb && cb(data)
  59. })
  60. },
  61. Video(video, cb = null) {
  62. app.websocket.emit('Video', video, function (data) {
  63. console.log(data, video);
  64. cb && cb(data)
  65. })
  66. },
  67. },
  68. showLoading: function () {
  69. return (() => {
  70. wx.showLoading({
  71. mask: true,
  72. title: "加载中",
  73. });
  74. })();
  75. },
  76. hideLoading: function () {
  77. return (() => {
  78. try {
  79. wx.hideLoading();
  80. } catch (error) {}
  81. })();
  82. },
  83. showAlert(msg, comfirm, confirmText = '确定') {
  84. if (comfirm) {
  85. return (() => {
  86. wx.showModal({
  87. title: "提示",
  88. confirmText,
  89. content: msg,
  90. showCancel: false,
  91. success(res) {
  92. if (res.confirm) {
  93. comfirm();
  94. }
  95. },
  96. });
  97. })();
  98. }
  99. return (() => {
  100. wx.showModal({
  101. title: "提示",
  102. showCancel: false,
  103. content: msg,
  104. success() {},
  105. });
  106. })();
  107. },
  108. sendCheck() {
  109. console.log(this.is_connect, this.is_connect_ok, this.is_other_used);
  110. if (!this.is_connect) {
  111. this.hideLoading()
  112. app.showAlert("服务器连接失败,请重新连接", () => {
  113. app.emitEvent.request();
  114. }, '重新连接');
  115. return false;
  116. } else if (this.is_connect_ok === false) {
  117. this.hideLoading()
  118. app.showAlert("服务器已断开,请重新连接", () => {
  119. setTimeout(() => {
  120. wx.showLoading({
  121. title: "重新连接...",
  122. mask: true
  123. });
  124. });
  125. setTimeout(() => {
  126. app.emitEvent.request();
  127. }, 1000);
  128. }, '重新连接');
  129. return false;
  130. } else if (this.is_other_used) {
  131. this.hideLoading()
  132. app.showAlert("当前画屏正在被使用,请稍后", () => {
  133. app.emitEvent.request();
  134. });
  135. return false;
  136. }
  137. this.is_send_msg = true;
  138. return true;
  139. },
  140. checkOperationTimeout(stop,cb=()=>{}) {
  141. this.operationTimer && clearTimeout(this.operationTimer);
  142. this.operationTimer = null;
  143. if (stop) {
  144. // 暂停检测
  145. return;
  146. }
  147. this.operationTimer = setTimeout(function () {
  148. this.is_other_used = true
  149. this.is_connect_ok = false
  150. app.checkOperationTimeout(true);
  151. cb()
  152. }, (this.noOperationTimeout || 120) * 1000);
  153. },
  154. };